Skip to content

Commit

Permalink
Vendor engine-api to 70d266e96080e3c3d63c55a4d8659e00ac1f7e6c
Browse files Browse the repository at this point in the history
Signed-off-by: Qiang Huang <[email protected]>
  • Loading branch information
hqhq committed Feb 29, 2016
1 parent 67a7793 commit 53b0d62
Show file tree
Hide file tree
Showing 35 changed files with 347 additions and 326 deletions.
16 changes: 8 additions & 8 deletions builder/dockerfile/dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,20 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
}

config := &container.Config{
Cmd: strslice.New(args...),
Cmd: strslice.StrSlice(args),
Image: b.image,
}

// stash the cmd
cmd := b.runConfig.Cmd
if b.runConfig.Entrypoint.Len() == 0 && b.runConfig.Cmd.Len() == 0 {
if len(b.runConfig.Entrypoint) == 0 && len(b.runConfig.Cmd) == 0 {
b.runConfig.Cmd = config.Cmd
}

// stash the config environment
env := b.runConfig.Env

defer func(cmd *strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
defer func(env []string) { b.runConfig.Env = env }(env)

// derive the net build-time environment for this run. We let config
Expand Down Expand Up @@ -366,7 +366,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
if len(cmdBuildEnv) > 0 {
sort.Strings(cmdBuildEnv)
tmpEnv := append([]string{fmt.Sprintf("|%d", len(cmdBuildEnv))}, cmdBuildEnv...)
saveCmd = strslice.New(append(tmpEnv, saveCmd.Slice()...)...)
saveCmd = strslice.StrSlice(append(tmpEnv, saveCmd...))
}

b.runConfig.Cmd = saveCmd
Expand Down Expand Up @@ -424,7 +424,7 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string)
}
}

b.runConfig.Cmd = strslice.New(cmdSlice...)
b.runConfig.Cmd = strslice.StrSlice(cmdSlice)

if err := b.commit("", b.runConfig.Cmd, fmt.Sprintf("CMD %q", cmdSlice)); err != nil {
return err
Expand Down Expand Up @@ -455,16 +455,16 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original
switch {
case attributes["json"]:
// ENTRYPOINT ["echo", "hi"]
b.runConfig.Entrypoint = strslice.New(parsed...)
b.runConfig.Entrypoint = strslice.StrSlice(parsed)
case len(parsed) == 0:
// ENTRYPOINT []
b.runConfig.Entrypoint = nil
default:
// ENTRYPOINT echo hi
if runtime.GOOS != "windows" {
b.runConfig.Entrypoint = strslice.New("/bin/sh", "-c", parsed[0])
b.runConfig.Entrypoint = strslice.StrSlice{"/bin/sh", "-c", parsed[0]}
} else {
b.runConfig.Entrypoint = strslice.New("cmd", "/S", "/C", parsed[0])
b.runConfig.Entrypoint = strslice.StrSlice{"cmd", "/S", "/C", parsed[0]}
}
}

Expand Down
20 changes: 10 additions & 10 deletions builder/dockerfile/internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/docker/engine-api/types/strslice"
)

func (b *Builder) commit(id string, autoCmd *strslice.StrSlice, comment string) error {
func (b *Builder) commit(id string, autoCmd strslice.StrSlice, comment string) error {
if b.disableCommit {
return nil
}
Expand All @@ -48,11 +48,11 @@ func (b *Builder) commit(id string, autoCmd *strslice.StrSlice, comment string)
if id == "" {
cmd := b.runConfig.Cmd
if runtime.GOOS != "windows" {
b.runConfig.Cmd = strslice.New("/bin/sh", "-c", "#(nop) "+comment)
b.runConfig.Cmd = strslice.StrSlice{"/bin/sh", "-c", "#(nop) " + comment}
} else {
b.runConfig.Cmd = strslice.New("cmd", "/S /C", "REM (nop) "+comment)
b.runConfig.Cmd = strslice.StrSlice{"cmd", "/S /C", "REM (nop) " + comment}
}
defer func(cmd *strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)

hit, err := b.probeCache()
if err != nil {
Expand Down Expand Up @@ -171,11 +171,11 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD

cmd := b.runConfig.Cmd
if runtime.GOOS != "windows" {
b.runConfig.Cmd = strslice.New("/bin/sh", "-c", fmt.Sprintf("#(nop) %s %s in %s", cmdName, srcHash, dest))
b.runConfig.Cmd = strslice.StrSlice{"/bin/sh", "-c", fmt.Sprintf("#(nop) %s %s in %s", cmdName, srcHash, dest)}
} else {
b.runConfig.Cmd = strslice.New("cmd", "/S", "/C", fmt.Sprintf("REM (nop) %s %s in %s", cmdName, srcHash, dest))
b.runConfig.Cmd = strslice.StrSlice{"cmd", "/S", "/C", fmt.Sprintf("REM (nop) %s %s in %s", cmdName, srcHash, dest)}
}
defer func(cmd *strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)

if hit, err := b.probeCache(); err != nil {
return err
Expand Down Expand Up @@ -527,9 +527,9 @@ func (b *Builder) create() (string, error) {
b.tmpContainers[c.ID] = struct{}{}
fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID))

if config.Cmd.Len() > 0 {
if len(config.Cmd) > 0 {
// override the entry point that may have been picked up from the base image
if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, config.Cmd.Slice()); err != nil {
if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, config.Cmd); err != nil {
return "", err
}
}
Expand Down Expand Up @@ -567,7 +567,7 @@ func (b *Builder) run(cID string) (err error) {
if ret, _ := b.docker.ContainerWait(cID, -1); ret != 0 {
// TODO: change error type, because jsonmessage.JSONError assumes HTTP
return &jsonmessage.JSONError{
Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", b.runConfig.Cmd.ToString(), ret),
Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", strings.Join(b.runConfig.Cmd, " "), ret),
Code: ret,
}
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func merge(userConf, imageConf *containertypes.Config) error {
userConf.Labels = imageConf.Labels
}

if userConf.Entrypoint.Len() == 0 {
if userConf.Cmd.Len() == 0 {
if len(userConf.Entrypoint) == 0 {
if len(userConf.Cmd) == 0 {
userConf.Cmd = imageConf.Cmd
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (strin
h := image.History{
Author: c.Author,
Created: time.Now().UTC(),
CreatedBy: strings.Join(container.Config.Cmd.Slice(), " "),
CreatedBy: strings.Join(container.Config.Cmd, " "),
Comment: c.Comment,
EmptyLayer: true,
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/container_operations_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
AllowedDevices: allowedDevices,
AppArmorProfile: c.AppArmorProfile,
AutoCreatedDevices: autoCreatedDevices,
CapAdd: c.HostConfig.CapAdd.Slice(),
CapDrop: c.HostConfig.CapDrop.Slice(),
CapAdd: c.HostConfig.CapAdd,
CapDrop: c.HostConfig.CapDrop,
CgroupParent: defaultCgroupParent,
GIDMapping: gidMap,
GroupAdd: c.HostConfig.GroupAdd,
Expand Down
12 changes: 5 additions & 7 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (daemon *Daemon) mergeAndVerifyConfig(config *containertypes.Config, img *i
return err
}
}
if config.Entrypoint.Len() == 0 && config.Cmd.Len() == 0 {
if len(config.Entrypoint) == 0 && len(config.Cmd) == 0 {
return fmt.Errorf("No command specified")
}
return nil
Expand Down Expand Up @@ -495,13 +495,11 @@ func (daemon *Daemon) generateHostname(id string, config *containertypes.Config)
}
}

func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint *strslice.StrSlice, configCmd *strslice.StrSlice) (string, []string) {
cmdSlice := configCmd.Slice()
if configEntrypoint.Len() != 0 {
eSlice := configEntrypoint.Slice()
return eSlice[0], append(eSlice[1:], cmdSlice...)
func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint strslice.StrSlice, configCmd strslice.StrSlice) (string, []string) {
if len(configEntrypoint) != 0 {
return configEntrypoint[0], append(configEntrypoint[1:], configCmd...)
}
return cmdSlice[0], cmdSlice[1:]
return configCmd[0], configCmd[1:]
}

func (daemon *Daemon) newContainer(name string, config *containertypes.Config, imgID image.ID) (*container.Container, error) {
Expand Down
4 changes: 2 additions & 2 deletions daemon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (d *Daemon) ContainerExecCreate(config *types.ExecConfig) (string, error) {
return "", err
}

cmd := strslice.New(config.Cmd...)
entrypoint, args := d.getEntrypointAndArgs(strslice.New(), cmd)
cmd := strslice.StrSlice(config.Cmd)
entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmd)

keys := []byte{}
if config.DetachKeys != "" {
Expand Down
2 changes: 1 addition & 1 deletion hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://gith
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
clone git github.com/docker/go-connections v0.2.0
clone git github.com/docker/engine-api 575694d38967b53e06cafe8b722c72892dd64db0
clone git github.com/docker/engine-api 70d266e96080e3c3d63c55a4d8659e00ac1f7e6c
clone git github.com/RackSec/srslog 6eb773f331e46fbba8eecb8e794e635e75fc04de
clone git github.com/imdario/mergo 0.2.1

Expand Down
2 changes: 1 addition & 1 deletion image/v1/imagev1.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func HistoryFromConfig(imageJSON []byte, emptyLayer bool) (image.History, error)
return image.History{
Author: v1Image.Author,
Created: v1Image.Created,
CreatedBy: strings.Join(v1Image.ContainerConfig.Cmd.Slice(), " "),
CreatedBy: strings.Join(v1Image.ContainerConfig.Cmd, " "),
Comment: v1Image.Comment,
EmptyLayer: emptyLayer,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions integration-cli/docker_api_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
c.Assert(json.Unmarshal(b, &img), checker.IsNil)

cmd := inspectField(c, img.ID, "Config.Cmd")
c.Assert(cmd, checker.Equals, "{[/bin/sh -c touch /test]}", check.Commentf("got wrong Cmd from commit: %q", cmd))
c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))

// sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.ID, "ls", "/test")
Expand Down Expand Up @@ -564,7 +564,7 @@ func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
c.Assert(label2, checker.Equals, "value2")

cmd := inspectField(c, img.ID, "Config.Cmd")
c.Assert(cmd, checker.Equals, "{[/bin/sh -c touch /test]}", check.Commentf("got wrong Cmd from commit: %q", cmd))
c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))

// sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.ID, "ls", "/test")
Expand Down
18 changes: 9 additions & 9 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) {
func (s *DockerSuite) TestBuildCmd(c *check.C) {
name := "testbuildcmd"

expected := "{[/bin/echo Hello World]}"
expected := "[/bin/echo Hello World]"
_, err := buildImage(name,
`FROM `+minimalBaseImage()+`
CMD ["/bin/echo", "Hello World"]`,
Expand Down Expand Up @@ -2362,7 +2362,7 @@ func (s *DockerSuite) TestBuildEmptyEntrypointInheritance(c *check.C) {
}
res := inspectField(c, name, "Config.Entrypoint")

expected := "{[/bin/echo]}"
expected := "[/bin/echo]"
if res != expected {
c.Fatalf("Entrypoint %s, expected %s", res, expected)
}
Expand All @@ -2376,7 +2376,7 @@ func (s *DockerSuite) TestBuildEmptyEntrypointInheritance(c *check.C) {
}
res = inspectField(c, name2, "Config.Entrypoint")

expected = "{[]}"
expected = "[]"

if res != expected {
c.Fatalf("Entrypoint %s, expected %s", res, expected)
Expand All @@ -2386,7 +2386,7 @@ func (s *DockerSuite) TestBuildEmptyEntrypointInheritance(c *check.C) {

func (s *DockerSuite) TestBuildEmptyEntrypoint(c *check.C) {
name := "testbuildentrypoint"
expected := "{[]}"
expected := "[]"

_, err := buildImage(name,
`FROM busybox
Expand All @@ -2405,7 +2405,7 @@ func (s *DockerSuite) TestBuildEmptyEntrypoint(c *check.C) {
func (s *DockerSuite) TestBuildEntrypoint(c *check.C) {
name := "testbuildentrypoint"

expected := "{[/bin/echo]}"
expected := "[/bin/echo]"
_, err := buildImage(name,
`FROM `+minimalBaseImage()+`
ENTRYPOINT ["/bin/echo"]`,
Expand Down Expand Up @@ -3087,7 +3087,7 @@ func (s *DockerSuite) TestBuildEntrypointRunCleanup(c *check.C) {
}
res := inspectField(c, name, "Config.Cmd")
// Cmd must be cleaned up
if res != "<nil>" {
if res != "[]" {
c.Fatalf("Cmd %s, expected nil", res)
}
}
Expand Down Expand Up @@ -3164,7 +3164,7 @@ func (s *DockerSuite) TestBuildInheritance(c *check.C) {
}

res := inspectField(c, name, "Config.Entrypoint")
if expected := "{[/bin/echo]}"; res != expected {
if expected := "[/bin/echo]"; res != expected {
c.Fatalf("Entrypoint %s, expected %s", res, expected)
}
ports2 := inspectField(c, name, "Config.ExposedPorts")
Expand Down Expand Up @@ -4367,12 +4367,12 @@ func (s *DockerSuite) TestBuildCleanupCmdOnEntrypoint(c *check.C) {
c.Fatal(err)
}
res := inspectField(c, name, "Config.Cmd")
if res != "<nil>" {
if res != "[]" {
c.Fatalf("Cmd %s, expected nil", res)
}

res = inspectField(c, name, "Config.Entrypoint")
if expected := "{[cat]}"; res != expected {
if expected := "[cat]"; res != expected {
c.Fatalf("Entrypoint %s, expected %s", res, expected)
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration-cli/docker_cli_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
"Config.ExposedPorts": "map[8080/tcp:{}]",
"Config.Env": "[DEBUG=true test=1 PATH=/foo]",
"Config.Labels": "map[foo:bar]",
"Config.Cmd": "{[/bin/sh]}",
"Config.Cmd": "[/bin/sh]",
"Config.WorkingDir": "/opt",
"Config.Entrypoint": "{[/bin/sh]}",
"Config.Entrypoint": "[/bin/sh]",
"Config.User": "testuser",
"Config.Volumes": "map[/var/lib/docker:{}]",
"Config.OnBuild": "[/usr/local/bin/python-build --dir /app/src]",
Expand Down
16 changes: 6 additions & 10 deletions runconfig/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ func Compare(a, b *container.Config) bool {
return false
}

if a.Cmd.Len() != b.Cmd.Len() ||
if len(a.Cmd) != len(b.Cmd) ||
len(a.Env) != len(b.Env) ||
len(a.Labels) != len(b.Labels) ||
len(a.ExposedPorts) != len(b.ExposedPorts) ||
a.Entrypoint.Len() != b.Entrypoint.Len() ||
len(a.Entrypoint) != len(b.Entrypoint) ||
len(a.Volumes) != len(b.Volumes) {
return false
}

aCmd := a.Cmd.Slice()
bCmd := b.Cmd.Slice()
for i := 0; i < len(aCmd); i++ {
if aCmd[i] != bCmd[i] {
for i := 0; i < len(a.Cmd); i++ {
if a.Cmd[i] != b.Cmd[i] {
return false
}
}
Expand All @@ -49,10 +47,8 @@ func Compare(a, b *container.Config) bool {
}
}

aEntrypoint := a.Entrypoint.Slice()
bEntrypoint := b.Entrypoint.Slice()
for i := 0; i < len(aEntrypoint); i++ {
if aEntrypoint[i] != bEntrypoint[i] {
for i := 0; i < len(a.Entrypoint); i++ {
if a.Entrypoint[i] != b.Entrypoint[i] {
return false
}
}
Expand Down
12 changes: 6 additions & 6 deletions runconfig/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func TestCompare(t *testing.T) {
volumes3["/test3"] = struct{}{}
envs1 := []string{"ENV1=value1", "ENV2=value2"}
envs2 := []string{"ENV1=value1", "ENV3=value3"}
entrypoint1 := strslice.New("/bin/sh", "-c")
entrypoint2 := strslice.New("/bin/sh", "-d")
entrypoint3 := strslice.New("/bin/sh", "-c", "echo")
cmd1 := strslice.New("/bin/sh", "-c")
cmd2 := strslice.New("/bin/sh", "-d")
cmd3 := strslice.New("/bin/sh", "-c", "echo")
entrypoint1 := strslice.StrSlice{"/bin/sh", "-c"}
entrypoint2 := strslice.StrSlice{"/bin/sh", "-d"}
entrypoint3 := strslice.StrSlice{"/bin/sh", "-c", "echo"}
cmd1 := strslice.StrSlice{"/bin/sh", "-c"}
cmd2 := strslice.StrSlice{"/bin/sh", "-d"}
cmd3 := strslice.StrSlice{"/bin/sh", "-c", "echo"}
labels1 := map[string]string{"LABEL1": "value1", "LABEL2": "value2"}
labels2 := map[string]string{"LABEL1": "value1", "LABEL2": "value3"}
labels3 := map[string]string{"LABEL1": "value1", "LABEL2": "value2", "LABEL3": "value3"}
Expand Down
Loading

0 comments on commit 53b0d62

Please sign in to comment.