Containerfile 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. # Build the manager binary
  2. FROM golang:1.25 AS builder
  3. ARG TARGETOS
  4. ARG TARGETARCH
  5. WORKDIR /workspace
  6. # Copy the Go Modules manifests
  7. COPY go.mod go.mod
  8. COPY go.sum go.sum
  9. # cache deps before building and copying source so that we don't need to re-download as much
  10. # and so that source changes don't invalidate our downloaded layer
  11. RUN go mod download
  12. # Copy the Go source (relies on .dockerignore to filter)
  13. COPY . .
  14. # Build
  15. # the GOARCH has no default value to allow the binary to be built according to the host where the command
  16. # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
  17. # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
  18. # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
  19. RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
  20. # Use distroless as minimal base image to package the manager binary
  21. # Refer to https://github.com/GoogleContainerTools/distroless for more details
  22. FROM gcr.io/distroless/static:nonroot
  23. WORKDIR /
  24. COPY --from=builder /workspace/manager .
  25. USER 65532:65532
  26. ENTRYPOINT ["/manager"]