File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change 11# Build the manager binary
2- FROM golang:{ { .goVersion } } as builder
2+ FROM --platform=$BUILDPLATFORM golang:{ { .goVersion } } as builder
33ARG TARGETOS
44ARG TARGETARCH
55
66WORKDIR /workspace
77# Copy the Go Modules manifests
88COPY go.mod go.mod
99COPY go.sum go.sum
10- # cache deps before building and copying source so that we don't need to re-download as much
10+ # Cache deps before building and copying source so that we don't need to re-download as much
1111# and so that source changes don't invalidate our downloaded layer
1212RUN go mod download
1313
14- # Copy the go source
14+ # Copy the go sources
1515COPY main.go main.go
1616COPY api/ api/
1717COPY pkg/ pkg/
18- COPY hack/ hack /
18+ COPY crds/ crds /
1919COPY Makefile Makefile
2020
21- # Build
22- # the GOARCH has not a default value to allow the binary be built according to the host where the command
23- # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
24- # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
25- # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
26- RUN CGO_ENABLED=0 GOOS=${ TARGETOS:-linux} GOARCH=${ TARGETARCH} make test build
21+ # Run tests and build
22+ RUN make envtest \
23+ && CGO_ENABLED=0 KUBEBUILDER_ASSETS="/workspace/bin/k8s/current" go test ./... \
24+ && CGO_ENABLED=0 GOOS=${ TARGETOS:-linux} GOARCH=${ TARGETARCH} go build -a -o manager main.go
2725
2826# Use distroless as minimal base image to package the manager binary
2927# Refer to https://github.com/GoogleContainerTools/distroless for more details
3028FROM gcr.io/distroless/static:nonroot
3129WORKDIR /
32- COPY --from=builder /workspace/bin/ manager .
30+ COPY --from=builder /workspace/manager .
3331USER 65532:65532
3432
3533ENTRYPOINT ["/manager"]
You can’t perform that action at this time.
0 commit comments