From 9b2dcbcb627d2545cd60248c4d056289be93caa2 Mon Sep 17 00:00:00 2001 From: Shishir Mahajan Date: Wed, 10 Jun 2020 11:47:43 -0700 Subject: [PATCH] Setup container environment. --- containerd/containerd.go | 4 ++-- containerd/driver.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/containerd/containerd.go b/containerd/containerd.go index 0a5042e..0728cad 100644 --- a/containerd/containerd.go +++ b/containerd/containerd.go @@ -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)), ) } diff --git a/containerd/driver.go b/containerd/driver.go index 7209a4e..c87eac0 100644 --- a/containerd/driver.go +++ b/containerd/driver.go @@ -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) }