diff --git a/Dockerfile b/Dockerfile index 64eb89882..c0976a665 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,23 @@ -# Build the manager binary -FROM golang:1.20 as builder +FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.2.1@sha256:8879a398dedf0aadaacfbd332b29ff2f84bc39ae6d4e9c0a1109db27ac5ba012 AS xx + +FROM --platform=$BUILDPLATFORM golang:1.20.3-alpine3.16@sha256:29c4e6e307eac79e5db29a261b243f27ffe0563fa1767e8d9a6407657c9a5f08 AS builder + +COPY --from=xx / / + +RUN apk add --update --no-cache ca-certificates make git curl clang lld + +ARG TARGETPLATFORM + +RUN xx-apk --update --no-cache add musl-dev gcc + +RUN xx-go --wrap + +WORKDIR /usr/local/src/logging-operator + +ARG GOPROXY + +ENV CGO_ENABLED=0 -WORKDIR /workspace # Copy the Go Modules manifests COPY go.mod go.mod COPY go.sum go.sum @@ -20,11 +36,12 @@ COPY controllers/ controllers/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o manager main.go - -# Use distroless as minimal base image to package the manager binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:latest -WORKDIR / -COPY --from=builder /workspace/manager . -ENTRYPOINT ["/manager"] +RUN go build -o /usr/local/bin/manager +RUN xx-verify /usr/local/bin/manager + + +FROM gcr.io/distroless/static:latest@sha256:a01d47d4036cae5a67a9619e3d06fa14a6811a2247b4da72b4233ece4efebd57 + +COPY --from=builder /usr/local/bin/manager /usr/local/bin + +ENTRYPOINT ["manager"]