feat: multi-arch Docker image.

This commit is contained in:
Fernandez Ludovic
2019-10-06 20:00:21 +02:00
parent affedf56a2
commit c88b974352
4 changed files with 48 additions and 2 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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

24
tmpl.Dockerfile Normal file
View File

@ -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