Skip to content

Commit 9b2de7a

Browse files
committed
use cache
Signed-off-by: walnuts1018 <r.juglans.1018@gmail.com>
1 parent 006d353 commit 9b2de7a

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

Dockerfile

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
# Build the manager binary
2-
FROM golang:1.21 AS builder
2+
FROM golang AS builder
33

44
WORKDIR /workspace
5-
# Copy the Go Modules manifests
6-
COPY go.mod go.mod
7-
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
115

12-
# Copy the go source
13-
COPY cmd/main.go cmd/main.go
14-
COPY api/ api/
15-
COPY internal/controller/ internal/controller/
16-
COPY internal/initplugins internal/initplugins
17-
COPY util/ util/
6+
RUN --mount=type=cache,target=/go/pkg/mod/,sharing=locked \
7+
--mount=type=bind,source=go.sum,target=go.sum \
8+
--mount=type=bind,source=go.mod,target=go.mod \
9+
go mod download -x
1810

19-
# Build
20-
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21-
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22-
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23-
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24-
RUN CGO_ENABLED=0 go build -a -o manager cmd/main.go
11+
RUN --mount=type=cache,target=/go/pkg/mod/ \
12+
--mount=type=bind,target=. \
13+
CGO_ENABLED=0 go build -a -o manager cmd/main.go
2514

2615
# Use distroless as minimal base image to package the manager binary
2716
# Refer to https://github.com/GoogleContainerTools/distroless for more details

0 commit comments

Comments
 (0)