Skip to content

Commit

Permalink
label docker image with git repo url
Browse files Browse the repository at this point in the history
fixes #77
  • Loading branch information
munkyboy committed May 17, 2018
1 parent bdccdca commit 5aedee7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions blackbox-test/features/package.feature
Expand Up @@ -222,14 +222,16 @@ Feature: package task
"""yaml
docker_image_name: elsyblackbox_docker_label_test
"""
When I run `lc package --git-commit=c8dfd9f`
When I run `lc package --git-commit=c8dfd9f --git-url=foobaz`
Then it should succeed
And the output should contain all of these:
| Image is up to date for alpine:latest |
| Attaching image label: com.elsy.metadata.git-commit=c8dfd9f |
| Attaching image label: com.elsy.metadata.git-url=foobaz |
And the image 'elsyblackbox_docker_label_test' should exist
And it should have the following labels:
| com.elsy.metadata.git-commit:c8dfd9f |
| com.elsy.metadata.git-commit:c8dfd9f |
| com.elsy.metadata.git-url:foobaz |

Scenario: custom package script generating the Dockerfile
Given a file named "docker-compose.yml" with:
Expand Down
9 changes: 9 additions & 0 deletions command/package.go
Expand Up @@ -28,6 +28,9 @@ import (
// commitLabel identifies the git commit the image was built from
const commitLabel = "com.elsy.metadata.git-commit"

// repoLabel identifies the git repo the image was built from
const repoLabel = "com.elsy.metadata.git-url"

// CmdPackage runs package service if present and then attempts to build Dockerfile.
// Unless --skip-tests is passed, it *will* run the tests, and any failures will abort
// the packaging process.
Expand Down Expand Up @@ -114,5 +117,11 @@ func constructLabelArgs(c *cli.Context) (labelArgs []string) {
labelArgs = append(labelArgs, "--label", fmt.Sprintf("%s=%s", commitLabel, commit))
}

gitUrl := c.String("git-url")
if gitUrl != "" {
logrus.Infof("Attaching image label: %s=%s", repoLabel, gitUrl)
labelArgs = append(labelArgs, "--label", fmt.Sprintf("%s=%s", repoLabel, gitUrl))
}

return
}
10 changes: 10 additions & 0 deletions main/commands.go
Expand Up @@ -159,6 +159,11 @@ func Commands() []cli.Command {
Usage: "Git commit that is being built",
EnvVar: "GIT_COMMIT",
},
cli.StringFlag{
Name: "git-url",
Usage: "Git repo that is being built",
EnvVar: "GIT_URL",
},
cli.StringFlag{
Name: "build-logs-dir",
Value: GetConfigFileString("build_logs_dir"),
Expand Down Expand Up @@ -243,6 +248,11 @@ func Commands() []cli.Command {
Usage: "Git commit that is being built",
EnvVar: "GIT_COMMIT",
},
cli.StringFlag{
Name: "git-url",
Usage: "Git repo that is being built",
EnvVar: "GIT_URL",
},
},
},
{
Expand Down

0 comments on commit 5aedee7

Please sign in to comment.