Skip to content

Instantly share code, notes, and snippets.

@cpuguy83
Created December 27, 2013 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpuguy83/8152875 to your computer and use it in GitHub Desktop.
Save cpuguy83/8152875 to your computer and use it in GitHub Desktop.
extract functionality for building CMD and ENTRYPOINT
func (b *buildFile) BuildCmdFromJson(args string) []string {
var cmd []string
if err := json.Unmarshal([]byte(args), &cmd); err != nil {
utils.Debugf("Error unmarhsalling: %s, setting %s to /bin/sh -c", err)
cmd = []string{"/bin/sh", "-c", args}
}
return cmd
}
func (b *buildFile) CmdCmd(args string) error {
cmd := b.BuildCmdFromJson(args)
if err := b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)); err != nil {
return err
}
b.config.Cmd = cmd
return nil
}
func (b *buildFile) CmdEntrypoint(args string) error {
entrypoint := b.BuildCmdFromJson(args)
if err := b.commit("", entrypoint, fmt.Sprintf("ENTRYPOINT %v", entrypoint)); err != nil {
return err
}
b.config.Entrypoint = entrypoint
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment