diff --git a/src/cmd/rocker/main.go b/src/cmd/rocker/main.go index d8472b56..37275b3c 100644 --- a/src/cmd/rocker/main.go +++ b/src/cmd/rocker/main.go @@ -110,6 +110,10 @@ func main() { Name: "print", Usage: "just print the Rockerfile after template processing and stop", }, + cli.StringFlag{ + Name: "id", + Usage: "override the default id generation strategy for current build", + }, } app.Commands = []cli.Command{ @@ -229,6 +233,7 @@ func buildCommand(c *cli.Context) { OutStream: os.Stdout, Docker: dockerClient, AddMeta: c.Bool("meta"), + Id: c.String("id"), } if _, err := builder.Build(); err != nil { diff --git a/src/rocker/build/builder.go b/src/rocker/build/builder.go index afbd21d6..428c38d2 100644 --- a/src/rocker/build/builder.go +++ b/src/rocker/build/builder.go @@ -53,6 +53,7 @@ type Builder struct { Rockerfile string RockerfileContent string ContextDir string + Id string OutStream io.Writer InStream io.ReadCloser Docker *docker.Client @@ -360,16 +361,24 @@ func (builder *Builder) getTmpPrefix() string { return ".rockertmp" } +// getIdentifier returns the sequence that is unique to the current Rockerfile +func (builder *Builder) getIdentifier() string { + if builder.Id != "" { + return builder.Id + } + return builder.ContextDir + ":" + builder.Rockerfile +} + // mountsContainerName returns the name of volume container that will be used for a particular MOUNT func (builder *Builder) mountsContainerName(destinations []string) string { // TODO: should mounts be reused between different FROMs ? - mountID := builder.ContextDir + ":" + builder.Rockerfile + ":" + strings.Join(destinations, ":") + mountID := builder.getIdentifier() + ":" + strings.Join(destinations, ":") return fmt.Sprintf("rocker_mount_%.6x", md5.Sum([]byte(mountID))) } // exportsContainerName return the name of volume container that will be used for EXPORTs func (builder *Builder) exportsContainerName() string { - mountID := builder.ContextDir + ":" + builder.Rockerfile + mountID := builder.getIdentifier() return fmt.Sprintf("rocker_exports_%.6x", md5.Sum([]byte(mountID))) }