2014-09-09 00:19:32 -04:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ExecConfig struct {
|
|
|
|
User string
|
|
|
|
Privileged bool
|
|
|
|
Tty bool
|
|
|
|
Container string
|
|
|
|
AttachStdin bool
|
|
|
|
AttachStderr bool
|
|
|
|
AttachStdout bool
|
|
|
|
Detach bool
|
|
|
|
Cmd []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExecConfigFromJob(job *engine.Job) *ExecConfig {
|
|
|
|
execConfig := &ExecConfig{
|
|
|
|
User: job.Getenv("User"),
|
|
|
|
Privileged: job.GetenvBool("Privileged"),
|
|
|
|
Tty: job.GetenvBool("Tty"),
|
|
|
|
Container: job.Getenv("Container"),
|
|
|
|
AttachStdin: job.GetenvBool("AttachStdin"),
|
|
|
|
AttachStderr: job.GetenvBool("AttachStderr"),
|
|
|
|
AttachStdout: job.GetenvBool("AttachStdout"),
|
|
|
|
}
|
2014-09-10 20:06:59 -04:00
|
|
|
if cmd := job.GetenvList("Cmd"); cmd != nil {
|
|
|
|
execConfig.Cmd = cmd
|
2014-09-09 00:19:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return execConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
|
|
|
|
var (
|
2014-09-09 13:36:13 -04:00
|
|
|
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")
|
|
|
|
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
|
|
|
|
execCmd []string
|
|
|
|
container string
|
2014-09-09 00:19:32 -04:00
|
|
|
)
|
|
|
|
if err := cmd.Parse(args); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
parsedArgs := cmd.Args()
|
|
|
|
if len(parsedArgs) > 1 {
|
|
|
|
container = cmd.Arg(0)
|
|
|
|
execCmd = parsedArgs[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
execConfig := &ExecConfig{
|
2014-09-09 13:36:13 -04:00
|
|
|
// TODO(vishh): Expose '-u' flag once it is supported.
|
|
|
|
User: "",
|
|
|
|
// TODO(vishh): Expose '-p' flag once it is supported.
|
|
|
|
Privileged: false,
|
2014-09-09 00:19:32 -04:00
|
|
|
Tty: *flTty,
|
|
|
|
Cmd: execCmd,
|
|
|
|
Container: container,
|
|
|
|
Detach: *flDetach,
|
|
|
|
}
|
|
|
|
|
|
|
|
// If -d is not set, attach to everything by default
|
|
|
|
if !*flDetach {
|
|
|
|
execConfig.AttachStdout = true
|
|
|
|
execConfig.AttachStderr = true
|
|
|
|
if *flStdin {
|
|
|
|
execConfig.AttachStdin = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return execConfig, nil
|
|
|
|
}
|