Allow to set env variables through the API
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -39,4 +39,5 @@ type InstanceConfig struct {
|
||||
PlaygroundFQDN string
|
||||
Type string
|
||||
DindVolumeSize string
|
||||
Envs []string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user