Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (53 loc) · 2.46 KB
/
Copy pathDockerfile
File metadata and controls
64 lines (53 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Support FROM override
ARG BUILD_IMAGE=docker.io/golang:1.26.6@sha256:640a234f4bea3e399c056b7b8f9c667c4939befae8db2f14e9785e16eccd4205
ARG BASE_IMAGE=gcr.io/distroless/base-debian13:nonroot@sha256:a557d784ac275c287d2bdf3172f47bece8d2a0ef3c0fdefb712e95084a04a562
# Shared SDK stage: pinned Go toolchain, modules, and checked-out tree.
# Downstream builder stages copy from here so we pay the `go mod download`
# cost once. Third parties can also build custom provisioner plugins against
# this image to guarantee toolchain and module-version parity with BMO.
FROM $BUILD_IMAGE AS sdk
WORKDIR /workspace
COPY go.mod go.sum ./
COPY apis/go.mod apis/go.sum apis/
COPY hack/tools/go.mod hack/tools/go.sum hack/tools/
COPY pkg/hardwareutils/go.mod pkg/hardwareutils/go.sum pkg/hardwareutils/
RUN go mod download
COPY . .
ENV CGO_ENABLED=1
ENV GO111MODULE=on
# Build the manager binary
FROM sdk AS builder
ARG ARCH=amd64
ARG LDFLAGS=-s -w
RUN GOOS=linux GOARCH=${ARCH} \
go build -a -ldflags "${LDFLAGS}" -o baremetal-operator main.go
# Build the ironic provisioner plugin
FROM sdk AS ironic-plugin-builder
ARG ARCH=amd64
ARG LDFLAGS=-s -w
RUN GOOS=linux GOARCH=${ARCH} \
go build -buildmode=plugin -ldflags "${LDFLAGS}" \
-o ironic-provisioner.so ./pkg/provisioner/ironic/plugin/
# Build the demo provisioner plugin
FROM sdk AS demo-plugin-builder
ARG ARCH=amd64
ARG LDFLAGS=-s -w
RUN GOOS=linux GOARCH=${ARCH} \
go build -buildmode=plugin -ldflags "${LDFLAGS}" \
-o demo-provisioner.so ./pkg/provisioner/demo/plugin/
# Runtime image. Uses distroless/base (not static) because Go plugins need glibc.
FROM $BASE_IMAGE
# image.version is set during image build by automation
LABEL org.opencontainers.image.authors="metal3-dev@googlegroups.com"
LABEL org.opencontainers.image.description="This is the image for the Metal3 BareMetal Operator"
LABEL org.opencontainers.image.documentation="https://book.metal3.io/bmo/introduction"
LABEL org.opencontainers.image.licenses="Apache License 2.0"
LABEL org.opencontainers.image.title="Metal3 BareMetal Operator"
LABEL org.opencontainers.image.url="https://github.com/metal3-io/baremetal-operator"
LABEL org.opencontainers.image.vendor="Metal3-io"
WORKDIR /
COPY --from=builder /workspace/baremetal-operator .
COPY --from=ironic-plugin-builder /workspace/ironic-provisioner.so /plugins/ironic-provisioner.so
COPY --from=demo-plugin-builder /workspace/demo-provisioner.so /plugins/demo-provisioner.so
USER nonroot:nonroot
ENTRYPOINT ["/baremetal-operator"]