diff --git a/api/client/client.go b/api/client/client.go index 48420c44a5..e42eebc21c 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -21,8 +21,8 @@ type apiClient interface { ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error) ContainerDiff(containerID string) ([]types.ContainerChange, error) - ContainerExecAttach(execID string, config runconfig.ExecConfig) (types.HijackedResponse, error) - ContainerExecCreate(config runconfig.ExecConfig) (types.ContainerExecCreateResponse, error) + ContainerExecAttach(execID string, config types.ExecConfig) (types.HijackedResponse, error) + ContainerExecCreate(config types.ExecConfig) (types.ContainerExecCreateResponse, error) ContainerExecInspect(execID string) (types.ContainerExecInspect, error) ContainerExecResize(options types.ResizeOptions) error ContainerExecStart(execID string, config types.ExecStartCheck) error diff --git a/api/client/lib/exec.go b/api/client/lib/exec.go index 4b042c71f2..8bcabb1657 100644 --- a/api/client/lib/exec.go +++ b/api/client/lib/exec.go @@ -4,11 +4,10 @@ import ( "encoding/json" "github.com/docker/docker/api/types" - "github.com/docker/docker/runconfig" ) // ContainerExecCreate creates a new exec configuration to run an exec process. -func (cli *Client) ContainerExecCreate(config runconfig.ExecConfig) (types.ContainerExecCreateResponse, error) { +func (cli *Client) ContainerExecCreate(config types.ExecConfig) (types.ContainerExecCreateResponse, error) { var response types.ContainerExecCreateResponse resp, err := cli.post("/containers/"+config.Container+"/exec", nil, config, nil) if err != nil { @@ -30,7 +29,7 @@ func (cli *Client) ContainerExecStart(execID string, config types.ExecStartCheck // It returns a types.HijackedConnection with the hijacked connection // and the a reader to get output. It's up to the called to close // the hijacked connection by calling types.HijackedResponse.Close. -func (cli *Client) ContainerExecAttach(execID string, config runconfig.ExecConfig) (types.HijackedResponse, error) { +func (cli *Client) ContainerExecAttach(execID string, config types.ExecConfig) (types.HijackedResponse, error) { headers := map[string][]string{"Content-Type": {"application/json"}} return cli.postHijacked("/exec/"+execID+"/start", nil, config, headers) } diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index 0f2f06bfcc..d2c50991dd 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -14,7 +14,7 @@ import ( // execBackend includes functions to implement to provide exec functionality. type execBackend interface { - ContainerExecCreate(config *runconfig.ExecConfig) (string, error) + ContainerExecCreate(config *types.ExecConfig) (string, error) ContainerExecInspect(id string) (*exec.Config, error) ContainerExecResize(name string, height, width int) error ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error diff --git a/api/server/router/container/exec.go b/api/server/router/container/exec.go index a4b1f700fa..4b54efde50 100644 --- a/api/server/router/container/exec.go +++ b/api/server/router/container/exec.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stdcopy" - "github.com/docker/docker/runconfig" "golang.org/x/net/context" ) @@ -33,7 +32,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re } name := vars["name"] - execConfig := &runconfig.ExecConfig{} + execConfig := &types.ExecConfig{} if err := json.NewDecoder(r.Body).Decode(execConfig); err != nil { return err } diff --git a/api/types/configs.go b/api/types/configs.go index c166ac7e51..cc026e73f8 100644 --- a/api/types/configs.go +++ b/api/types/configs.go @@ -35,3 +35,17 @@ type ContainerCommitConfig struct { MergeConfigs bool Config *runconfig.Config } + +// ExecConfig is a small subset of the Config struct that hold the configuration +// for the exec feature of docker. +type ExecConfig struct { + User string // User that will run the command + Privileged bool // Is the container in privileged mode + Tty bool // Attach standard streams to a tty. + Container string // Name of the container (to execute in) + AttachStdin bool // Attach the standard input, makes possible user interaction + AttachStderr bool // Attach the standard output + AttachStdout bool // Attach the standard error + Detach bool // Execute in detach mode + Cmd []string // Execution commands and args +} diff --git a/daemon/exec.go b/daemon/exec.go index 2d67813193..f400bc72f5 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Sirupsen/logrus" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/container" "github.com/docker/docker/daemon/exec" @@ -13,7 +14,6 @@ import ( derr "github.com/docker/docker/errors" "github.com/docker/docker/pkg/pools" "github.com/docker/docker/pkg/promise" - "github.com/docker/docker/runconfig" ) func (d *Daemon) registerExecCommand(container *container.Container, config *exec.Config) { @@ -79,7 +79,7 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) { } // ContainerExecCreate sets up an exec in a running container. -func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, error) { +func (d *Daemon) ContainerExecCreate(config *types.ExecConfig) (string, error) { container, err := d.getActiveContainer(config.Container) if err != nil { return "", err diff --git a/daemon/exec_unix.go b/daemon/exec_unix.go index 4ac49927e9..40bd2c8ab8 100644 --- a/daemon/exec_unix.go +++ b/daemon/exec_unix.go @@ -3,14 +3,14 @@ package daemon import ( + "github.com/docker/docker/api/types" "github.com/docker/docker/container" "github.com/docker/docker/daemon/execdriver" - "github.com/docker/docker/runconfig" ) // setPlatformSpecificExecProcessConfig sets platform-specific fields in the // ProcessConfig structure. -func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *container.Container, pc *execdriver.ProcessConfig) { +func setPlatformSpecificExecProcessConfig(config *types.ExecConfig, container *container.Container, pc *execdriver.ProcessConfig) { user := config.User if len(user) == 0 { user = container.Config.User diff --git a/daemon/exec_windows.go b/daemon/exec_windows.go index d6e887acad..f1b93bf02a 100644 --- a/daemon/exec_windows.go +++ b/daemon/exec_windows.go @@ -1,12 +1,12 @@ package daemon import ( + "github.com/docker/docker/api/types" "github.com/docker/docker/container" "github.com/docker/docker/daemon/execdriver" - "github.com/docker/docker/runconfig" ) // setPlatformSpecificExecProcessConfig sets platform-specific fields in the // ProcessConfig structure. This is a no-op on Windows -func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *container.Container, pc *execdriver.ProcessConfig) { +func setPlatformSpecificExecProcessConfig(config *types.ExecConfig, container *container.Container, pc *execdriver.ProcessConfig) { } diff --git a/runconfig/exec.go b/runconfig/exec.go index 6fe28ea338..0ef8926602 100644 --- a/runconfig/exec.go +++ b/runconfig/exec.go @@ -1,28 +1,15 @@ package runconfig import ( + "github.com/docker/docker/api/types" flag "github.com/docker/docker/pkg/mflag" ) -// ExecConfig is a small subset of the Config struct that hold the configuration -// for the exec feature of docker. -type ExecConfig struct { - User string // User that will run the command - Privileged bool // Is the container in privileged mode - Tty bool // Attach standard streams to a tty. - Container string // Name of the container (to execute in) - AttachStdin bool // Attach the standard input, makes possible user interaction - AttachStderr bool // Attach the standard output - AttachStdout bool // Attach the standard error - Detach bool // Execute in detach mode - Cmd []string // Execution commands and args -} - // ParseExec parses the specified args for the specified command and generates // an ExecConfig from it. // If the minimal number of specified args is not right or if specified args are // not valid, it will return an error. -func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) { +func ParseExec(cmd *flag.FlagSet, args []string) (*types.ExecConfig, error) { var ( flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached") flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY") @@ -40,7 +27,7 @@ func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) { parsedArgs := cmd.Args() execCmd = parsedArgs[1:] - execConfig := &ExecConfig{ + execConfig := &types.ExecConfig{ User: *flUser, Privileged: *flPrivileged, Tty: *flTty, diff --git a/runconfig/exec_test.go b/runconfig/exec_test.go index a4b7ea9bac..1acae6eff6 100644 --- a/runconfig/exec_test.go +++ b/runconfig/exec_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "testing" + "github.com/docker/docker/api/types" flag "github.com/docker/docker/pkg/mflag" ) @@ -18,7 +19,7 @@ func TestParseExec(t *testing.T) { &arguments{[]string{"-u"}}: fmt.Errorf("flag needs an argument: -u"), &arguments{[]string{"--user"}}: fmt.Errorf("flag needs an argument: --user"), } - valids := map[*arguments]*ExecConfig{ + valids := map[*arguments]*types.ExecConfig{ &arguments{ []string{"container", "command"}, }: { @@ -92,7 +93,7 @@ func TestParseExec(t *testing.T) { } } -func compareExecConfig(config1 *ExecConfig, config2 *ExecConfig) bool { +func compareExecConfig(config1 *types.ExecConfig, config2 *types.ExecConfig) bool { if config1.AttachStderr != config2.AttachStderr { return false }