1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Support copying value from env with -e option.

This commit is contained in:
Brian Olsen 2013-08-14 02:31:04 +02:00
parent be7eb4bfcb
commit 25c4c87c86
2 changed files with 21 additions and 7 deletions

View file

@ -226,6 +226,18 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
} }
} }
envs := []string{}
for _, env := range flEnv {
arr := strings.Split(env, "=")
if len(arr) > 1 {
envs = append(envs, env)
} else {
v := os.Getenv(env)
envs = append(envs, env+"="+v)
}
}
var binds []string var binds []string
// add any bind targets to the list of container volumes // add any bind targets to the list of container volumes
@ -298,7 +310,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
AttachStdin: flAttach.Get("stdin"), AttachStdin: flAttach.Get("stdin"),
AttachStdout: flAttach.Get("stdout"), AttachStdout: flAttach.Get("stdout"),
AttachStderr: flAttach.Get("stderr"), AttachStderr: flAttach.Get("stderr"),
Env: flEnv, Env: envs,
Cmd: runCmd, Cmd: runCmd,
Dns: flDns, Dns: flDns,
Image: image, Image: image,

View file

@ -973,14 +973,14 @@ func TestTty(t *testing.T) {
} }
func TestEnv(t *testing.T) { func TestEnv(t *testing.T) {
os.Setenv("TRUE", "false")
runtime := mkRuntime(t) runtime := mkRuntime(t)
defer nuke(runtime) defer nuke(runtime)
container, _, err := runtime.Create(&Config{ config, _, _, err := ParseRun([]string{"-e=FALSE=true", "-e=TRUE", GetTestImage(runtime).ID, "env"}, nil)
Image: GetTestImage(runtime).ID, if err != nil {
Cmd: []string{"env"}, t.Fatal(err)
}, }
"", container, _, err := runtime.Create(config, "")
)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1010,6 +1010,8 @@ func TestEnv(t *testing.T) {
"HOME=/", "HOME=/",
"container=lxc", "container=lxc",
"HOSTNAME=" + container.ShortID(), "HOSTNAME=" + container.ShortID(),
"FALSE=true",
"TRUE=false",
} }
sort.Strings(goodEnv) sort.Strings(goodEnv)
if len(goodEnv) != len(actualEnv) { if len(goodEnv) != len(actualEnv) {