|
1 | 1 | # Build the manager binary |
2 | | -FROM golang:1.21 AS builder |
| 2 | +FROM golang AS builder |
3 | 3 |
|
4 | 4 | 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 |
11 | 5 |
|
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 |
18 | 10 |
|
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 |
25 | 14 |
|
26 | 15 | # Use distroless as minimal base image to package the manager binary |
27 | 16 | # Refer to https://github.com/GoogleContainerTools/distroless for more details |
|
0 commit comments