From e5b578ae5d86da31a63d91d2fc3f169b7af4aa6d Mon Sep 17 00:00:00 2001 From: Trevor O Date: Wed, 18 Mar 2020 17:50:46 -0700 Subject: [PATCH] Fix make build-docker-local This commit addresses a couple problems with the Dockerfile which was resulting in a failed build. The likely culprit of this not being caught earlier was some cached images. This does two things 1. It removes unnecessary references to things that aren't being used any more. The ENV setting was removed in a previous commit, but not the reference of it later in the Dockerfile. If this is in error please let me know! 2. The go modules are cached in a layer as these are much less likely to change between build runs than the source code itself. The technique is simple enough; just copy the files in a separate COPY and run `go mod download`. This reduces the hydrated build time (previous layers cached) from 2m35s on average (3 runs) to 34s on average (3 runs). --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30a7847c2..361d5cb5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,6 @@ RUN apk add --update --no-cache build-base curl git upx && \ RUN apk add --update nodejs npm -RUN curl -sSL \ - https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl \ - -o /usr/local/bin/kubectl - RUN curl -sSL \ https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator \ -o /usr/local/bin/aws-iam-authenticator @@ -24,10 +20,15 @@ unzip -d /usr/local/bin/ /tmp/terraform.zip RUN chmod +x /usr/local/bin/* && \ upx --lzma /usr/local/bin/* +# Hydrate the dependency cache. This way, if the go.mod or go.sum files do not +# change we can cache the depdency layer without having to reinstall them. WORKDIR /tmp/commit0 +COPY go.mod go.sum ./ +RUN go mod download + COPY . . -RUN make build-deps && make build && \ +RUN make build && \ mv commit0 /usr/local/bin && \ upx --lzma /usr/local/bin/commit0 @@ -37,11 +38,10 @@ ENV \ GOPATH=/proto-libs RUN apk add --update bash ca-certificates git python && \ -apk add --update -t deps make py-pip + apk add --update -t deps make py-pip RUN mkdir ${GOPATH} COPY --from=builder /usr/local/bin /usr/local/bin -COPY --from=builder /usr/local/include /usr/local/include COPY --from=builder /go/src/github.com/grpc-ecosystem/grpc-gateway ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway WORKDIR /project