Browse code

builder: some small fixups + fix a bug where empty entrypoints would not override inheritance.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)

Erik Hollensbe authored on 2014/10/24 09:23:25
Showing 5 changed files
... ...
@@ -195,7 +195,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
195 195
 
196 196
 	defer func(cmd []string) { b.Config.Cmd = cmd }(cmd)
197 197
 
198
-	log.Debugf("Command to be executed: %v", b.Config.Cmd)
198
+	log.Debugf("[BUILDER] Command to be executed: %v", b.Config.Cmd)
199 199
 
200 200
 	hit, err := b.probeCache()
201 201
 	if err != nil {
... ...
@@ -261,14 +261,14 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original
261 261
 	parsed := handleJsonArgs(args, attributes)
262 262
 
263 263
 	switch {
264
-	case len(parsed) == 0:
265
-		// ENTYRPOINT []
266
-		b.Config.Entrypoint = nil
267 264
 	case attributes["json"]:
268 265
 		// ENTRYPOINT ["echo", "hi"]
269 266
 		b.Config.Entrypoint = parsed
267
+	case len(parsed) == 0:
268
+		// ENTRYPOINT []
269
+		b.Config.Entrypoint = nil
270 270
 	default:
271
-		// ENTYRPOINT echo hi
271
+		// ENTRYPOINT echo hi
272 272
 		b.Config.Entrypoint = []string{"/bin/sh", "-c", parsed[0]}
273 273
 	}
274 274
 
... ...
@@ -149,7 +149,7 @@ func (b *Builder) Run(context io.Reader) (string, error) {
149 149
 	b.dockerfile = ast
150 150
 
151 151
 	// some initializations that would not have been supplied by the caller.
152
-	b.Config = &runconfig.Config{Entrypoint: []string{}, Cmd: nil}
152
+	b.Config = &runconfig.Config{}
153 153
 	b.TmpContainers = map[string]struct{}{}
154 154
 
155 155
 	for i, n := range b.dockerfile.Children {
... ...
@@ -87,10 +87,11 @@ func parseLine(line string) (string, *Node, error) {
87 87
 
88 88
 	if sexp.Value != "" || sexp.Next != nil || sexp.Children != nil {
89 89
 		node.Next = sexp
90
-		node.Attributes = attrs
91
-		node.Original = line
92 90
 	}
93 91
 
92
+	node.Attributes = attrs
93
+	node.Original = line
94
+
94 95
 	return "", node, nil
95 96
 }
96 97
 
... ...
@@ -1429,6 +1429,49 @@ func TestBuildExpose(t *testing.T) {
1429 1429
 	logDone("build - expose")
1430 1430
 }
1431 1431
 
1432
+func TestBuildEmptyEntrypointInheritance(t *testing.T) {
1433
+	name := "testbuildentrypointinheritance"
1434
+	name2 := "testbuildentrypointinheritance2"
1435
+	defer deleteImages(name, name2)
1436
+
1437
+	_, err := buildImage(name,
1438
+		`FROM busybox
1439
+        ENTRYPOINT ["/bin/echo"]`,
1440
+		true)
1441
+	if err != nil {
1442
+		t.Fatal(err)
1443
+	}
1444
+	res, err := inspectField(name, "Config.Entrypoint")
1445
+	if err != nil {
1446
+		t.Fatal(err)
1447
+	}
1448
+
1449
+	expected := "[/bin/echo]"
1450
+	if res != expected {
1451
+		t.Fatalf("Entrypoint %s, expected %s", res, expected)
1452
+	}
1453
+
1454
+	_, err = buildImage(name2,
1455
+		fmt.Sprintf(`FROM %s
1456
+        ENTRYPOINT []`, name),
1457
+		true)
1458
+	if err != nil {
1459
+		t.Fatal(err)
1460
+	}
1461
+	res, err = inspectField(name2, "Config.Entrypoint")
1462
+	if err != nil {
1463
+		t.Fatal(err)
1464
+	}
1465
+
1466
+	expected = "[]"
1467
+
1468
+	if res != expected {
1469
+		t.Fatalf("Entrypoint %s, expected %s", res, expected)
1470
+	}
1471
+
1472
+	logDone("build - empty entrypoint inheritance")
1473
+}
1474
+
1432 1475
 func TestBuildEmptyEntrypoint(t *testing.T) {
1433 1476
 	name := "testbuildentrypoint"
1434 1477
 	defer deleteImages(name)
... ...
@@ -88,7 +88,10 @@ func Merge(userConf, imageConf *Config) error {
88 88
 		if len(userConf.Cmd) == 0 {
89 89
 			userConf.Cmd = imageConf.Cmd
90 90
 		}
91
-		userConf.Entrypoint = imageConf.Entrypoint
91
+
92
+		if userConf.Entrypoint == nil {
93
+			userConf.Entrypoint = imageConf.Entrypoint
94
+		}
92 95
 	}
93 96
 	if userConf.WorkingDir == "" {
94 97
 		userConf.WorkingDir = imageConf.WorkingDir