From fe0fe929451fd555c650366d436133c4af46ad52 Mon Sep 17 00:00:00 2001 From: Isao Jonas Date: Sun, 4 Aug 2013 19:11:23 -0500 Subject: [PATCH 1/2] fix entrypoint without cmd Upstream-commit: 0f249c85ea9acc7fba33994aa5d20a897463db2c Component: engine --- components/engine/builder.go | 4 +++- components/engine/buildfile.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/engine/builder.go b/components/engine/builder.go index 82ad1c1271..9124f76ac1 100644 --- a/components/engine/builder.go +++ b/components/engine/builder.go @@ -38,7 +38,9 @@ func (builder *Builder) Create(config *Config) (*Container, error) { MergeConfig(config, img.Config) } - if config.Cmd == nil || len(config.Cmd) == 0 { + if len(config.Entrypoint) != 0 && config.Cmd == nil { + config.Cmd = []string{} + } else if config.Cmd == nil || len(config.Cmd) == 0 { return nil, fmt.Errorf("No command specified") } diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 159d7ba704..ba4427a49f 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -93,6 +93,8 @@ func (b *buildFile) CmdRun(args string) error { b.config.Cmd = nil MergeConfig(b.config, config) + defer func(cmd []string) { b.config.Cmd = cmd }(cmd) + utils.Debugf("Command to be executed: %v", b.config.Cmd) if b.utilizeCache { @@ -115,7 +117,7 @@ func (b *buildFile) CmdRun(args string) error { if err := b.commit(cid, cmd, "run"); err != nil { return err } - b.config.Cmd = cmd + return nil } From d445832a9e40816b1b408c614f78a3cb56736c2d Mon Sep 17 00:00:00 2001 From: Isao Jonas Date: Mon, 5 Aug 2013 09:03:42 -0500 Subject: [PATCH 2/2] added tests for 1405 Upstream-commit: d00fb4096700cd8feed06ca32c93f080fb6446b1 Component: engine --- components/engine/buildfile_test.go | 34 +++++++++++++++++++++++++++++ components/engine/container_test.go | 22 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/components/engine/buildfile_test.go b/components/engine/buildfile_test.go index 0e2d9ecefc..9d002f0665 100644 --- a/components/engine/buildfile_test.go +++ b/components/engine/buildfile_test.go @@ -328,6 +328,40 @@ func TestBuildEntrypoint(t *testing.T) { } } +// testing #1405 - config.Cmd does not get cleaned up if +// utilizing cache +func TestBuildEntrypointRunCleanup(t *testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + srv := &Server{ + runtime: runtime, + pullingPool: make(map[string]struct{}), + pushingPool: make(map[string]struct{}), + } + + img := buildImage(testContextTemplate{` + from {IMAGE} + run echo "hello" + `, + nil, nil}, t, srv, true) + + img = buildImage(testContextTemplate{` + from {IMAGE} + run echo "hello" + add foo /foo + entrypoint ["/bin/echo"] + `, + [][2]string{{"foo", "HEYO"}}, nil}, t, srv, true) + + if len(img.Config.Cmd) != 0 { + t.Fail() + } +} + func TestBuildImageWithCache(t *testing.T) { runtime, err := newTestRuntime() if err != nil { diff --git a/components/engine/container_test.go b/components/engine/container_test.go index f29ae9e4ea..2f9da15f6e 100644 --- a/components/engine/container_test.go +++ b/components/engine/container_test.go @@ -996,6 +996,28 @@ func TestEntrypoint(t *testing.T) { } } +func TestEntrypointNoCmd(t *testing.T) { + runtime := mkRuntime(t) + defer nuke(runtime) + container, err := NewBuilder(runtime).Create( + &Config{ + Image: GetTestImage(runtime).ID, + Entrypoint: []string{"/bin/echo", "foobar"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container) + output, err := container.Output() + if err != nil { + t.Fatal(err) + } + if strings.Trim(string(output), "\r\n") != "foobar" { + t.Error(string(output)) + } +} + func grepFile(t *testing.T, path string, pattern string) { f, err := os.Open(path) if err != nil {