Browse Source

Merge pull request #10123 from duglin/Issue10097

Build CMD/ENTRYPOINT cache strings properly
Tibor Vass 10 years ago
parent
commit
70fbd45a5c
2 changed files with 40 additions and 2 deletions
  1. 2 2
      builder/dispatchers.go
  2. 38 0
      integration-cli/docker_cli_build_test.go

+ 2 - 2
builder/dispatchers.go

@@ -272,7 +272,7 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string)
 		b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
 		b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
 	}
 	}
 
 
-	if err := b.commit("", b.Config.Cmd, fmt.Sprintf("CMD %v", b.Config.Cmd)); err != nil {
+	if err := b.commit("", b.Config.Cmd, fmt.Sprintf("CMD %q", b.Config.Cmd)); err != nil {
 		return err
 		return err
 	}
 	}
 
 
@@ -312,7 +312,7 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original
 		b.Config.Cmd = nil
 		b.Config.Cmd = nil
 	}
 	}
 
 
-	if err := b.commit("", b.Config.Cmd, fmt.Sprintf("ENTRYPOINT %v", b.Config.Entrypoint)); err != nil {
+	if err := b.commit("", b.Config.Cmd, fmt.Sprintf("ENTRYPOINT %q", b.Config.Entrypoint)); err != nil {
 		return err
 		return err
 	}
 	}
 
 

+ 38 - 0
integration-cli/docker_cli_build_test.go

@@ -4091,6 +4091,44 @@ func TestBuildCmdShDashC(t *testing.T) {
 	logDone("build - cmd should have sh -c for non-json")
 	logDone("build - cmd should have sh -c for non-json")
 }
 }
 
 
+func TestBuildCmdSpaces(t *testing.T) {
+	// Test to make sure that when we strcat arrays we take into account
+	// the arg separator to make sure ["echo","hi"] and ["echo hi"] don't
+	// look the same
+	name := "testbuildcmdspaces"
+	defer deleteImages(name)
+	var id1 string
+	var id2 string
+	var err error
+
+	if id1, err = buildImage(name, "FROM busybox\nCMD [\"echo hi\"]\n", true); err != nil {
+		t.Fatal(err)
+	}
+
+	if id2, err = buildImage(name, "FROM busybox\nCMD [\"echo\", \"hi\"]\n", true); err != nil {
+		t.Fatal(err)
+	}
+
+	if id1 == id2 {
+		t.Fatal("Should not have resulted in the same CMD")
+	}
+
+	// Now do the same with ENTRYPOINT
+	if id1, err = buildImage(name, "FROM busybox\nENTRYPOINT [\"echo hi\"]\n", true); err != nil {
+		t.Fatal(err)
+	}
+
+	if id2, err = buildImage(name, "FROM busybox\nENTRYPOINT [\"echo\", \"hi\"]\n", true); err != nil {
+		t.Fatal(err)
+	}
+
+	if id1 == id2 {
+		t.Fatal("Should not have resulted in the same ENTRYPOINT")
+	}
+
+	logDone("build - cmd with spaces")
+}
+
 func TestBuildCmdJSONNoShDashC(t *testing.T) {
 func TestBuildCmdJSONNoShDashC(t *testing.T) {
 	name := "testbuildcmdjson"
 	name := "testbuildcmdjson"
 	defer deleteImages(name)
 	defer deleteImages(name)