Skip to content

Commit 71fb1b8

Browse files
Add operator multiarch builds
1 parent e31a88b commit 71fb1b8

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

operator/Dockerfile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@
66

77
# Use distroless as minimal base image to package the manager binary. Refer to
88
# https://github.com/GoogleContainerTools/distroless for more details.
9-
FROM gcr.io/distroless/static:nonroot
9+
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static:nonroot
10+
LABEL maintainers="ThinkParQ"
11+
LABEL description="BeeGFS CSI Driver Operator"
1012
LABEL org.opencontainers.image.description="BeeGFS CSI Driver Operator"
1113
LABEL org.opencontainers.image.source="https://github.com/ThinkParQ/beegfs-csi-driver/operator"
1214
LABEL org.opencontainers.image.licenses="Apache-2.0"
15+
16+
# Multi-arch images can be built from this Dockerfile. When the container image is built it is
17+
# expected the controller binary was already created and exists bin/ using Make. By default calling
18+
# Make with no arguments builds these files for the current architecture with no suffix allowing the
19+
# container image to be built without multiarch support by default.
20+
#
21+
# If Make is called with the `BUILD_PLATFORMS` build argument, a controller binary will be
22+
# compiled for each platform with an architecture suffix. These can then be used to build a
23+
# multiarch container image using `docker buildx build` by specifying the same list of platforms
24+
# using the `--platform` flag. Note the buildx flag and BUILD_PLATFORMS argument accept slightly
25+
# different values, for example to build for both amd64 and arm64:
26+
#
27+
# `make BUILD_PLATFORMS="linux amd64 amd64 amd64;linux arm64 arm64 arm64" all`
28+
# `docker buildx build --platform=linux/amd64,linux/arm64`
29+
ARG TARGETARCH
1330
WORKDIR /
14-
COPY bin/manager .
31+
32+
# Copy architecture specific manager to the image.
33+
COPY bin/manager$TARGETARCH /manager
1534
USER 65532:65532
1635

1736
ENTRYPOINT ["/manager"]

operator/Makefile

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
66
VERSION ?= 1.5.0
77

8+
# BUILD_PLATFORMS contains a set of tuples [os arch buildx_platform suffix base_image addon_image]
9+
# separated by semicolon. An empty variable or empty entry (= just a
10+
# semicolon) builds for the default platform of the current Go
11+
# toolchain. This approach was adapted from the CSI driver release-tools.1
12+
BUILD_PLATFORMS =
13+
814
# CHANNELS define the bundle channels used in the bundle.
915
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
1016
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
@@ -110,15 +116,24 @@ test: manifests generate fmt vet envtest ## Run tests.
110116
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./... -coverprofile cover.out
111117

112118
##@ Build
113-
114119
.PHONY: build
115120
build: generate fmt vet ## Build manager binary.
116-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager main.go
121+
mkdir -p bin
122+
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
123+
if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags \
124+
'$(FULL_LDFLAGS)' -o "./bin/manager$$suffix" main.go); then \
125+
echo "Building manager for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
126+
exit 1; \
127+
fi; \
128+
done
117129

118130
.PHONY: run
119131
run: manifests generate fmt vet ## Run a controller from your host.
120132
go run ./main.go --zap-devel=true --zap-log-level=5
121133

134+
# Note the Makefile doesn't build multiarch images (only the current architecture).
135+
# Multiarch images are currently built/published using GitHub actions or manually.
136+
122137
.PHONY: docker-build
123138
docker-build: test ## Build docker image with the manager.
124139
docker build -t ${IMG} .
@@ -249,9 +264,14 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
249264
.PHONY: docker-buildx
250265
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
251266
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
252-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
253-
- docker buildx create --name project-v3-builder
254-
docker buildx use project-v3-builder
255-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
256-
- docker buildx rm project-v3-builder
257-
rm Dockerfile.cross
267+
# sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
268+
# - docker buildx create --name project-v3-builder
269+
# docker buildx use project-v3-builder
270+
# - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
271+
# - docker buildx rm project-v3-builder
272+
# rm Dockerfile.cross
273+
# This has not been updated to work with how we build multiarch images using GitHub actions.
274+
# Fail the target to prevent accidental usage.
275+
@echo "Using the docker-buildx target is not currently supported"
276+
@exit 1
277+

operator/docs/developer-docs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ chmod +x install.sh
333333
* All prerequisites for the BeeGFS CSI driver must be installed on your
334334
Kubernetes nodes. If you are using Minikube there is a script to do this at
335335
`hack/minikube_install_driver_prerequisites.sh`.
336+
* You must also provide Minikube its own base client configuration file. For example you might
337+
bind mount /etc/beegfs from the host OS into the Minikube container using `minikube mount
338+
/etc/beegfs:/etc/beegfs` (note the command must stay running for the mount to stay active).
336339

337340
Steps:
338341

operator/hack/minikube_install_driver_prerequisites.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
export BEEGFS_VERSION=7.3.4
4+
export BEEGFS_VERSION=7.4.2
55

66
# Install the BeeGFS beegfs-ctl tool into the Minikube container:
77
minikube ssh "sudo apt-get update"

0 commit comments

Comments
 (0)