Skip to content

Commit

Permalink
Build binary within Docker image
Browse files Browse the repository at this point in the history
This is good for reproducible builds
  • Loading branch information
ash2k committed Jun 23, 2016
1 parent fb08bb3 commit 311dc01
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ BINARY_NAME := gostatsd
IMAGE_NAME := atlassianlabs/$(BINARY_NAME)
ARCH ?= darwin
METALINTER_CONCURRENCY ?= 4
GOVERSION = 1.6.2
GOVERSION := 1.6.2
GP := /gopath

setup: setup-ci
go get -v -u github.com/githubnemo/CompileDaemon
Expand Down Expand Up @@ -85,19 +86,24 @@ git-hook:
cp dev/push-hook.sh .git/hooks/pre-push

# Compile a static binary. Cannot be used with -race
cross:
CGO_ENABLED=0 GOOS=linux go build -o build/bin/linux/$(BINARY_NAME) $(GOBUILD_VERSION_ARGS) -a -installsuffix cgo github.com/atlassian/gostatsd

docker: cross
docker:
docker run \
--rm \
-v "$(GOPATH)":"$(GP)" \
-w "$(GP)/src/github.com/atlassian/gostatsd" \
-e GOPATH="$(GP)" \
-e CGO_ENABLED=0 \
golang:$(GOVERSION) \
go build -o build/bin/linux/$(BINARY_NAME) $(GOBUILD_VERSION_ARGS) -a -installsuffix cgo github.com/atlassian/gostatsd
docker build --pull -t $(IMAGE_NAME):$(GIT_HASH) build

# Compile a binary with -race.
# Compile a binary with -race. Needs to be run on a glibc-based system.
docker-race:
docker run \
--rm \
-v "$(GOPATH)":/opt/gopath \
-w /opt/gopath/src/github.com/atlassian/gostatsd \
-e GOPATH=/opt/gopath \
-v "$(GOPATH)":"$(GP)" \
-w "$(GP)/src/github.com/atlassian/gostatsd" \
-e GOPATH="$(GP)" \
golang:$(GOVERSION) \
go build -race -o build/bin/linux/$(BINARY_NAME) $(GOBUILD_VERSION_ARGS) -a -installsuffix cgo github.com/atlassian/gostatsd
docker build --pull -t $(IMAGE_NAME):$(GIT_HASH)-race -f build/Dockerfile-glibc build
Expand All @@ -111,6 +117,9 @@ release-normal: release-hash
docker tag $(IMAGE_NAME):$(GIT_HASH) $(IMAGE_NAME):$(REPO_VERSION)
docker push $(IMAGE_NAME):$(REPO_VERSION)

release-hash-race: check test docker-race
docker push $(IMAGE_NAME):$(GIT_HASH)-race

release-race: docker-race
docker tag $(IMAGE_NAME):$(GIT_HASH)-race $(IMAGE_NAME):$(REPO_VERSION)-race
docker push $(IMAGE_NAME):$(REPO_VERSION)-race
Expand Down

0 comments on commit 311dc01

Please sign in to comment.