From 1302c5aaf11b22576144bd8f309d7699548119ba Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 3 May 2022 11:35:15 -0700 Subject: [PATCH] docker: improving caching of go modules download go modules as its own image layer, rather than as part of compiling perkeep. This reduces image build time by approximately 40% in cases where modules are unchanged (109 to 67 seconds in my testing). --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b585ba83a..65ca4d536 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,11 @@ MAINTAINER Perkeep Authors ENV DEBIAN_FRONTEND noninteractive +WORKDIR /go/src/perkeep.org + +COPY go.mod go.sum ./ +RUN go mod download + # Add each directory separately, so our context doesn't include the # Dockerfile itself, to permit quicker iteration with docker's # caching. @@ -29,10 +34,6 @@ ADD server /go/src/perkeep.org/server ADD website /go/src/perkeep.org/website ADD make.go /go/src/perkeep.org/make.go ADD VERSION /go/src/perkeep.org/VERSION -ADD go.mod /go/src/perkeep.org/go.mod -ADD go.sum /go/src/perkeep.org/go.sum - -WORKDIR /go/src/perkeep.org RUN go run make.go -v