@@ -6,12 +6,13 @@ ARG BASE_IMAGE=gcr.io/distroless/static:nonroot@sha256:9ecc53c269509f63c69a26616
66FROM $BUILD_IMAGE AS builder
77
88WORKDIR /workspace
9+ ARG LDFLAGS=-s -w -extldflags=-static
910# Copy the Go Modules manifests
1011COPY go.mod go.sum ./
1112COPY api/go.mod api/go.sum api/
1213# cache deps before building and copying source so that we don't need to re-download as much
1314# and so that source changes don't invalidate our downloaded layer
14- RUN go mod download -x
15+ RUN --mount=type=cache,target=/go/pkg/mod/ go mod download -x
1516
1617# Copy the go source
1718COPY cmd/main.go cmd/main.go
@@ -20,19 +21,20 @@ COPY internal/ internal/
2021COPY pkg/ pkg/
2122
2223# Build
23- RUN CGO_ENABLED=0 go build -a -o manager cmd/main.go
24+ RUN CGO_ENABLED=0 go build -a -ldflags "${LDFLAGS}" \
25+ -o manager cmd/main.go
2426
2527# Use distroless as minimal base image to package the manager binary
2628FROM $BASE_IMAGE
2729
2830# image.version is set during image build by automation
29- LABEL org.opencontainers.image.authors=
"[email protected] " 30- LABEL org.opencontainers.image.description="Operator managing an Ironic deployment for Metal3"
31- LABEL org.opencontainers.image.documentation="https://book.metal3.io/irso/introduction"
32- LABEL org.opencontainers.image.licenses="Apache License 2.0"
33- LABEL org.opencontainers.image.title="Ironic Standalone Operator"
34- LABEL org.opencontainers.image.url="https://github.com/metal3-io/ironic-standalone-operator"
35- LABEL org.opencontainers.image.vendor="Metal3-io"
31+ LABEL org.opencontainers.image.authors=
"[email protected] " \ 32+ org.opencontainers.image.description="Operator managing an Ironic deployment for Metal3" \
33+ org.opencontainers.image.documentation="https://book.metal3.io/irso/introduction" \
34+ org.opencontainers.image.licenses="Apache License 2.0" \
35+ org.opencontainers.image.title="Ironic Standalone Operator" \
36+ org.opencontainers.image.url="https://github.com/metal3-io/ironic-standalone-operator" \
37+ org.opencontainers.image.vendor="Metal3-io"
3638
3739WORKDIR /
3840COPY --from=builder /workspace/manager .
0 commit comments