-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
185 lines (138 loc) · 7.24 KB
/
Dockerfile
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.23 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY api/ api/
COPY broker/ broker/
COPY client-go/ client-go/
COPY cmd/ cmd/
COPY internal/ internal/
COPY ori/ ori/
COPY orictl/ orictl/
COPY orictl-bucket/ orictl-bucket/
COPY orictl-machine/ orictl-machine/
COPY orictl-volume/ orictl-volume/
COPY poollet/ poollet/
COPY utils/ utils/
ARG TARGETOS
ARG TARGETARCH
RUN mkdir bin
FROM builder as apiserver-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/onmetal-apiserver ./cmd/onmetal-apiserver
FROM builder as manager-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/onmetal-controller-manager ./cmd/onmetal-controller-manager
FROM builder as machinepoollet-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/machinepoollet ./poollet/machinepoollet/cmd/machinepoollet/main.go
FROM builder as machinebroker-builder
# TODO: Remove orictl-machine once debug containers are more broadly available.
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/machinebroker ./broker/machinebroker/cmd/machinebroker/main.go && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-machine ./orictl-machine/cmd/orictl-machine/main.go
FROM builder as orictl-machine-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-machine ./orictl-machine/cmd/orictl-machine/main.go
FROM builder as volumepoollet-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/volumepoollet ./poollet/volumepoollet/cmd/volumepoollet/main.go
FROM builder as volumebroker-builder
# TODO: Remove orictl-volume once debug containers are more broadly available.
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/volumebroker ./broker/volumebroker/cmd/volumebroker/main.go && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-volume ./orictl-volume/cmd/orictl-volume/main.go
FROM builder as orictl-volume-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-volume ./orictl-volume/cmd/orictl-volume/main.go
FROM builder as bucketpoollet-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/bucketpoollet ./poollet/bucketpoollet/cmd/bucketpoollet/main.go
FROM builder as bucketbroker-builder
# TODO: Remove orictl-bucket once debug containers are more broadly available.
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/bucketbroker ./broker/bucketbroker/cmd/bucketbroker/main.go && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-bucket ./orictl-bucket/cmd/orictl-bucket/main.go
FROM builder as orictl-bucket-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-bucket ./orictl-bucket/cmd/orictl-bucket/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:nonroot as manager
WORKDIR /
COPY --from=manager-builder /workspace/bin/onmetal-controller-manager .
USER 65532:65532
ENTRYPOINT ["/onmetal-controller-manager"]
FROM gcr.io/distroless/static:nonroot as apiserver
WORKDIR /
COPY --from=apiserver-builder /workspace/bin/onmetal-apiserver .
USER 65532:65532
ENTRYPOINT ["/onmetal-apiserver"]
FROM gcr.io/distroless/static:nonroot as machinepoollet
WORKDIR /
COPY --from=machinepoollet-builder /workspace/bin/machinepoollet .
USER 65532:65532
ENTRYPOINT ["/machinepoollet"]
# TODO: Switch to distroless as soon as ephemeral debug containers are more broadly available.
FROM debian:bullseye-slim as machinebroker
WORKDIR /
COPY --from=machinebroker-builder /workspace/bin/machinebroker .
# TODO: Remove orictl-machine as soon as ephemeral debug containers are more broadly available.
COPY --from=machinebroker-builder /workspace/bin/orictl-machine .
USER 65532:65532
ENTRYPOINT ["/machinebroker"]
FROM debian:bullseye-slim as orictl-machine
WORKDIR /
COPY --from=orictl-machine-builder /workspace/bin/orictl-machine .
USER 65532:65532
FROM gcr.io/distroless/static:nonroot as volumepoollet
WORKDIR /
COPY --from=volumepoollet-builder /workspace/bin/volumepoollet .
USER 65532:65532
ENTRYPOINT ["/volumepoollet"]
# TODO: Switch to distroless as soon as ephemeral debug containers are more broadly available.
FROM debian:bullseye-slim as volumebroker
WORKDIR /
COPY --from=volumebroker-builder /workspace/bin/volumebroker .
# TODO: Remove orictl-volume as soon as ephemeral debug containers are more broadly available.
COPY --from=volumebroker-builder /workspace/bin/orictl-volume .
USER 65532:65532
ENTRYPOINT ["/volumebroker"]
FROM debian:bullseye-slim as orictl-volume
WORKDIR /
COPY --from=orictl-volume-builder /workspace/bin/orictl-volume .
USER 65532:65532
FROM gcr.io/distroless/static:nonroot as bucketpoollet
WORKDIR /
COPY --from=bucketpoollet-builder /workspace/bin/bucketpoollet .
USER 65532:65532
ENTRYPOINT ["/bucketpoollet"]
# TODO: Switch to distroless as soon as ephemeral debug containers are more broadly available.
FROM debian:bullseye-slim as bucketbroker
WORKDIR /
COPY --from=bucketbroker-builder /workspace/bin/bucketbroker .
# TODO: Remove orictl-bucket as soon as ephemeral debug containers are more broadly available.
COPY --from=bucketbroker-builder /workspace/bin/orictl-bucket .
USER 65532:65532
ENTRYPOINT ["/bucketbroker"]
FROM debian:bullseye-slim as orictl-bucket
WORKDIR /
COPY --from=orictl-bucket-builder /workspace/bin/orictl-bucket .
USER 65532:65532