1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use same error handling while unmarshalling args for CMD and ENTRYPOINT

This commit is contained in:
Brian Goff 2013-12-27 21:06:26 -05:00
parent c23b15b9d8
commit 323c4b5211
2 changed files with 20 additions and 21 deletions

View file

@ -271,16 +271,30 @@ func (b *buildFile) CmdEnv(args string) error {
return b.commit("", b.config.Cmd, fmt.Sprintf("ENV %s", replacedVar)) return b.commit("", b.config.Cmd, fmt.Sprintf("ENV %s", replacedVar))
} }
func (b *buildFile) CmdCmd(args string) error { func (b *buildFile) buildCmdFromJson(args string) []string {
var cmd []string var cmd []string
if err := json.Unmarshal([]byte(args), &cmd); err != nil { if err := json.Unmarshal([]byte(args), &cmd); err != nil {
utils.Debugf("Error unmarshalling: %s, setting cmd to /bin/sh -c", err) utils.Debugf("Error unmarshalling: %s, setting to /bin/sh -c", err)
cmd = []string{"/bin/sh", "-c", args} cmd = []string{"/bin/sh", "-c", args}
} }
if err := b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)); err != nil { return cmd
}
func (b *buildFile) CmdCmd(args string) error {
cmd := b.buildCmdFromJson(args)
b.config.Cmd = cmd
if err := b.commit("", b.config.Cmd, fmt.Sprintf("CMD %v", cmd)); err != nil {
return err
}
return nil
}
func (b *buildFile) CmdEntrypoint(args string) error {
entrypoint := b.buildCmdFromJson(args)
b.config.Entrypoint = entrypoint
if err := b.commit("", b.config.Cmd, fmt.Sprintf("ENTRYPOINT %v", entrypoint)); err != nil {
return err return err
} }
b.config.Cmd = cmd
return nil return nil
} }
@ -303,23 +317,6 @@ func (b *buildFile) CmdCopy(args string) error {
return fmt.Errorf("COPY has been deprecated. Please use ADD instead") return fmt.Errorf("COPY has been deprecated. Please use ADD instead")
} }
func (b *buildFile) CmdEntrypoint(args string) error {
if args == "" {
return fmt.Errorf("Entrypoint cannot be empty")
}
var entrypoint []string
if err := json.Unmarshal([]byte(args), &entrypoint); err != nil {
b.config.Entrypoint = []string{"/bin/sh", "-c", args}
} else {
b.config.Entrypoint = entrypoint
}
if err := b.commit("", b.config.Cmd, fmt.Sprintf("ENTRYPOINT %s", args)); err != nil {
return err
}
return nil
}
func (b *buildFile) CmdWorkdir(workdir string) error { func (b *buildFile) CmdWorkdir(workdir string) error {
b.config.WorkingDir = workdir b.config.WorkingDir = workdir
return b.commit("", b.config.Cmd, fmt.Sprintf("WORKDIR %v", workdir)) return b.commit("", b.config.Cmd, fmt.Sprintf("WORKDIR %v", workdir))

View file

@ -391,6 +391,8 @@ func TestBuildEntrypoint(t *testing.T) {
} }
if img.Config.Entrypoint[0] != "/bin/echo" { if img.Config.Entrypoint[0] != "/bin/echo" {
t.Log(img.Config.Entrypoint[0])
t.Fail()
} }
} }