1 # Build the manager binary
\r
2 FROM golang:1.20 as builder
\r
7 # Copy the Go Modules manifests
\r
10 # cache deps before building and copying source so that we don't need to re-download as much
\r
11 # and so that source changes don't invalidate our downloaded layer
\r
14 # Copy the go source
\r
15 COPY cmd/main.go cmd/main.go
\r
17 COPY internal/controller/ internal/controller/
\r
20 # the GOARCH has not a default value to allow the binary be built according to the host where the command
\r
21 # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
\r
22 # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
\r
23 # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
\r
24 RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
\r
26 # Use distroless as minimal base image to package the manager binary
\r
27 # Refer to https://github.com/GoogleContainerTools/distroless for more details
\r
28 FROM gcr.io/distroless/static:nonroot
\r
30 COPY --from=builder /workspace/manager .
\r
33 ENTRYPOINT ["/manager"]
\r