allow 'make dev-docker' to cache resolved modules (#5588)

This commit is contained in:
R.B. Boyer 2019-04-01 11:41:33 -05:00 committed by GitHub
parent 5cd32d0a9e
commit 3364638e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 3 deletions

View File

@ -7,10 +7,26 @@ ARG GIT_DESCRIBE
# WORKDIR /go/src/github.com/hashicorp/consul
ENV CONSUL_DEV=1
ENV COLORIZE=0
Add . /go/src/github.com/hashicorp/consul/
RUN make dev
# Cache modules separately from more frequently edited source files.
#
# The trick is taken from [https://medium.com/@pliutau/docker-and-go-modules-4265894f9fc#6622]
#
# We copy the modules files in first since they are less likely to change frequently
# and the population of the go mod cache will be invalidated less frequently.
COPY go.mod .
COPY go.sum .
RUN mkdir -p api sdk
COPY api/go.mod api
COPY api/go.sum api
COPY sdk/go.mod sdk
COPY sdk/go.sum sdk
RUN go mod download
# Add the rest of the code.
ADD . /consul/
RUN make dev
FROM consul:latest
COPY --from=builder /go/src/github.com/hashicorp/consul/bin/consul /bin
COPY --from=builder /go/bin/consul /bin