From 833e71330fa82695cbbfdeac8360dc0460fa9c82 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Fri, 19 Jun 2020 08:26:12 -0300 Subject: [PATCH] Allow to set env variables through the API --- docker/docker.go | 3 ++- provisioner/dind.go | 1 + pwd/instance_test.go | 3 ++- pwd/types/instance.go | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 466a228..26036a9 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -262,6 +262,7 @@ type CreateContainerOpts struct { Labels map[string]string Networks []string DindVolumeSize string + Envs []string } func (d *docker) ContainerCreate(opts CreateContainerOpts) (err error) { @@ -269,7 +270,7 @@ func (d *docker) ContainerCreate(opts CreateContainerOpts) (err error) { containerDir := "/opt/pwd" containerCertDir := fmt.Sprintf("%s/certs", containerDir) - env := []string{fmt.Sprintf("SESSION_ID=%s", opts.SessionId)} + env := append([]string{}, fmt.Sprintf("SESSION_ID=%s", opts.SessionId)) // Write certs to container cert dir if len(opts.ServerCert) > 0 { diff --git a/provisioner/dind.go b/provisioner/dind.go index 9c5468b..a63daee 100644 --- a/provisioner/dind.go +++ b/provisioner/dind.go @@ -78,6 +78,7 @@ func (d *DinD) InstanceNew(session *types.Session, conf types.InstanceConfig) (* Privileged: true, Networks: []string{session.Id}, DindVolumeSize: conf.DindVolumeSize, + Envs: conf.Envs, } dockerClient, err := d.factory.GetForSession(session) diff --git a/pwd/instance_test.go b/pwd/instance_test.go index 129bc8f..2513894 100644 --- a/pwd/instance_test.go +++ b/pwd/instance_test.go @@ -171,6 +171,7 @@ func TestInstanceNew_WithNotAllowedImage(t *testing.T) { ServerKey: nil, CACert: nil, Privileged: true, + Envs: []string{"HELLO=WORLD"}, Networks: []string{session.Id}, } _d.On("ContainerCreate", expectedContainerOpts).Return(nil) @@ -178,7 +179,7 @@ func TestInstanceNew_WithNotAllowedImage(t *testing.T) { _s.On("InstancePut", mock.AnythingOfType("*types.Instance")).Return(nil) _e.M.On("Emit", event.INSTANCE_NEW, "aaaabbbbcccc", []interface{}{"aaaabbbb_aaaabbbbcccc", "10.0.0.1", "node1", "ip10-0-0-1-aaaabbbbcccc"}).Return() - instance, err := p.InstanceNew(session, types.InstanceConfig{ImageName: "redis"}) + instance, err := p.InstanceNew(session, types.InstanceConfig{ImageName: "redis", Envs: []string{"HELLO=WORLD"}}) assert.Nil(t, err) assert.Equal(t, expectedInstance, *instance) diff --git a/pwd/types/instance.go b/pwd/types/instance.go index 033ab0e..4f84ed1 100644 --- a/pwd/types/instance.go +++ b/pwd/types/instance.go @@ -39,4 +39,5 @@ type InstanceConfig struct { PlaygroundFQDN string Type string DindVolumeSize string + Envs []string }