Setup container environment.

This commit is contained in:
Shishir Mahajan 2020-06-10 11:47:43 -07:00
parent 80585b3a0a
commit 9b2dcbcb62
No known key found for this signature in database
GPG Key ID: D41782E7688DEC4A
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) 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( return d.client.NewContainer(
d.ctxContainerd, d.ctxContainerd,
containerName, containerName,
containerd.WithRuntime(containerdRuntime, nil), containerd.WithRuntime(containerdRuntime, nil),
containerd.WithNewSnapshot(containerSnapshotName, image), 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())) 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) 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 { if err != nil {
return nil, nil, fmt.Errorf("Error in creating container: %v", err) return nil, nil, fmt.Errorf("Error in creating container: %v", err)
} }