Skip to content

Commit 42d28be

Browse files
authored
Use multi-stage docker builds and buildx for multi-arch (#2139)
1 parent 5902774 commit 42d28be

File tree

22 files changed

+260
-496
lines changed

22 files changed

+260
-496
lines changed

.github/workflows/release-cpo.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v3
1515

16-
- uses: actions/setup-go@v3
17-
with:
18-
go-version: 1.19
16+
-
17+
# Add support for more platforms with QEMU (optional)
18+
# https://github.com/docker/setup-qemu-action
19+
name: Set up QEMU
20+
uses: docker/setup-qemu-action@v2
1921

2022
- name: Set up Docker Buildx
21-
uses: docker/setup-buildx-action@v1
23+
uses: docker/setup-buildx-action@v2
2224

2325
- name: Login to docker hub
24-
uses: docker/login-action@v1
26+
uses: docker/login-action@v2
2527
with:
2628
registry: docker.io
2729
username: ${{ secrets.DOCKER_USERNAME }}
@@ -33,7 +35,7 @@ jobs:
3335

3436
- name: build & publish images
3537
run: |
36-
REGISTRY=docker.io/k8scloudprovider ARCHS='amd64 arm arm64 ppc64le s390x' GOOS=linux VERSION=${{ steps.get_version.outputs.VERSION }} make upload-images
38+
make push-multiarch-images REGISTRY=docker.io/k8scloudprovider VERSION=${{ steps.get_version.outputs.VERSION }}
3739
3840
- name: Create Release
3941
id: create_release

Dockerfile

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
################################################################################
14+
## BUILD ARGS ##
15+
################################################################################
16+
# This build arg allows the specification of a custom Golang image.
17+
ARG GOLANG_IMAGE=golang:1.19.6
18+
19+
# The distroless image on which the CPI manager image is built.
20+
#
21+
# Please do not use "latest". Explicit tags should be used to provide
22+
# deterministic builds. Follow what kubernetes uses to build
23+
# kube-controller-manager, for example for 1.23.x:
24+
# https://github.com/kubernetes/kubernetes/blob/release-1.24/build/common.sh#L94
25+
ARG DISTROLESS_IMAGE=k8s.gcr.io/build-image/go-runner:v2.3.1-go1.19.6-bullseye.0
26+
27+
# We use Alpine as the source for default CA certificates and some output
28+
# images
29+
ARG ALPINE_IMAGE=alpine:3.15.4
30+
31+
# cinder-csi-plugin uses Debian as a base image
32+
ARG DEBIAN_IMAGE=registry.k8s.io/build-image/debian-base:bullseye-v1.4.3
33+
34+
################################################################################
35+
## BUILD STAGE ##
36+
################################################################################
37+
38+
# Build an image containing a common ca-certificates used by all target images
39+
# regardless of how they are built. We arbitrarily take ca-certificates from
40+
# the Alpine image.
41+
FROM ${ALPINE_IMAGE} as certs
42+
RUN apk add --no-cache ca-certificates
43+
44+
45+
# Build all command targets. We build all command targets in a single build
46+
# stage for efficiency. Target images copy their binary from this image.
47+
FROM --platform=linux/amd64 ${GOLANG_IMAGE} as builder
48+
49+
ARG GOPROXY=https://goproxy.io,direct
50+
ARG TARGETOS
51+
ARG TARGETARCH
52+
ARG VERSION
53+
54+
WORKDIR /build
55+
COPY Makefile go.mod go.sum ./
56+
COPY cmd/ cmd/
57+
COPY pkg/ pkg/
58+
RUN make build GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOPROXY=${GOPROXY} VERSION=${VERSION}
59+
60+
61+
################################################################################
62+
## TARGET IMAGES ##
63+
################################################################################
64+
65+
##
66+
## openstack-cloud-controller-manager
67+
##
68+
FROM --platform=${TARGETPLATFORM} ${DISTROLESS_IMAGE} as openstack-cloud-controller-manager
69+
70+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
71+
COPY --from=builder /build/openstack-cloud-controller-manager /bin/openstack-cloud-controller-manager
72+
73+
LABEL name="openstack-cloud-controller-manager" \
74+
license="Apache Version 2.0" \
75+
maintainers="Kubernetes Authors" \
76+
description="OpenStack cloud controller manager" \
77+
distribution-scope="public" \
78+
summary="OpenStack cloud controller manager" \
79+
help="none"
80+
81+
CMD [ "/bin/openstack-cloud-controller-manager" ]
82+
83+
##
84+
## barbican-kms-plugin
85+
##
86+
FROM --platform=${TARGETPLATFORM} ${ALPINE_IMAGE} as barbican-kms-plugin
87+
# barbican-kms-plugin uses ALPINE instead of distroless because its entrypoint
88+
# uses a shell for environment substitution. If there are no other uses this
89+
# could be replaced by callers passing arguments explicitly.
90+
91+
COPY --from=builder /build/barbican-kms-plugin /bin/barbican-kms-plugin
92+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
93+
94+
LABEL name="barbican-kms-plugin" \
95+
license="Apache Version 2.0" \
96+
maintainers="Kubernetes Authors" \
97+
description="Barbican kms plugin" \
98+
distribution-scope="public" \
99+
summary="Barbican kms plugin" \
100+
help="none"
101+
102+
CMD ["sh", "-c", "/bin/barbican-kms-plugin --socketpath ${socketpath} --cloud-config ${cloudconfig}"]
103+
104+
##
105+
## cinder-csi-plugin
106+
##
107+
FROM --platform=${TARGETPLATFORM} ${DEBIAN_IMAGE} as cinder-csi-plugin
108+
109+
# Install e4fsprogs for format
110+
RUN clean-install btrfs-progs e2fsprogs mount udev xfsprogs
111+
112+
COPY --from=builder /build/cinder-csi-plugin /bin/cinder-csi-plugin
113+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
114+
115+
LABEL name="cinder-csi-plugin" \
116+
license="Apache Version 2.0" \
117+
maintainers="Kubernetes Authors" \
118+
description="Cinder CSI Plugin" \
119+
distribution-scope="public" \
120+
summary="Cinder CSI Plugin" \
121+
help="none"
122+
123+
CMD ["/bin/cinder-csi-plugin"]
124+
125+
##
126+
## k8s-keystone-auth
127+
##
128+
FROM --platform=${TARGETPLATFORM} ${DISTROLESS_IMAGE} as k8s-keystone-auth
129+
130+
COPY --from=builder /build/k8s-keystone-auth /bin/k8s-keystone-auth
131+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
132+
133+
LABEL name="k8s-keystone-auth" \
134+
license="Apache Version 2.0" \
135+
maintainers="Kubernetes Authors" \
136+
description="K8s Keystone Auth" \
137+
distribution-scope="public" \
138+
summary="K8s Keystone Auth" \
139+
help="none"
140+
141+
EXPOSE 8443
142+
143+
CMD ["/bin/k8s-keystone-auth"]
144+
145+
##
146+
## magnum-auto-healer
147+
##
148+
FROM --platform=${TARGETPLATFORM} ${DISTROLESS_IMAGE} as magnum-auto-healer
149+
150+
COPY --from=builder /build/magnum-auto-healer /bin/magnum-auto-healer
151+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
152+
153+
LABEL name="magnum-auto-healer" \
154+
license="Apache Version 2.0" \
155+
maintainers="Kubernetes Authors" \
156+
description="Magnum auto healer" \
157+
distribution-scope="public" \
158+
summary="Magnum auto healer" \
159+
help="none"
160+
161+
CMD ["/bin/magnum-auto-healer"]
162+
163+
##
164+
## manila-csi-plugin
165+
##
166+
FROM --platform=${TARGETPLATFORM} ${ALPINE_IMAGE} as manila-csi-plugin
167+
# manila-csi-plugin uses ALPINE because it pulls in jq and curl
168+
169+
RUN apk add --no-cache jq curl
170+
171+
COPY --from=builder /build/manila-csi-plugin /bin/manila-csi-plugin
172+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
173+
174+
LABEL name="manila-csi-plugin" \
175+
license="Apache Version 2.0" \
176+
maintainers="Kubernetes Authors" \
177+
description="Manila CSI Plugin" \
178+
distribution-scope="public" \
179+
summary="Manila CSI Plugin" \
180+
help="none"
181+
182+
ENTRYPOINT ["/bin/manila-csi-plugin"]
183+
184+
##
185+
## octavia-ingress-controller
186+
##
187+
FROM --platform=${TARGETPLATFORM} ${DISTROLESS_IMAGE} as octavia-ingress-controller
188+
189+
COPY --from=builder /build/octavia-ingress-controller /bin/octavia-ingress-controller
190+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
191+
192+
LABEL name="octavia-ingress-controller" \
193+
license="Apache Version 2.0" \
194+
maintainers="Kubernetes Authors" \
195+
description="Octavia ingress controller" \
196+
distribution-scope="public" \
197+
summary="Octavia ingress controller" \
198+
help="none"
199+
200+
CMD ["/bin/octavia-ingress-controller"]

0 commit comments

Comments
 (0)