Browse code

Use parent image config in buildfile

Michael Crosby authored on 2013/11/05 06:20:14
Showing 2 changed files
... ...
@@ -65,6 +65,9 @@ func (b *buildFile) CmdFrom(name string) error {
65 65
 	}
66 66
 	b.image = image.ID
67 67
 	b.config = &Config{}
68
+	if image.Config != nil {
69
+		b.config = image.Config
70
+	}
68 71
 	if b.config.Env == nil || len(b.config.Env) == 0 {
69 72
 		b.config.Env = append(b.config.Env, "HOME=/", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
70 73
 	}
... ...
@@ -542,3 +542,39 @@ func TestBuildADDFileNotFound(t *testing.T) {
542 542
 		t.Fail()
543 543
 	}
544 544
 }
545
+
546
+func TestBuildInheritance(t *testing.T) {
547
+	runtime, err := newTestRuntime("")
548
+	if err != nil {
549
+		t.Fatal(err)
550
+	}
551
+	defer nuke(runtime)
552
+
553
+	srv := &Server{
554
+		runtime:     runtime,
555
+		pullingPool: make(map[string]struct{}),
556
+		pushingPool: make(map[string]struct{}),
557
+	}
558
+
559
+	img := buildImage(testContextTemplate{`
560
+            from {IMAGE}
561
+            expose 4243
562
+            `,
563
+		nil, nil}, t, srv, true)
564
+
565
+	img2 := buildImage(testContextTemplate{fmt.Sprintf(`
566
+            from %s
567
+            entrypoint ["/bin/echo"]
568
+            `, img.ID),
569
+		nil, nil}, t, srv, true)
570
+
571
+	// from child
572
+	if img2.Config.Entrypoint[0] != "/bin/echo" {
573
+		t.Fail()
574
+	}
575
+
576
+	// from parent
577
+	if img.Config.PortSpecs[0] != "4243" {
578
+		t.Fail()
579
+	}
580
+}