mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #8284 from erikh/fix_cmd_again
builder: Fix CMD to inject /bin/sh -c when provided with a non-json value
This commit is contained in:
commit
670c8696a2
2 changed files with 43 additions and 1 deletions
|
@ -234,7 +234,7 @@ func cmd(b *Builder, args []string, attributes map[string]bool) error {
|
|||
b.Config.Cmd = handleJsonArgs(args, attributes)
|
||||
|
||||
if !attributes["json"] && len(b.Config.Entrypoint) == 0 {
|
||||
b.Config.Entrypoint = []string{"/bin/sh", "-c"}
|
||||
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 {
|
||||
|
|
|
@ -2403,3 +2403,45 @@ func TestBuildInvalidTag(t *testing.T) {
|
|||
}
|
||||
logDone("build - invalid tag")
|
||||
}
|
||||
|
||||
func TestBuildCmdShDashC(t *testing.T) {
|
||||
name := "testbuildcmdshc"
|
||||
defer deleteImages(name)
|
||||
if _, err := buildImage(name, "FROM busybox\nCMD echo cmd\n", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err := inspectFieldJSON(name, "Config.Cmd")
|
||||
if err != nil {
|
||||
t.Fatal(err, res)
|
||||
}
|
||||
|
||||
expected := `["/bin/sh","-c","echo cmd"]`
|
||||
|
||||
if res != expected {
|
||||
t.Fatalf("Expected value %s not in Config.Cmd: %s", expected, res)
|
||||
}
|
||||
|
||||
logDone("build - cmd should have sh -c for non-json")
|
||||
}
|
||||
|
||||
func TestBuildCmdJSONNoShDashC(t *testing.T) {
|
||||
name := "testbuildcmdjson"
|
||||
defer deleteImages(name)
|
||||
if _, err := buildImage(name, "FROM busybox\nCMD [\"echo\", \"cmd\"]", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err := inspectFieldJSON(name, "Config.Cmd")
|
||||
if err != nil {
|
||||
t.Fatal(err, res)
|
||||
}
|
||||
|
||||
expected := `["echo","cmd"]`
|
||||
|
||||
if res != expected {
|
||||
t.Fatalf("Expected value %s not in Config.Cmd: %s", expected, res)
|
||||
}
|
||||
|
||||
logDone("build - cmd should not have /bin/sh -c for json")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue