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

Commit

Permalink
Merge pull request #7 from grammarly/issue-6
Browse files Browse the repository at this point in the history
#6 provide `-id` parameter
  • Loading branch information
Yuriy Bogdanov committed Sep 14, 2015
2 parents 3bcd54e + 12a136b commit 5931ecf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 5931ecf

Please sign in to comment.