From d9371ee80764d0eecf7b8a562121f0a6234167a3 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 25 Apr 2017 12:21:43 -0400 Subject: [PATCH] Fix run with entrypoint in base image Update a test to use a base image with entrypoint to that the linux build has at least one test that behaves like all the windows tests. Signed-off-by: Daniel Nephin --- builder/dockerfile/dispatchers.go | 13 +++++-------- builder/dockerfile/internals.go | 18 +++++++++++++++++- integration-cli/docker_cli_build_test.go | 18 ++++++++++++------ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index 85f82806e9..0b76f2ff8e 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -368,7 +368,9 @@ func run(req dispatchRequest) error { saveCmd = prependEnvOnCmd(req.builder.buildArgs, buildArgs, cmdFromArgs) } - runConfigForCacheProbe := copyRunConfig(req.runConfig, withCmd(saveCmd)) + runConfigForCacheProbe := copyRunConfig(req.runConfig, + withCmd(saveCmd), + withEntrypointOverride(saveCmd, nil)) hit, err := req.builder.probeCache(req.builder.image, runConfigForCacheProbe) if err != nil || hit { return err @@ -376,18 +378,13 @@ func run(req dispatchRequest) error { runConfig := copyRunConfig(req.runConfig, withCmd(cmdFromArgs), - withEnv(append(req.runConfig.Env, buildArgs...))) + withEnv(append(req.runConfig.Env, buildArgs...)), + withEntrypointOverride(saveCmd, strslice.StrSlice{""})) // set config as already being escaped, this prevents double escaping on windows runConfig.ArgsEscaped = true logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd) - - // Set blank entrypoint to cancel the entrypoint from the parent image - if len(runConfig.Cmd) > 0 { - runConfig.Entrypoint = strslice.StrSlice{""} - } - cID, err := req.builder.create(runConfig) if err != nil { return err diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index 094331f1ff..55f3c15490 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -65,7 +65,8 @@ func (b *Builder) commitContainer(id string, containerConfig *container.Config) ContainerCommitConfig: types.ContainerCommitConfig{ Author: b.maintainer, Pause: true, - Config: b.runConfig, + // TODO: this should be done by Commit() + Config: copyRunConfig(b.runConfig), }, ContainerConfig: containerConfig, } @@ -233,6 +234,21 @@ func withEnv(env []string) runConfigModifier { } } +// withEntrypointOverride sets an entrypoint on runConfig if the command is +// not empty. The entrypoint is left unmodified if command is empty. +// +// The dockerfile RUN instruction expect to run without an entrypoint +// so the runConfig entrypoint needs to be modified accordingly. ContainerCreate +// will change a []string{""} entrypoint to nil, so we probe the cache with the +// nil entrypoint. +func withEntrypointOverride(cmd []string, entrypoint []string) runConfigModifier { + return func(runConfig *container.Config) { + if len(cmd) > 0 { + runConfig.Entrypoint = entrypoint + } + } +} + // getShell is a helper function which gets the right shell for prefixing the // shell-form of RUN, ENTRYPOINT and CMD instructions func getShell(c *container.Config) []string { diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 2e9b897d0f..701572908b 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -1785,11 +1785,17 @@ func (s *DockerSuite) TestBuildConditionalCache(c *check.C) { } } -// FIXME(vdemeester) this really seems to test the same thing as before func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check.C) { name := "testbuildaddmultiplelocalfilewithcache" - dockerfile := ` + baseName := name + "-base" + + cli.BuildCmd(c, baseName, build.WithDockerfile(` FROM busybox + ENTRYPOINT ["/bin/sh"] + `)) + + dockerfile := ` + FROM testbuildaddmultiplelocalfilewithcache-base MAINTAINER dockerio ADD foo Dockerfile /usr/lib/bla/ RUN sh -c "[ $(cat /usr/lib/bla/foo) = "hello" ]"` @@ -1799,15 +1805,15 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check. defer ctx.Close() cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) id1 := getIDByName(c, name) - cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) + result2 := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) id2 := getIDByName(c, name) - cli.BuildCmd(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx)) + result3 := cli.BuildCmd(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx)) id3 := getIDByName(c, name) if id1 != id2 { - c.Fatal("The cache should have been used but hasn't.") + c.Fatalf("The cache should have been used but hasn't: %s", result2.Stdout()) } if id1 == id3 { - c.Fatal("The cache should have been invalided but hasn't.") + c.Fatalf("The cache should have been invalided but hasn't: %s", result3.Stdout()) } }