Skip to content

Commit 719a5bc

Browse files
Support multiarch driver builds
1 parent b8444a3 commit 719a5bc

File tree

4 files changed

+123
-27
lines changed

4 files changed

+123
-27
lines changed

.github/workflows/build-test-publish.yaml

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ env:
1919
REGISTRY: ghcr.io
2020
# Where to push an image of the CSI driver that will be retained (for master builds or releases) without a specific tag:
2121
IMAGE_NAME: ghcr.io/thinkparq/beegfs-csi-driver
22+
# Equivalent of BUILD_PLATFORMS in the Makefile and release-tools build.make. We cannot just set
23+
# this as a default inside the project Makefile because it will be overridden by the release-tools
24+
# build.make. We can't update release-tools because it there is a check to prevent modifying
25+
# release-tools. Note release-tools specifies the buildx_platform without the os (i.e., arm64
26+
# instead of linux/arm64).
27+
RELEASE_TOOLS_BUILD_PLATFORMS: "linux amd64 amd64 amd64;linux arm64 arm64 arm64"
28+
# Used as the list of platforms for Docker buildx when it is not called through release-tools.
29+
DOCKER_BUILDX_BUILD_PLATFORMS: "linux/amd64,linux/arm64"
2230
# Where to push an image of the CSI driver for testing (including the operator) without a specific tag:
2331
TEST_IMAGE_NAME: ghcr.io/thinkparq/test-beegfs-csi-driver
2432
# Where to push an image of the operator that will be retained (for master builds or releases) without a specific tag:
@@ -50,12 +58,12 @@ jobs:
5058
# Dependencies are cached by default: https://github.com/actions/setup-go#v4
5159
# This can be explicitly disabled if it ever causes problems.
5260

53-
- name: Build the container image
61+
- name: Build the BeeGFS CSI driver binaries and assemble chwrap tar files for each architecture
5462
run: |
5563
export SHELL=/bin/bash
56-
make container
57-
echo -n "verifying images:"
58-
docker images
64+
make BUILD_PLATFORMS="${{ env.RELEASE_TOOLS_BUILD_PLATFORMS }}" all
65+
echo -n "built artifacts:"
66+
ls -alh bin/
5967
6068
- name: Install test dependencies
6169
run: |
@@ -75,6 +83,9 @@ jobs:
7583
# TODO: Can we cache anything here? test-vendor downloads a lot of stuff.
7684
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go#caching-dependencies
7785

86+
- name: Set up Docker Buildx
87+
uses: docker/setup-buildx-action@v3
88+
7889
- name: Log into the GitHub Container Registry
7990
uses: docker/login-action@v2
8091
with:
@@ -84,10 +95,58 @@ jobs:
8495

8596
# Push the image for reuse in subsequent steps, jobs, and workflows.
8697
# For now just tag with the commit ID to ensure subsequent jobs in this workflow run use the correct image.
87-
- name: Tag and push the CSI driver as a test package
98+
# This uses the Git sha: https://github.com/docker/metadata-action?tab=readme-ov-file#typesha
99+
- name: Extract metadata for test CSI driver container image
100+
id: meta
101+
uses: docker/metadata-action@v4
102+
with:
103+
images: |
104+
${{ env.TEST_IMAGE_NAME }}
105+
tags: |
106+
type=sha,enable=true,priority=100,prefix=,suffix=,format=long
107+
108+
- name: Build and push test container images for each supported platform
109+
uses: docker/[email protected]
110+
id: build-and-push
111+
with:
112+
context: .
113+
platforms: "${{ env.DOCKER_BUILDX_BUILD_PLATFORMS }}"
114+
push: true
115+
tags: ${{ steps.meta.outputs.tags }}
116+
labels: ${{ steps.meta.outputs.labels }}
117+
# If provenance is not set to false then the manifest list will contain unknown platform
118+
# entries that are also displayed in GitHub. Some detail on why this is needed in:
119+
# https://github.com/docker/buildx/issues/1509 and
120+
# https://github.com/docker/build-push-action/issues/755#issuecomment-1607792956.
121+
provenance: false
122+
# Reference: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
123+
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=The BeeGFS Container Storage Interface (CSI) driver provides high performing and scalable storage for workloads running in Kubernetes,org.opencontainers.image.source=https://github.com/ThinkParQ/beegfs-csi-driver,org.opencontainers.image.licenses=Apache-2.0
124+
125+
126+
- name: Install Cosign
127+
uses: sigstore/[email protected]
128+
with:
129+
cosign-release: "v2.1.1"
130+
131+
# Adapted from:
132+
# https://github.blog/2021-12-06-safeguard-container-signing-capability-actions/
133+
# https://github.com/sigstore/cosign-installer#usage
134+
- name: Sign CSI driver images for each platform with Cosign
88135
run: |
89-
docker tag beegfs-csi-driver:latest ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }}
90-
docker push ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }}
136+
images=""
137+
for tag in ${TAGS}; do
138+
images+="${tag}@${DIGEST} "
139+
done
140+
cosign sign --yes --key env://COSIGN_PRIVATE_KEY \
141+
-a "repo=${{ github.repository }}" \
142+
-a "run=${{ github.run_id }}" \
143+
-a "ref=${{ github.sha }}" \
144+
${images}
145+
env:
146+
TAGS: ${{ steps.meta.outputs.tags }}
147+
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
148+
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
149+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
91150

92151
# TODO: Cache this dependency for reuse here and in e2e tests.
93152
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go#caching-dependencies
@@ -128,6 +187,12 @@ jobs:
128187
cd operator
129188
make -e IMG=${{ env.OPERATOR_TEST_IMAGE_NAME }}:${{ github.sha }} -e BUNDLE_IMG=${{ env.OPERATOR_TEST_BUNDLE_NAME }}:${{ github.sha }} bundle bundle-build bundle-push
130189
190+
- name: Upload artifacts
191+
uses: actions/upload-artifact@v4
192+
with:
193+
name: beegfs-csi-driver-artifacts
194+
path: bin/
195+
131196
e2e-tests:
132197
runs-on: ubuntu-22.04
133198
timeout-minutes: 10

Dockerfile

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
# Modifications Copyright 2021 NetApp, Inc. All Rights Reserved.
2+
# Modifications Copyright 2024 ThinkParQ, GmbH. All Rights Reserved.
23
# Licensed under the Apache License, Version 2.0.
34

45
# Use distroless as minimal base image to package the driver binary. Refer to
56
# https://github.com/GoogleContainerTools/distroless for more details.
6-
FROM gcr.io/distroless/static:latest
7-
7+
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static:latest
88
LABEL maintainers="ThinkParQ"
99
LABEL description="BeeGFS CSI Driver"
1010
LABEL org.opencontainers.image.description="BeeGFS CSI Driver"
1111
LABEL org.opencontainers.image.source="https://github.com/ThinkParQ/beegfs-csi-driver"
1212
LABEL org.opencontainers.image.licenses="Apache-2.0"
1313

14-
# Copy all built binaries to netapp/ directory.
15-
COPY bin/beegfs-csi-driver bin/chwrap netapp/
14+
# Multi-arch images can be built from this Dockerfile. When the container image is built it is
15+
# expected binaries and a chwrap tar file were already created under bin/ using Make. By default
16+
# calling Make with no arguments builds these files for the current architecture with no suffix
17+
# allowing the container image to be built without multiarch support by default.
18+
#
19+
# If Make is called with the `BUILD_PLATFORMS` build argument, then binaries and chwrap tar files
20+
# will be generared for each platform with an architecture suffix. These can then be used to build a
21+
# multiarch container image using `docker buildx build` by specifying the same list of platforms
22+
# using the `--platform` flag. Note the buildx flag and BUILD_PLATFORMS argument accept slightly
23+
# different values, for example to build for both amd64 and arm64:
24+
#
25+
# `make BUILD_PLATFORMS="linux amd64 amd64 amd64;linux arm64 arm64 arm64" all`
26+
# `docker buildx build --platform=linux/amd64,linux/arm64`
27+
ARG TARGETARCH
28+
# Work around the fact TARGETARCH is not set consistently when building multiarch images using
29+
# release-tools versus docker buildx. While release-tools isn't currently used by GitHub Actions to
30+
# publish multiarch images, this is the only thing preventing use of release-tools, which may be
31+
# useful for local testing.
32+
ARG ARCH=$TARGETARCH
33+
WORKDIR /
34+
35+
# Copy architecture specific BeeGFS CSI driver to the image.
36+
COPY bin/beegfs-csi-driver$ARCH /beegfs-csi-driver
1637

17-
# Add chwrap symbolic links to netapp/ directory.
18-
ADD bin/chwrap.tar /
38+
# Unpack architecture specific chwrap symbolic links into osutils directory.
39+
ADD bin/chwrap$ARCH.tar /
1940

2041
# Call chwrap linked binaries before container installed binaries.
21-
ENV PATH "/netapp:/$PATH"
42+
ENV PATH "/osutils:$PATH"
2243

23-
ENTRYPOINT ["beegfs-csi-driver"]
44+
ENTRYPOINT ["/beegfs-csi-driver"]

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
# limitations under the License.
1616

1717
# Modifications Copyright 2021 NetApp, Inc. All Rights Reserved.
18+
# Modifications Copyright 2024 ThinkParQ, GmbH. All Rights Reserved.
1819
# Licensed under the Apache License, Version 2.0.
1920

2021
CMDS ?= beegfs-csi-driver
2122
# Speed up unit testing by explicitly NOT building anything in the e2e folder.
2223
# Do not run any operator tests during normal testing.
2324
TEST_GO_FILTER_CMD = -e '/test/e2e' -e '/operator'
24-
all: build
25+
all: build build-chwrap bin/chwrap.tar
2526

2627
check-go-version:
2728
./hack/check-go-version.sh
@@ -36,7 +37,7 @@ generate-notices:
3637
build-%: check-go-version-go
3738
# Commands are taken directly from build.make build-%.
3839
mkdir -p bin
39-
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix; do \
40+
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
4041
if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags \
4142
'$(FULL_LDFLAGS)' -o "./bin/$*$$suffix" ./cmd/$*); then \
4243
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
@@ -46,14 +47,22 @@ build-%: check-go-version-go
4647

4748
# Put symbolic links between various commands (e.g. beegfs-ctl, mount, and umount) and cmd/chwrap into a .tar file to
4849
# be unpacked in the container. chwrap.tar is obviously not a binary file, but bin/ is where release-tools/build.make
49-
# outputs files and it is cleaned out on "make clean".
50+
# outputs files and it is cleaned out on "make clean". If we BUILD_PLATFORMS is set then we will create multiple tar
51+
# files each suffixed with the appropriate architecture. Otherwise we will create a single tar file with no suffix
52+
# for the current architecture.
5053
bin/chwrap.tar: build-chwrap cmd/chwrap/chwrap.sh
51-
cmd/chwrap/chwrap.sh bin/chwrap bin/chwrap.tar
54+
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
55+
if ! (set -x; cmd/chwrap/chwrap.sh bin/chwrap$$arch bin/chwrap$$arch.tar osutils); then \
56+
echo "Building $* for $$arch failed, see error(s) above."; \
57+
exit 1; \
58+
fi; \
59+
done
5260

53-
# The beegfs-csi-driver container requires chwrap to be built and included, so we build it anytime container or push
54-
# are made. Additional prerequisites and the recipes for container and push are defined in release-tools/build.make. A
55-
# different workaround will likely be required for multiarch builds.
61+
# The beegfs-csi-driver container requires chwrap to be built and included, so we build it anytime
62+
# container, push, or push-multiarch are made. Additional prerequisites and the recipes for
63+
# container and push are defined in release-tools/build.make.
5664
container: build-chwrap bin/chwrap.tar
65+
push-multiarch: build-chwrap bin/chwrap.tar
5766
push: container # not explicitly executed in release-tools/build.make
5867

5968
# For details on what licenses are disallowed see

cmd/chwrap/chwrap.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
# Copyright 2020 NetApp, Inc. All Rights Reserved.
66
# Modifications Copyright 2021 NetApp, Inc. All Rights Reserved.
7+
# Modifications Copyright 2024 ThinkParQ, GmbH. All Rights Reserved.
78
# Licensed under the Apache License, Version 2.0.
89

9-
[ -n "$1" ] && [ -n "$2" ] || exit 1
10+
[ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ] || exit 1
1011

1112
PREFIX=/tmp/$(uuidgen)
12-
mkdir -p $PREFIX/netapp
13-
cp "$1" $PREFIX/netapp/chwrap
13+
mkdir -p $PREFIX/$3
14+
cp "$1" $PREFIX/$3/chwrap
1415
for BIN in beegfs-ctl lsmod modprobe mount touch umount; do
15-
ln -s chwrap $PREFIX/netapp/$BIN
16+
ln -s chwrap $PREFIX/$3/$BIN
1617
done
17-
tar --owner=0 --group=0 -C $PREFIX -cf "$2" netapp
18+
tar --owner=0 --group=0 -C $PREFIX -cf "$2" $3
1819
rm -rf $PREFIX

0 commit comments

Comments
 (0)