From c88b974352a1c970de23c5a689db9919770b79dd Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 6 Oct 2019 20:00:21 +0200 Subject: [PATCH] feat: multi-arch Docker image. --- .travis.yml | 17 +++++++++++++++++ Dockerfile | 2 +- Makefile | 7 ++++++- tmpl.Dockerfile | 24 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tmpl.Dockerfile diff --git a/.travis.yml b/.travis.yml index a04236e..180be32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,9 @@ before_install: # Install linters and misspell - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin ${GOLANGCI_LINT_VERSION} - golangci-lint --version + # Install Docker image multi-arch builder + - curl -sfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | bash -s -- -b "${GOPATH}/bin" ${SEIHON_VERSION} + - seihon --version install: - go mod tidy @@ -33,3 +36,17 @@ install: script: - make - make image + +before_deploy: + - > + if ! [ "$BEFORE_DEPLOY_RUN" ]; then + export BEFORE_DEPLOY_RUN=1; + echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin + fi + +deploy: + - provider: script + skip_cleanup: true + script: make publish-images + on: + tags: true diff --git a/Dockerfile b/Dockerfile index fe2b060..30c88ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13-alpine as builder +FROM golang:1-alpine as builder RUN apk --no-cache --no-progress add git ca-certificates tzdata make \ && update-ca-certificates \ diff --git a/Makefile b/Makefile index 34b6081..d2381a1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -.PHONY: default build image check +.PHONY: default build image check publish-images + +TAG_NAME := $(shell git tag -l --contains HEAD) default: check test build @@ -13,3 +15,6 @@ image: check: golangci-lint run + +publish-images: + seihon publish -v "$(TAG_NAME)" -v "latest" --image-name containous/whoami --dry-run=false diff --git a/tmpl.Dockerfile b/tmpl.Dockerfile new file mode 100644 index 0000000..81803d9 --- /dev/null +++ b/tmpl.Dockerfile @@ -0,0 +1,24 @@ +FROM golang:1-alpine as builder + +RUN apk --no-cache --no-progress add git ca-certificates tzdata make \ + && update-ca-certificates \ + && rm -rf /var/cache/apk/* + +WORKDIR /go/whoami + +# Download go modules +COPY go.mod . +COPY go.sum . +RUN GO111MODULE=on GOPROXY=https://proxy.golang.org go mod download + +COPY . . +RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build + +FROM scratch + +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /go/whoami/whoami . + +ENTRYPOINT ["/whoami"] +EXPOSE 80