Dockerfile 1.5 KB

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