Skip to content

Commit deb65f3

Browse files
authored
Merge pull request #770 from mengqiy/cachegomod
✨ cache go module cache in docker
2 parents 9fa919d + fe027da commit deb65f3

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pkg/scaffold/v2/dockerfile.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ var dockerfileTemplate = `# Build the manager binary
4040
FROM golang:1.12.5 as builder
4141
4242
WORKDIR /workspace
43-
# Copy the go source
44-
COPY main.go main.go
45-
COPY api/ api/
46-
COPY controllers/ controllers/
4743
# Copy the Go Modules manifests
4844
COPY go.mod go.mod
4945
COPY go.sum go.sum
46+
# cache deps before building and copying source so that we don't need to re-download as much
47+
# and so that source changes don't invalidate our downloaded layer
48+
RUN go mod download
5049
50+
# Copy the go source
51+
COPY main.go main.go
52+
COPY api/ api/
53+
COPY controllers/ controllers/
5154
5255
# Build
5356
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go

testdata/project-v2/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
FROM golang:1.12.5 as builder
33

44
WORKDIR /workspace
5-
# Copy the go source
6-
COPY main.go main.go
7-
COPY api/ api/
8-
COPY controllers/ controllers/
95
# Copy the Go Modules manifests
106
COPY go.mod go.mod
117
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
1211

12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
1316

1417
# Build
1518
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go

0 commit comments

Comments
 (0)