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 <dnephin@docker.com>
This commit is contained in:
parent
97f8607164
commit
d9371ee807
3 changed files with 34 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue