mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Refactor ProcessConfig
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
7adfb3221e
commit
5fa2e4d4f2
10 changed files with 74 additions and 56 deletions
|
@ -300,10 +300,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
processConfig := execdriver.ProcessConfig{
|
processConfig := execdriver.ProcessConfig{
|
||||||
|
CommonProcessConfig: execdriver.CommonProcessConfig{
|
||||||
|
Entrypoint: c.Path,
|
||||||
|
Arguments: c.Args,
|
||||||
|
Tty: c.Config.Tty,
|
||||||
|
},
|
||||||
Privileged: c.hostConfig.Privileged,
|
Privileged: c.hostConfig.Privileged,
|
||||||
Entrypoint: c.Path,
|
|
||||||
Arguments: c.Args,
|
|
||||||
Tty: c.Config.Tty,
|
|
||||||
User: c.Config.User,
|
User: c.Config.User,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,13 +86,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Windows. Further refactoring required (privileged/user)
|
|
||||||
processConfig := execdriver.ProcessConfig{
|
processConfig := execdriver.ProcessConfig{
|
||||||
Privileged: c.hostConfig.Privileged,
|
CommonProcessConfig: execdriver.CommonProcessConfig{
|
||||||
Entrypoint: c.Path,
|
Entrypoint: c.Path,
|
||||||
Arguments: c.Args,
|
Arguments: c.Args,
|
||||||
Tty: c.Config.Tty,
|
Tty: c.Config.Tty,
|
||||||
User: c.Config.User,
|
},
|
||||||
ConsoleSize: c.hostConfig.ConsoleSize,
|
ConsoleSize: c.hostConfig.ConsoleSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,18 +156,14 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
|
||||||
cmd := stringutils.NewStrSlice(config.Cmd...)
|
cmd := stringutils.NewStrSlice(config.Cmd...)
|
||||||
entrypoint, args := d.getEntrypointAndArgs(stringutils.NewStrSlice(), cmd)
|
entrypoint, args := d.getEntrypointAndArgs(stringutils.NewStrSlice(), cmd)
|
||||||
|
|
||||||
user := config.User
|
|
||||||
if len(user) == 0 {
|
|
||||||
user = container.Config.User
|
|
||||||
}
|
|
||||||
|
|
||||||
processConfig := &execdriver.ProcessConfig{
|
processConfig := &execdriver.ProcessConfig{
|
||||||
Tty: config.Tty,
|
CommonProcessConfig: execdriver.CommonProcessConfig{
|
||||||
Entrypoint: entrypoint,
|
Tty: config.Tty,
|
||||||
Arguments: args,
|
Entrypoint: entrypoint,
|
||||||
User: user,
|
Arguments: args,
|
||||||
Privileged: config.Privileged,
|
},
|
||||||
}
|
}
|
||||||
|
setPlatformSpecificExecProcessConfig(config, container, processConfig)
|
||||||
|
|
||||||
ExecConfig := &ExecConfig{
|
ExecConfig := &ExecConfig{
|
||||||
ID: stringid.GenerateNonCryptoID(),
|
ID: stringid.GenerateNonCryptoID(),
|
||||||
|
|
20
daemon/exec_unix.go
Normal file
20
daemon/exec_unix.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// +build linux freebsd
|
||||||
|
|
||||||
|
package daemon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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, pc *execdriver.ProcessConfig) {
|
||||||
|
user := config.User
|
||||||
|
if len(user) == 0 {
|
||||||
|
user = container.Config.User
|
||||||
|
}
|
||||||
|
|
||||||
|
pc.User = user
|
||||||
|
pc.Privileged = config.Privileged
|
||||||
|
}
|
11
daemon/exec_windows.go
Normal file
11
daemon/exec_windows.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package daemon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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, pc *execdriver.ProcessConfig) {
|
||||||
|
}
|
|
@ -112,18 +112,15 @@ type ResourceStats struct {
|
||||||
SystemUsage uint64 `json:"system_usage"`
|
SystemUsage uint64 `json:"system_usage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessConfig describes a process that will be run inside a container.
|
// CommonProcessConfig is the common platform agnostic part of the ProcessConfig
|
||||||
type ProcessConfig struct {
|
// structure that describes a process that will be run inside a container.
|
||||||
|
type CommonProcessConfig struct {
|
||||||
exec.Cmd `json:"-"`
|
exec.Cmd `json:"-"`
|
||||||
|
|
||||||
Privileged bool `json:"privileged"`
|
Tty bool `json:"tty"`
|
||||||
User string `json:"user"`
|
Entrypoint string `json:"entrypoint"`
|
||||||
Tty bool `json:"tty"`
|
Arguments []string `json:"arguments"`
|
||||||
Entrypoint string `json:"entrypoint"`
|
Terminal Terminal `json:"-"` // standard or tty terminal
|
||||||
Arguments []string `json:"arguments"`
|
|
||||||
Terminal Terminal `json:"-"` // standard or tty terminal (Unix)
|
|
||||||
Console string `json:"-"` // dev/console path (Unix)
|
|
||||||
ConsoleSize [2]int `json:"-"` // h,w of initial console size (Windows)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommonCommand is the common platform agnostic part of the Command structure
|
// CommonCommand is the common platform agnostic part of the Command structure
|
||||||
|
|
|
@ -47,6 +47,17 @@ type Resources struct {
|
||||||
MemorySwappiness int64 `json:"memory_swappiness"`
|
MemorySwappiness int64 `json:"memory_swappiness"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessConfig is the platform specific structure that describes a process
|
||||||
|
// that will be run inside a container.
|
||||||
|
type ProcessConfig struct {
|
||||||
|
CommonProcessConfig
|
||||||
|
|
||||||
|
// Fields below here are platform specific
|
||||||
|
Privileged bool `json:"privileged"`
|
||||||
|
User string `json:"user"`
|
||||||
|
Console string `json:"-"` // dev/console path
|
||||||
|
}
|
||||||
|
|
||||||
// Ipc settings of the container
|
// Ipc settings of the container
|
||||||
// It is for IPC namespace setting. Usually different containers
|
// It is for IPC namespace setting. Usually different containers
|
||||||
// have their own IPC namespace, however this specifies to use
|
// have their own IPC namespace, however this specifies to use
|
||||||
|
|
|
@ -17,6 +17,15 @@ type Resources struct {
|
||||||
// Fields below here are platform specific
|
// Fields below here are platform specific
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessConfig is the platform specific structure that describes a process
|
||||||
|
// that will be run inside a container.
|
||||||
|
type ProcessConfig struct {
|
||||||
|
CommonProcessConfig
|
||||||
|
|
||||||
|
// Fields below here are platform specific
|
||||||
|
ConsoleSize [2]int `json:"-"` // h,w of initial console size
|
||||||
|
}
|
||||||
|
|
||||||
// Network settings of the container
|
// Network settings of the container
|
||||||
type Network struct {
|
type Network struct {
|
||||||
Interface *NetworkInterface `json:"interface"`
|
Interface *NetworkInterface `json:"interface"`
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package windows
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
|
||||||
)
|
|
||||||
|
|
||||||
func checkSupportedOptions(c *execdriver.Command) error {
|
|
||||||
// Windows doesn't support username
|
|
||||||
if c.ProcessConfig.User != "" {
|
|
||||||
return errors.New("Windows does not support the username option")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Windows: Validate other fields which Windows doesn't support, factor
|
|
||||||
// out where applicable per platform.
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -94,12 +94,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
// Make sure the client isn't asking for options which aren't supported
|
|
||||||
err = checkSupportedOptions(c)
|
|
||||||
if err != nil {
|
|
||||||
return execdriver.ExitStatus{ExitCode: -1}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cu := &containerInit{
|
cu := &containerInit{
|
||||||
SystemType: "Container",
|
SystemType: "Container",
|
||||||
Name: c.ID,
|
Name: c.ID,
|
||||||
|
|
Loading…
Reference in a new issue