frontend: optimize dockerfile

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-06-28 18:46:58 -07:00 committed by Simon Zeltser
parent f2ee88a9a2
commit 92274f4ff4

View file

@ -1,23 +1,29 @@
FROM golang:1.10-alpine as builder FROM golang:1.10-alpine as builder
RUN apk add --no-cache ca-certificates git RUN apk add --no-cache ca-certificates git
WORKDIR /go/src/frontend WORKDIR /go/src/frontend
COPY . .
# download known dependencies # fetch known dependencies for caching
RUN go get -d github.com/google/uuid \ RUN go get -d github.com/google/uuid \
github.com/gorilla/mux \ github.com/gorilla/mux \
google.golang.org/grpc \ google.golang.org/grpc \
google.golang.org/grpc/codes \ google.golang.org/grpc/codes \
google.golang.org/grpc/status google.golang.org/grpc/status
# other dependencies might not have listed above # copy go-only part of the build
COPY *.go ./
COPY ./genproto ./genproto
COPY ./money ./money
# fetch other dependencies might not have listed above (ideally noop)
RUN go get -d ./... RUN go get -d ./...
RUN go build -o /frontend . RUN go install .
# ---
FROM alpine as release FROM alpine as release
RUN apk add --no-cache ca-certificates RUN apk add --no-cache ca-certificates
WORKDIR /frontend WORKDIR /frontend
COPY --from=builder /frontend /frontend/server COPY --from=builder /go/bin/frontend /frontend/server
COPY ./templates ./templates COPY ./templates ./templates
COPY ./static ./static COPY ./static ./static
EXPOSE 8080 EXPOSE 8080