From 510476dca9bf871d160722d5a8354e8c2ae61091 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 17 Sep 2019 00:38:14 +0200 Subject: [PATCH] chore: improve Dockerfile. --- Dockerfile | 18 +++++++++++++++++- Makefile | 5 +---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3ef744c..fe2b060 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,26 @@ -FROM golang:1.12 as builder +FROM golang:1.13-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 make build # Create a minimal container to run a Golang static binary 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 diff --git a/Makefile b/Makefile index ae4ff8b..2b93505 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,9 @@ -.PHONY: default build dependencies image +.PHONY: default build image default: build build: CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami -dependencies: - go mod download - image: docker build -t containous/whoami .