Browse code

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>

Daniel Nephin authored on 2017/04/26 01:21:43
Showing 3 changed files
... ...
@@ -368,7 +368,9 @@ func run(req dispatchRequest) error {
368 368
 		saveCmd = prependEnvOnCmd(req.builder.buildArgs, buildArgs, cmdFromArgs)
369 369
 	}
370 370
 
371
-	runConfigForCacheProbe := copyRunConfig(req.runConfig, withCmd(saveCmd))
371
+	runConfigForCacheProbe := copyRunConfig(req.runConfig,
372
+		withCmd(saveCmd),
373
+		withEntrypointOverride(saveCmd, nil))
372 374
 	hit, err := req.builder.probeCache(req.builder.image, runConfigForCacheProbe)
373 375
 	if err != nil || hit {
374 376
 		return err
... ...
@@ -376,18 +378,13 @@ func run(req dispatchRequest) error {
376 376
 
377 377
 	runConfig := copyRunConfig(req.runConfig,
378 378
 		withCmd(cmdFromArgs),
379
-		withEnv(append(req.runConfig.Env, buildArgs...)))
379
+		withEnv(append(req.runConfig.Env, buildArgs...)),
380
+		withEntrypointOverride(saveCmd, strslice.StrSlice{""}))
380 381
 
381 382
 	// set config as already being escaped, this prevents double escaping on windows
382 383
 	runConfig.ArgsEscaped = true
383 384
 
384 385
 	logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
385
-
386
-	// Set blank entrypoint to cancel the entrypoint from the parent image
387
-	if len(runConfig.Cmd) > 0 {
388
-		runConfig.Entrypoint = strslice.StrSlice{""}
389
-	}
390
-
391 386
 	cID, err := req.builder.create(runConfig)
392 387
 	if err != nil {
393 388
 		return err
... ...
@@ -65,7 +65,8 @@ func (b *Builder) commitContainer(id string, containerConfig *container.Config)
65 65
 		ContainerCommitConfig: types.ContainerCommitConfig{
66 66
 			Author: b.maintainer,
67 67
 			Pause:  true,
68
-			Config: b.runConfig,
68
+			// TODO: this should be done by Commit()
69
+			Config: copyRunConfig(b.runConfig),
69 70
 		},
70 71
 		ContainerConfig: containerConfig,
71 72
 	}
... ...
@@ -233,6 +234,21 @@ func withEnv(env []string) runConfigModifier {
233 233
 	}
234 234
 }
235 235
 
236
+// withEntrypointOverride sets an entrypoint on runConfig if the command is
237
+// not empty. The entrypoint is left unmodified if command is empty.
238
+//
239
+// The dockerfile RUN instruction expect to run without an entrypoint
240
+// so the runConfig entrypoint needs to be modified accordingly. ContainerCreate
241
+// will change a []string{""} entrypoint to nil, so we probe the cache with the
242
+// nil entrypoint.
243
+func withEntrypointOverride(cmd []string, entrypoint []string) runConfigModifier {
244
+	return func(runConfig *container.Config) {
245
+		if len(cmd) > 0 {
246
+			runConfig.Entrypoint = entrypoint
247
+		}
248
+	}
249
+}
250
+
236 251
 // getShell is a helper function which gets the right shell for prefixing the
237 252
 // shell-form of RUN, ENTRYPOINT and CMD instructions
238 253
 func getShell(c *container.Config) []string {
... ...
@@ -1785,11 +1785,17 @@ func (s *DockerSuite) TestBuildConditionalCache(c *check.C) {
1785 1785
 	}
1786 1786
 }
1787 1787
 
1788
-// FIXME(vdemeester) this really seems to test the same thing as before
1789 1788
 func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check.C) {
1790 1789
 	name := "testbuildaddmultiplelocalfilewithcache"
1791
-	dockerfile := `
1790
+	baseName := name + "-base"
1791
+
1792
+	cli.BuildCmd(c, baseName, build.WithDockerfile(`
1792 1793
 		FROM busybox
1794
+		ENTRYPOINT ["/bin/sh"]
1795
+	`))
1796
+
1797
+	dockerfile := `
1798
+		FROM testbuildaddmultiplelocalfilewithcache-base
1793 1799
         MAINTAINER dockerio
1794 1800
         ADD foo Dockerfile /usr/lib/bla/
1795 1801
 		RUN sh -c "[ $(cat /usr/lib/bla/foo) = "hello" ]"`
... ...
@@ -1799,15 +1805,15 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check.
1799 1799
 	defer ctx.Close()
1800 1800
 	cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
1801 1801
 	id1 := getIDByName(c, name)
1802
-	cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
1802
+	result2 := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
1803 1803
 	id2 := getIDByName(c, name)
1804
-	cli.BuildCmd(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx))
1804
+	result3 := cli.BuildCmd(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx))
1805 1805
 	id3 := getIDByName(c, name)
1806 1806
 	if id1 != id2 {
1807
-		c.Fatal("The cache should have been used but hasn't.")
1807
+		c.Fatalf("The cache should have been used but hasn't: %s", result2.Stdout())
1808 1808
 	}
1809 1809
 	if id1 == id3 {
1810
-		c.Fatal("The cache should have been invalided but hasn't.")
1810
+		c.Fatalf("The cache should have been invalided but hasn't: %s", result3.Stdout())
1811 1811
 	}
1812 1812
 }
1813 1813