docker: improving caching of go modules

0 views
Skip to first unread message

nor...@perkeep.org

unread,
Jun 17, 2022, 10:37:38 AM6/17/22
to camlistor...@googlegroups.com


https://github.com/perkeep/perkeep/commit/1302c5aaf11b22576144bd8f309d7699548119ba

commit 1302c5aaf11b22576144bd8f309d7699548119ba
Author: Will Norris <wi...@willnorris.com>
Date: Tue May 3 11:35:15 2022 -0700

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).

diff --git a/Dockerfile b/Dockerfile
index b585ba8..65ca4d5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,6 +13,11 @@ MAINTAINER Perkeep Authors <per...@googlegroups.com>

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

Reply all
Reply to author
Forward
0 new messages