diff --git a/builder/dispatchers.go b/builder/dispatchers.go index 0c2a580872c6a35001acfd36174332361c782139..e585c4021e46911d793adb26738a2ad4410610b5 100644 --- a/builder/dispatchers.go +++ b/builder/dispatchers.go @@ -195,7 +195,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string) defer func(cmd []string) { b.Config.Cmd = cmd }(cmd) - log.Debugf("Command to be executed: %v", b.Config.Cmd) + log.Debugf("[BUILDER] Command to be executed: %v", b.Config.Cmd) hit, err := b.probeCache() if err != nil { @@ -261,14 +261,14 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original parsed := handleJsonArgs(args, attributes) switch { - case len(parsed) == 0: - // ENTYRPOINT [] - b.Config.Entrypoint = nil case attributes["json"]: // ENTRYPOINT ["echo", "hi"] b.Config.Entrypoint = parsed + case len(parsed) == 0: + // ENTRYPOINT [] + b.Config.Entrypoint = nil default: - // ENTYRPOINT echo hi + // ENTRYPOINT echo hi b.Config.Entrypoint = []string{"/bin/sh", "-c", parsed[0]} } diff --git a/builder/evaluator.go b/builder/evaluator.go index 4122616350abb4c70ef2a4a03e40280acc668297..aed8d29335f251c47d7054a86952b639d8d924c1 100644 --- a/builder/evaluator.go +++ b/builder/evaluator.go @@ -149,7 +149,7 @@ func (b *Builder) Run(context io.Reader) (string, error) { b.dockerfile = ast // some initializations that would not have been supplied by the caller. - b.Config = &runconfig.Config{Entrypoint: []string{}, Cmd: nil} + b.Config = &runconfig.Config{} b.TmpContainers = map[string]struct{}{} for i, n := range b.dockerfile.Children { diff --git a/builder/parser/parser.go b/builder/parser/parser.go index 5e8bcb5a9cd40d186ed4ade31f094ea754b9d5af..6b0ab7ab8c72983ff1ce53339342e297ae9f3631 100644 --- a/builder/parser/parser.go +++ b/builder/parser/parser.go @@ -87,10 +87,11 @@ func parseLine(line string) (string, *Node, error) { if sexp.Value != "" || sexp.Next != nil || sexp.Children != nil { node.Next = sexp - node.Attributes = attrs - node.Original = line } + node.Attributes = attrs + node.Original = line + return "", node, nil } diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 808f64c7e9c096a36de64940b860b428918aff1a..8be0e01a26491606e2b95830e9ae25af1dabda5d 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -1362,6 +1362,49 @@ func TestBuildExpose(t *testing.T) { logDone("build - expose") } +func TestBuildEmptyEntrypointInheritance(t *testing.T) { + name := "testbuildentrypointinheritance" + name2 := "testbuildentrypointinheritance2" + defer deleteImages(name, name2) + + _, err := buildImage(name, + `FROM busybox + ENTRYPOINT ["/bin/echo"]`, + true) + if err != nil { + t.Fatal(err) + } + res, err := inspectField(name, "Config.Entrypoint") + if err != nil { + t.Fatal(err) + } + + expected := "[/bin/echo]" + if res != expected { + t.Fatalf("Entrypoint %s, expected %s", res, expected) + } + + _, err = buildImage(name2, + fmt.Sprintf(`FROM %s + ENTRYPOINT []`, name), + true) + if err != nil { + t.Fatal(err) + } + res, err = inspectField(name2, "Config.Entrypoint") + if err != nil { + t.Fatal(err) + } + + expected = "[]" + + if res != expected { + t.Fatalf("Entrypoint %s, expected %s", res, expected) + } + + logDone("build - empty entrypoint inheritance") +} + func TestBuildEmptyEntrypoint(t *testing.T) { name := "testbuildentrypoint" defer deleteImages(name) diff --git a/runconfig/merge.go b/runconfig/merge.go index 0c60d1df0b9ea4fd815891cde6406054be2b852d..64950bf625fc0cc0d2949fe2ec9cdb1eba43d326 100644 --- a/runconfig/merge.go +++ b/runconfig/merge.go @@ -88,7 +88,10 @@ func Merge(userConf, imageConf *Config) error { if len(userConf.Cmd) == 0 { userConf.Cmd = imageConf.Cmd } - userConf.Entrypoint = imageConf.Entrypoint + + if userConf.Entrypoint == nil { + userConf.Entrypoint = imageConf.Entrypoint + } } if userConf.WorkingDir == "" { userConf.WorkingDir = imageConf.WorkingDir