Bladeren bron

Merge pull request #1405 from jonasi/entrypoint-noargs

*Runtime: Allow ENTRYPOINT without CMD
Victor Vieux 12 jaren geleden
bovenliggende
commit
bdc0e8f825
4 gewijzigde bestanden met toevoegingen van 62 en 2 verwijderingen
  1. 3 1
      builder.go
  2. 3 1
      buildfile.go
  3. 34 0
      buildfile_test.go
  4. 22 0
      container_test.go

+ 3 - 1
builder.go

@@ -38,7 +38,9 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
 		MergeConfig(config, img.Config)
 	}
 
-	if config.Cmd == nil || len(config.Cmd) == 0 {
+	if len(config.Entrypoint) != 0 && config.Cmd == nil {
+		config.Cmd = []string{}
+	} else if config.Cmd == nil || len(config.Cmd) == 0 {
 		return nil, fmt.Errorf("No command specified")
 	}
 

+ 3 - 1
buildfile.go

@@ -93,6 +93,8 @@ func (b *buildFile) CmdRun(args string) error {
 	b.config.Cmd = nil
 	MergeConfig(b.config, config)
 
+	defer func(cmd []string) { b.config.Cmd = cmd }(cmd)
+
 	utils.Debugf("Command to be executed: %v", b.config.Cmd)
 
 	if b.utilizeCache {
@@ -115,7 +117,7 @@ func (b *buildFile) CmdRun(args string) error {
 	if err := b.commit(cid, cmd, "run"); err != nil {
 		return err
 	}
-	b.config.Cmd = cmd
+
 	return nil
 }
 

+ 34 - 0
buildfile_test.go

@@ -328,6 +328,40 @@ func TestBuildEntrypoint(t *testing.T) {
 	}
 }
 
+// testing #1405 - config.Cmd does not get cleaned up if
+// utilizing cache
+func TestBuildEntrypointRunCleanup(t *testing.T) {
+	runtime, err := newTestRuntime()
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer nuke(runtime)
+
+	srv := &Server{
+		runtime:     runtime,
+		pullingPool: make(map[string]struct{}),
+		pushingPool: make(map[string]struct{}),
+	}
+
+	img := buildImage(testContextTemplate{`
+        from {IMAGE}
+        run echo "hello"
+        `,
+		nil, nil}, t, srv, true)
+
+	img = buildImage(testContextTemplate{`
+        from {IMAGE}
+        run echo "hello"
+        add foo /foo
+        entrypoint ["/bin/echo"]
+        `,
+		[][2]string{{"foo", "HEYO"}}, nil}, t, srv, true)
+
+	if len(img.Config.Cmd) != 0 {
+		t.Fail()
+	}
+}
+
 func TestBuildImageWithCache(t *testing.T) {
 	runtime, err := newTestRuntime()
 	if err != nil {

+ 22 - 0
container_test.go

@@ -996,6 +996,28 @@ func TestEntrypoint(t *testing.T) {
 	}
 }
 
+func TestEntrypointNoCmd(t *testing.T) {
+	runtime := mkRuntime(t)
+	defer nuke(runtime)
+	container, err := NewBuilder(runtime).Create(
+		&Config{
+			Image:      GetTestImage(runtime).ID,
+			Entrypoint: []string{"/bin/echo", "foobar"},
+		},
+	)
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer runtime.Destroy(container)
+	output, err := container.Output()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if strings.Trim(string(output), "\r\n") != "foobar" {
+		t.Error(string(output))
+	}
+}
+
 func grepFile(t *testing.T, path string, pattern string) {
 	f, err := os.Open(path)
 	if err != nil {