mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move ExecConfig to types.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
056e744903
commit
839f73c302
10 changed files with 32 additions and 32 deletions
|
@ -21,8 +21,8 @@ type apiClient interface {
|
||||||
ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
|
ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
|
||||||
ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error)
|
ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error)
|
||||||
ContainerDiff(containerID string) ([]types.ContainerChange, error)
|
ContainerDiff(containerID string) ([]types.ContainerChange, error)
|
||||||
ContainerExecAttach(execID string, config runconfig.ExecConfig) (types.HijackedResponse, error)
|
ContainerExecAttach(execID string, config types.ExecConfig) (types.HijackedResponse, error)
|
||||||
ContainerExecCreate(config runconfig.ExecConfig) (types.ContainerExecCreateResponse, error)
|
ContainerExecCreate(config types.ExecConfig) (types.ContainerExecCreateResponse, error)
|
||||||
ContainerExecInspect(execID string) (types.ContainerExecInspect, error)
|
ContainerExecInspect(execID string) (types.ContainerExecInspect, error)
|
||||||
ContainerExecResize(options types.ResizeOptions) error
|
ContainerExecResize(options types.ResizeOptions) error
|
||||||
ContainerExecStart(execID string, config types.ExecStartCheck) error
|
ContainerExecStart(execID string, config types.ExecStartCheck) error
|
||||||
|
|
|
@ -4,11 +4,10 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/runconfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerExecCreate creates a new exec configuration to run an exec process.
|
// 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
|
var response types.ContainerExecCreateResponse
|
||||||
resp, err := cli.post("/containers/"+config.Container+"/exec", nil, config, nil)
|
resp, err := cli.post("/containers/"+config.Container+"/exec", nil, config, nil)
|
||||||
if err != 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
|
// It returns a types.HijackedConnection with the hijacked connection
|
||||||
// and the a reader to get output. It's up to the called to close
|
// and the a reader to get output. It's up to the called to close
|
||||||
// the hijacked connection by calling types.HijackedResponse.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"}}
|
headers := map[string][]string{"Content-Type": {"application/json"}}
|
||||||
return cli.postHijacked("/exec/"+execID+"/start", nil, config, headers)
|
return cli.postHijacked("/exec/"+execID+"/start", nil, config, headers)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
// execBackend includes functions to implement to provide exec functionality.
|
// execBackend includes functions to implement to provide exec functionality.
|
||||||
type execBackend interface {
|
type execBackend interface {
|
||||||
ContainerExecCreate(config *runconfig.ExecConfig) (string, error)
|
ContainerExecCreate(config *types.ExecConfig) (string, error)
|
||||||
ContainerExecInspect(id string) (*exec.Config, error)
|
ContainerExecInspect(id string) (*exec.Config, error)
|
||||||
ContainerExecResize(name string, height, width int) error
|
ContainerExecResize(name string, height, width int) error
|
||||||
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/docker/docker/api/server/httputils"
|
"github.com/docker/docker/api/server/httputils"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/stdcopy"
|
"github.com/docker/docker/pkg/stdcopy"
|
||||||
"github.com/docker/docker/runconfig"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
|
||||||
}
|
}
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
|
|
||||||
execConfig := &runconfig.ExecConfig{}
|
execConfig := &types.ExecConfig{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(execConfig); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(execConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,3 +35,17 @@ type ContainerCommitConfig struct {
|
||||||
MergeConfigs bool
|
MergeConfigs bool
|
||||||
Config *runconfig.Config
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/strslice"
|
"github.com/docker/docker/api/types/strslice"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/exec"
|
"github.com/docker/docker/daemon/exec"
|
||||||
|
@ -13,7 +14,6 @@ import (
|
||||||
derr "github.com/docker/docker/errors"
|
derr "github.com/docker/docker/errors"
|
||||||
"github.com/docker/docker/pkg/pools"
|
"github.com/docker/docker/pkg/pools"
|
||||||
"github.com/docker/docker/pkg/promise"
|
"github.com/docker/docker/pkg/promise"
|
||||||
"github.com/docker/docker/runconfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *Daemon) registerExecCommand(container *container.Container, config *exec.Config) {
|
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.
|
// 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)
|
container, err := d.getActiveContainer(config.Container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
"github.com/docker/docker/runconfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
|
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
|
||||||
// ProcessConfig structure.
|
// 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
|
user := config.User
|
||||||
if len(user) == 0 {
|
if len(user) == 0 {
|
||||||
user = container.Config.User
|
user = container.Config.User
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
"github.com/docker/docker/runconfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
|
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
|
||||||
// ProcessConfig structure. This is a no-op on Windows
|
// 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) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,15 @@
|
||||||
package runconfig
|
package runconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
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
|
// ParseExec parses the specified args for the specified command and generates
|
||||||
// an ExecConfig from it.
|
// an ExecConfig from it.
|
||||||
// If the minimal number of specified args is not right or if specified args are
|
// If the minimal number of specified args is not right or if specified args are
|
||||||
// not valid, it will return an error.
|
// 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 (
|
var (
|
||||||
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
|
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")
|
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()
|
parsedArgs := cmd.Args()
|
||||||
execCmd = parsedArgs[1:]
|
execCmd = parsedArgs[1:]
|
||||||
|
|
||||||
execConfig := &ExecConfig{
|
execConfig := &types.ExecConfig{
|
||||||
User: *flUser,
|
User: *flUser,
|
||||||
Privileged: *flPrivileged,
|
Privileged: *flPrivileged,
|
||||||
Tty: *flTty,
|
Tty: *flTty,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
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{"-u"}}: fmt.Errorf("flag needs an argument: -u"),
|
||||||
&arguments{[]string{"--user"}}: fmt.Errorf("flag needs an argument: --user"),
|
&arguments{[]string{"--user"}}: fmt.Errorf("flag needs an argument: --user"),
|
||||||
}
|
}
|
||||||
valids := map[*arguments]*ExecConfig{
|
valids := map[*arguments]*types.ExecConfig{
|
||||||
&arguments{
|
&arguments{
|
||||||
[]string{"container", "command"},
|
[]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 {
|
if config1.AttachStderr != config2.AttachStderr {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue