Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

#6 provide -id parameter #7

Merged
merged 1 commit into from
Sep 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cmd/rocker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions src/rocker/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Builder struct {
Rockerfile string
RockerfileContent string
ContextDir string
Id string
OutStream io.Writer
InStream io.ReadCloser
Docker *docker.Client
Expand Down Expand Up @@ -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)))
}

Expand Down