Skip to content

Commit 3f9b0a4

Browse files
authored
KEP-2170: Bind repository into the build environment instead of filecopy (kubeflow#2222)
Signed-off-by: Yuki Iwai <[email protected]>
1 parent 6f36eb7 commit 3f9b0a4

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
# Build the manager binary
2-
FROM golang:1.22 as builder
2+
FROM golang:1.22 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
11-
12-
# Copy the go source
13-
COPY . .
145

156
# Build
16-
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager cmd/training-operator.v2alpha1/main.go
7+
RUN --mount=type=cache,target=/go/pkg/mod/,sharing=locked \
8+
--mount=type=bind,source=go.sum,target=go.sum \
9+
--mount=type=bind,source=go.mod,target=go.mod \
10+
go mod download
11+
RUN --mount=type=cache,target=/go/pkg/mod/ \
12+
--mount=type=bind,target=. \
13+
CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /bin/manager cmd/training-operator.v2alpha1/main.go
1714

1815
# Use distroless as minimal base image to package the manager binary
1916
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2017
FROM gcr.io/distroless/static:nonroot
2118
WORKDIR /
22-
COPY --from=builder /workspace/manager .
19+
COPY --from=builder /bin/manager .
2320
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)