From a35cd7f4a4f4faf340633bdc8376a5b11c6b9e07 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Tue, 26 Jun 2018 13:21:36 -0700 Subject: [PATCH] Convert go-env Dockerfile into a multi-stage build (#683) Converting to a multi-stage build reduces the size of the final image from ~750MB to ~15MB. --- environments/go/Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/environments/go/Dockerfile b/environments/go/Dockerfile index 9c1daf04..7a33fa28 100644 --- a/environments/go/Dockerfile +++ b/environments/go/Dockerfile @@ -1,6 +1,6 @@ ARG GO_VERSION=1.9.2 -FROM golang:${GO_VERSION} +FROM golang:${GO_VERSION} AS builder ENV GOPATH /usr ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go @@ -10,7 +10,12 @@ ADD server.go ${APP} WORKDIR ${APP} RUN go get -RUN go build -o /server server.go +RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o /server server.go + +FROM alpine:3.7 +WORKDIR / +COPY --from=builder /server / +RUN apk -U add ca-certificates ENTRYPOINT ["/server"] EXPOSE 8888