From 7164b66cfc70b43bad98e156e72e305b66aa8ca4 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Wed, 21 Dec 2016 22:42:39 +0100 Subject: [PATCH] Move ReplaceOrAppendEnvValues to container package Signed-off-by: Vincent Demeester --- container/container_unix.go | 3 +-- container/container_windows.go | 3 +-- utils/utils.go => container/env.go | 2 +- utils/utils_test.go => container/env_test.go | 2 +- daemon/exec.go | 15 +++++++-------- 5 files changed, 11 insertions(+), 14 deletions(-) rename utils/utils.go => container/env.go (98%) rename utils/utils_test.go => container/env_test.go (95%) diff --git a/container/container_unix.go b/container/container_unix.go index f92d586204..d311b6c0bf 100644 --- a/container/container_unix.go +++ b/container/container_unix.go @@ -16,7 +16,6 @@ import ( "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/symlink" "github.com/docker/docker/pkg/system" - "github.com/docker/docker/utils" "github.com/docker/docker/volume" "github.com/opencontainers/runc/libcontainer/label" "golang.org/x/sys/unix" @@ -69,7 +68,7 @@ func (container *Container) CreateDaemonEnvironment(tty bool, linkedEnv []string // because the env on the container can override certain default values // we need to replace the 'env' keys where they match and append anything // else. - env = utils.ReplaceOrAppendEnvValues(env, container.Config.Env) + env = ReplaceOrAppendEnvValues(env, container.Config.Env) return env } diff --git a/container/container_windows.go b/container/container_windows.go index b24aa3d845..0ade8461c2 100644 --- a/container/container_windows.go +++ b/container/container_windows.go @@ -8,7 +8,6 @@ import ( "path/filepath" containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/utils" ) // Container holds fields specific to the Windows implementation. See @@ -30,7 +29,7 @@ func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) // because the env on the container can override certain default values // we need to replace the 'env' keys where they match and append anything // else. - return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env) + return ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env) } // UnmountIpcMounts unmounts Ipc related mounts. diff --git a/utils/utils.go b/container/env.go similarity index 98% rename from utils/utils.go rename to container/env.go index 9a7acca419..896a384c4d 100644 --- a/utils/utils.go +++ b/container/env.go @@ -1,4 +1,4 @@ -package utils +package container import ( "strings" diff --git a/utils/utils_test.go b/container/env_test.go similarity index 95% rename from utils/utils_test.go rename to container/env_test.go index ab3911e8b3..fb304fe361 100644 --- a/utils/utils_test.go +++ b/container/env_test.go @@ -1,4 +1,4 @@ -package utils +package container import "testing" diff --git a/daemon/exec.go b/daemon/exec.go index 8197426a33..ab5315a745 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -18,7 +18,6 @@ import ( "github.com/docker/docker/pkg/pools" "github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/term" - "github.com/docker/docker/utils" ) // Seconds to wait after sending TERM before trying KILL @@ -94,7 +93,7 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) { // ContainerExecCreate sets up an exec in a running container. func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (string, error) { - container, err := d.getActiveContainer(name) + cntr, err := d.getActiveContainer(name) if err != nil { return "", err } @@ -115,7 +114,7 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str execConfig.OpenStdin = config.AttachStdin execConfig.OpenStdout = config.AttachStdout execConfig.OpenStderr = config.AttachStderr - execConfig.ContainerID = container.ID + execConfig.ContainerID = cntr.ID execConfig.DetachKeys = keys execConfig.Entrypoint = entrypoint execConfig.Args = args @@ -123,18 +122,18 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str execConfig.Privileged = config.Privileged execConfig.User = config.User - linkedEnv, err := d.setupLinkedContainers(container) + linkedEnv, err := d.setupLinkedContainers(cntr) if err != nil { return "", err } - execConfig.Env = utils.ReplaceOrAppendEnvValues(container.CreateDaemonEnvironment(config.Tty, linkedEnv), config.Env) + execConfig.Env = container.ReplaceOrAppendEnvValues(cntr.CreateDaemonEnvironment(config.Tty, linkedEnv), config.Env) if len(execConfig.User) == 0 { - execConfig.User = container.Config.User + execConfig.User = cntr.Config.User } - d.registerExecCommand(container, execConfig) + d.registerExecCommand(cntr, execConfig) - d.LogContainerEvent(container, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " ")) + d.LogContainerEvent(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " ")) return execConfig.ID, nil }