Skip to content

Commit

Permalink
Using goreleaser to build the docker image too
Browse files Browse the repository at this point in the history
  • Loading branch information
aerostitch committed Oct 30, 2018
1 parent 3f9aa08 commit 8ece330
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
9 changes: 4 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
project_name: awsRetagger
before:
hooks:
- make go-dep
Expand Down Expand Up @@ -36,10 +35,10 @@ dockers:
# GOARCH of the built binary that should be used.
goarch: amd64
image_templates:
- "vevo/{{.ProjectName}}:latest"
- "vevo/{{.ProjectName}}:{{ .Tag }}"
- "vevo/awsretagger:latest"
- "vevo/awsretagger:{{ .Tag }}"
skip_push: false
# Path to the Dockerfile (from the project root).
dockerfile: Dockerfile
extra_files:
- /etc/ssl/certs/ca-certificates.crt
# extra_files:
# - /etc/ssl/certs/ca-certificates.crt
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
FROM golang:alpine as base
# the base image is only used for compilation
ARG BUILD_VERSION=0.0.1-test
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
WORKDIR /go/src/github.com/VEVO/awsRetagger
RUN apk add --no-cache git build-base
COPY . .
RUN make go-build
# ARG BUILD_VERSION=0.0.1-test
# ENV CGO_ENABLED=0
# ENV GOOS=linux
# ENV GOARCH=amd64
# WORKDIR /go/src/github.com/VEVO/awsRetagger
# RUN apk add --no-cache git build-base
# COPY . .
# RUN make go-build

# Getting a small image with only the binary
FROM scratch
COPY --from=base /go/src/github.com/VEVO/awsRetagger/awsRetagger /awsRetagger
# COPY --from=base /go/src/github.com/VEVO/awsRetagger/awsRetagger /awsRetagger
COPY awsRetagger /
# This is needed when you do HTTPS requests
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/awsRetagger"]
25 changes: 5 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GO_REVISION?=$(shell git rev-parse HEAD)
GO_TO_REVISION?=$(GO_REVISION)
GO_FROM_REVISION?=$(shell git rev-parse refs/remotes/origin/master)
GIT_TAG=$(IMAGE_NAME):$(GO_REVISION)
BUILD_VERSION?=1.0.$(shell date +%Y%m%d)
BUILD_VERSION?=$(shell date +%Y%m%d%H%M%S)-dev
BUILD_TAG=$(IMAGE_NAME):$(BUILD_VERSION)
LATEST_TAG=$(IMAGE_NAME):latest

Expand All @@ -18,18 +18,6 @@ docker-lint:
docker-login:
@docker login -u "$(DOCKER_USER)" -p "$(DOCKER_PASS)"

docker-build:
docker build --build-arg BUILD_VERSION=$(BUILD_VERSION) -t $(GIT_TAG) .

docker-tag:
docker tag $(GIT_TAG) $(BUILD_TAG)
docker tag $(GIT_TAG) $(LATEST_TAG)

docker-push: docker-login
docker push $(GIT_TAG)
docker push $(BUILD_TAG)
docker push $(LATEST_TAG)

go-dep:
@if [ -f "glide.yaml" ] ; then \
go get github.com/Masterminds/glide \
Expand Down Expand Up @@ -67,14 +55,11 @@ go-test:
go-build: go-dep go-lint go-test
@go build -v -a -ldflags "-X main.version=$(BUILD_VERSION)"

go-compile:
@docker run --rm -v "$${PWD}":/go/src/github.com/VEVO/$(APP_NAME) -w /go/src/github.com/VEVO/$(APP_NAME) -e GOARCH=amd64 -e GOOS=linux -e CGO_ENABLED=0 -e BUILD_VERSION=$(BUILD_VERSION) golang:alpine make go-build

build: docker-lint docker-build
build: go-build

release: build docker-tag docker-push
git tag -s $(BUILD_VERSION)
release:
git tag -s $(BUILD_VERSION) -m "Release $(BUILD_VERSION)"
# We skip publish for now for sanity purposes
goreleaser release --skip-publish
goreleaser release --rm-dist --skip-publish

# vim: ft=make

0 comments on commit 8ece330

Please sign in to comment.