Skip to content

Commit

Permalink
builder: some small fixups + fix a bug where empty entrypoints would …
Browse files Browse the repository at this point in the history
…not override inheritance.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <[email protected]> (github: erikh)
  • Loading branch information
Erik Hollensbe committed Oct 24, 2014
1 parent 45c511f commit cdd6e97
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
10 changes: 5 additions & 5 deletions builder/dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]}
}

Expand Down
2 changes: 1 addition & 1 deletion builder/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions builder/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
43 changes: 43 additions & 0 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,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)
Expand Down
5 changes: 4 additions & 1 deletion runconfig/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cdd6e97

Please sign in to comment.