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

Use git branch names as tags for docker images #70

Merged
merged 4 commits into from
Feb 3, 2016
Merged
Changes from 2 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
24 changes: 11 additions & 13 deletions Rockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM golang:1.5.1

{{ assert .Version }}
{{ $stable := "0.2.3" }}
{{ $beta := "0.2.4" }}
{{ $v1 := "1." }}
{{ $commit := (or .Env.GIT_COMMIT "") }}
{{ $branch := (or .Env.GIT_BRANCH "") }}
{{ $version:= (or .Version "local") }}

ADD . /go/src/github.com/grammarly/rocker
WORKDIR /go/src/github.com/grammarly/rocker
Expand All @@ -22,10 +21,9 @@ RUN make test
ATTACH ["bash"]

RUN \
TIME=$(TZ=GMT date "+%Y-%m-%d_%H:%M_GMT") \
go build \
-a -installsuffix cgo \
-ldflags "-X main.Version={{ .Version }} -X main.GitCommit=$commit -X main.GitBranch=$branch -X main.BuildTime=$TIME" \
-ldflags "-X main.Version={{$version}} -X main.GitCommit={{$commit}} -X main.GitBranch={{$branch}} -X main.BuildTime=$(TZ=GMT date '+%Y-%m-%d_%H:%M_GMT')" \
-v -o /bin/rocker

EXPORT /bin/rocker
Expand All @@ -47,12 +45,12 @@ ENV PATH=/opt/rocker/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin

CMD ["/opt/rocker/bin/rocker"]

PUSH dockerhub.grammarly.io/rocker:{{ .Version }}
{{ if $version }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do a branch PUSH always, without any conditions. Branch can be none or no-branch by default.
PUSH with version can be with condition and be pushed to rocker:$version but not rocker:$branch-$version. Because if you know a particular version, you don't care about a branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this condition does not make sense because you always assign a value to the $version variable.

{{ if $branch }}

{{ if hasPrefix .Version $stable }}
PUSH dockerhub.grammarly.io/rocker:stable
{{ else if hasPrefix .Version $beta }}
PUSH dockerhub.grammarly.io/rocker:beta
{{ else if hasPrefix .Version $v1 }}
PUSH dockerhub.grammarly.io/rocker:v1
PUSH dockerhub.grammarly.io/rocker:{{ $branch }}-{{ $version }}
PUSH dockerhub.grammarly.io/rocker:{{ $branch }}

{{ end }}
{{ end }}