Skip to content

Commit e5b578a

Browse files
author
Trevor O
committed
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).
1 parent dee9499 commit e5b578a

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ RUN apk add --update --no-cache build-base curl git upx && \
88

99
RUN apk add --update nodejs npm
1010

11-
RUN curl -sSL \
12-
https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl \
13-
-o /usr/local/bin/kubectl
14-
1511
RUN curl -sSL \
1612
https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator \
1713
-o /usr/local/bin/aws-iam-authenticator
@@ -24,10 +20,15 @@ unzip -d /usr/local/bin/ /tmp/terraform.zip
2420
RUN chmod +x /usr/local/bin/* && \
2521
upx --lzma /usr/local/bin/*
2622

23+
# Hydrate the dependency cache. This way, if the go.mod or go.sum files do not
24+
# change we can cache the depdency layer without having to reinstall them.
2725
WORKDIR /tmp/commit0
26+
COPY go.mod go.sum ./
27+
RUN go mod download
28+
2829
COPY . .
2930

30-
RUN make build-deps && make build && \
31+
RUN make build && \
3132
mv commit0 /usr/local/bin && \
3233
upx --lzma /usr/local/bin/commit0
3334

@@ -37,11 +38,10 @@ ENV \
3738
GOPATH=/proto-libs
3839

3940
RUN apk add --update bash ca-certificates git python && \
40-
apk add --update -t deps make py-pip
41+
apk add --update -t deps make py-pip
4142

4243
RUN mkdir ${GOPATH}
4344
COPY --from=builder /usr/local/bin /usr/local/bin
44-
COPY --from=builder /usr/local/include /usr/local/include
4545
COPY --from=builder /go/src/github.com/grpc-ecosystem/grpc-gateway ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway
4646
WORKDIR /project
4747

0 commit comments

Comments
 (0)