Dockerfile 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. # Build the manager binary
  2. FROM golang:1.20 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
  13. COPY cmd/main.go cmd/main.go
  14. COPY api/ api/
  15. COPY internal/controller/ internal/controller/
  16. # Build
  17. # the GOARCH has not a default value to allow the binary be built according to the host where the command
  18. # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
  19. # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
  20. # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
  21. RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
  22. # Use distroless as minimal base image to package the manager binary
  23. # Refer to https://github.com/GoogleContainerTools/distroless for more details
  24. FROM gcr.io/distroless/static:nonroot
  25. WORKDIR /
  26. COPY --from=builder /workspace/manager .
  27. USER 65532:65532
  28. ENTRYPOINT ["/manager"]