Skip to content

Commit

Permalink
KEP-2170: Bind repository into the build environment instead of filec…
Browse files Browse the repository at this point in the history
…opy (#2222)

Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
  • Loading branch information
tenzen-y authored Aug 15, 2024
1 parent 6f36eb7 commit 3f9b0a4
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions cmd/training-operator.v2alpha1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM golang:1.22 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY . .

# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager cmd/training-operator.v2alpha1/main.go
RUN --mount=type=cache,target=/go/pkg/mod/,sharing=locked \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /bin/manager cmd/training-operator.v2alpha1/main.go

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

0 comments on commit 3f9b0a4

Please sign in to comment.