Merge pull request #4 from Roblox/env

Setup container environment.
This commit is contained in:
Shishir 2020-06-10 13:58:37 -07:00 committed by GitHub
commit 4672345bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -18,13 +18,13 @@ func (d *Driver) pullImage(imageName string) (containerd.Image, error) {
return d.client.Pull(d.ctxContainerd, imageName, containerd.WithPullUnpack)
}
func (d *Driver) createContainer(image containerd.Image, containerName, containerSnapshotName, containerdRuntime string) (containerd.Container, error) {
func (d *Driver) createContainer(image containerd.Image, containerName, containerSnapshotName, containerdRuntime string, env []string) (containerd.Container, error) {
return d.client.NewContainer(
d.ctxContainerd,
containerName,
containerd.WithRuntime(containerdRuntime, nil),
containerd.WithNewSnapshot(containerSnapshotName, image),
containerd.WithNewSpec(oci.WithImageConfig(image)),
containerd.WithNewSpec(oci.WithImageConfig(image), oci.WithEnv(env)),
)
}

View File

@ -292,8 +292,14 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
d.logger.Info(fmt.Sprintf("Successfully pulled %s image\n", image.Name()))
// Setup environment variables.
var env []string
for key, val := range cfg.Env {
env = append(env, fmt.Sprintf("%s=%s", key, val))
}
containerSnapshotName := fmt.Sprintf("%s-snapshot", containerName)
container, err := d.createContainer(image, containerName, containerSnapshotName, d.config.ContainerdRuntime)
container, err := d.createContainer(image, containerName, containerSnapshotName, d.config.ContainerdRuntime, env)
if err != nil {
return nil, nil, fmt.Errorf("Error in creating container: %v", err)
}