From 8ece3301934983d9ff4afafea51ba0a0a951abe2 Mon Sep 17 00:00:00 2001 From: Joseph Herlant Date: Mon, 29 Oct 2018 18:44:43 -0700 Subject: [PATCH] Using goreleaser to build the docker image too --- .goreleaser.yml | 9 ++++----- Dockerfile | 19 ++++++++++--------- Makefile | 25 +++++-------------------- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index b211742..99a6a4b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,3 @@ -project_name: awsRetagger before: hooks: - make go-dep @@ -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 diff --git a/Dockerfile b/Dockerfile index 94d4989..0b50b46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index 7fcd021..9c56218 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 \ @@ -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