Skip to content

Commit 2e8219f

Browse files
authored
fix(build): pass the shared buildx flags from every image target (#4485)
## What this PR does Five image builds skipped the shared buildx flags in `hack/common-envs.mk` and wrote their own: flux-plunger, kubeovn-plunger, both dashboard images, and metallb. The plungers ignored `PLATFORM`, so on an arm64 workstation they came out as arm64 images that fail on amd64 nodes with `exec format error`. CI builds on amd64, so it never showed. Dashboard and metallb hardcoded `--platform=linux/amd64`; for metallb that sat next to `$(BUILDX_ARGS)`, so setting `PLATFORM` gave buildx two platforms. All of them now build through `$(BUILDX_ARGS)` only. How it split: kubeovn-plunger landed two days before 9f2b98d moved the other Makefiles onto `BUILDX_ARGS`, flux-plunger was copied from it, and dashboard kept its own flags when that change touched it. CI builds do not change. CI sets only `BUILDER`, which these targets already honoured, and every build runner is x86-64. One behaviour change is intentional: a local `make image` for dashboard or metallb now follows the host architecture, like every other package. On an arm64 machine, build for an amd64 cluster with `PLATFORM=linux/amd64`. A new bats test dry-runs every package image target with a probe platform and a marker in `BUILDX_EXTRA_ARGS`. Each buildx call must carry the marker and exactly that platform. On main it flags the five targets above. ### Screenshots No UI changes. ### Downstream repositories - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(build): every package image build honours PLATFORM, SBOM and BUILDX_EXTRA_ARGS; local dashboard and metallb builds now follow the host architecture unless PLATFORM is set. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * System image builds now use shared Buildx settings for platform selection and publishing options, while retaining their image tags, cache settings, and metadata. * MetalLB image builds no longer explicitly target `linux/amd64`; the selected platform follows Buildx defaults and configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 9c94337 + 623113f commit 2e8219f

6 files changed

Lines changed: 64 additions & 26 deletions

File tree

‎hack/common-envs.mk‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags --match 'v*'))
6161
# SBOM=1 attaches a CycloneDX SBOM as a buildx build attestation (--sbom=true).
6262
# Requires the docker-container buildx driver and registry referrers/attestation
6363
# support. Kept OFF by default until an OCIR referrers/attestation probe confirms
64-
# support — otherwise the attestation push fails the build. (NB: the dashboard
65-
# package's bespoke buildx calls don't read BUILDX_ARGS, so they are not yet
66-
# SBOM-covered — follow-up.) See #2937.
64+
# support — otherwise the attestation push fails the build. See #2937.
6765
SBOM ?= 0
6866

6967
BUILDX_ARGS := --provenance=false --push=$(PUSH) --load=$(LOAD) \
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bats
2+
# Every package image target builds through $(BUILDX_ARGS) from
3+
# hack/common-envs.mk, so PLATFORM, BUILDER, SBOM and BUILDX_EXTRA_ARGS reach
4+
# each `docker buildx build`. A target that spells its flags out instead builds
5+
# for the host architecture when PLATFORM is set: on an arm64 workstation that
6+
# is an arm64 image, which fails on amd64 nodes with "exec format error" while
7+
# CI, running on amd64, never shows it.
8+
#
9+
# The check is a dry run of `make image` with a platform no target hardcodes
10+
# and a marker passed through BUILDX_EXTRA_ARGS. Every buildx invocation it
11+
# prints must carry the marker, which only $(BUILDX_ARGS) forwards, and that
12+
# platform and no other, since a second hardcoded --platform turns the build
13+
# into a multi-platform one.
14+
#
15+
# Written for POSIX sh: hack/cozytest.sh sources this file into /bin/sh.
16+
#
17+
# Requires: make.
18+
19+
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
20+
PROBE_PLATFORM="linux/riscv64"
21+
PROBE_MARKER="--build-arg=BUILDX_ARGS_PROBE=1"
22+
23+
@test "every package image target passes BUILDX_ARGS and PLATFORM to docker buildx" {
24+
command -v make >/dev/null || { echo "make is required" >&2; exit 1; }
25+
26+
failed=""
27+
checked=0
28+
errlog="$(mktemp)"
29+
cmdlist="$(mktemp)"
30+
for makefile in "$REPO_ROOT"/packages/*/*/Makefile; do
31+
grep -q 'docker buildx build' "$makefile" || continue
32+
dir="$(dirname "$makefile")"
33+
# COZYSTACK_VERSION is set so common-envs.mk does not shell out to git.
34+
commands="$(make --no-print-directory -s -n -C "$dir" image \
35+
PLATFORM="$PROBE_PLATFORM" BUILDX_EXTRA_ARGS="$PROBE_MARKER" COZYSTACK_VERSION=0.0.0 2>"$errlog" \
36+
| sed -e ':a' -e '/\\$/N; s/\\\n//; ta' | grep 'docker buildx build')" || true
37+
if [ -z "$commands" ]; then
38+
failed="$failed ${dir#"$REPO_ROOT"/} (no buildx command: $(tr '\n' ' ' <"$errlog"))"
39+
continue
40+
fi
41+
printf '%s\n' "$commands" >"$cmdlist"
42+
while IFS= read -r cmd; do
43+
checked=$((checked + 1))
44+
case "$cmd" in
45+
*"$PROBE_MARKER"*) ;;
46+
*) failed="$failed ${dir#"$REPO_ROOT"/} (no \$(BUILDX_ARGS))"; continue ;;
47+
esac
48+
platforms="$(printf '%s\n' "$cmd" | grep -oE -- '--platform[= ][^ ]+' | tr '\n' ' ')"
49+
[ "$platforms" = "--platform=$PROBE_PLATFORM " ] || failed="$failed ${dir#"$REPO_ROOT"/} ($platforms)"
50+
done <"$cmdlist"
51+
done
52+
rm -f "$errlog" "$cmdlist"
53+
54+
[ "$checked" -gt 0 ] # the glob must find image targets at all
55+
if [ -n "$failed" ]; then
56+
echo "image targets not building through BUILDX_ARGS for exactly PLATFORM:$failed" >&2
57+
exit 1
58+
fi
59+
}

‎packages/system/dashboard/Makefile‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ image-console: build-console update-values-console
2525
build-console:
2626
docker buildx build images/console \
2727
--file images/console/Containerfile \
28-
--provenance false \
29-
--builder=$(BUILDER) \
30-
--platform=linux/amd64 \
3128
$(call image-tags,cozystack-ui,v$(COZYSTACK_VERSION)) \
3229
$(call cache-args,cozystack-ui) \
3330
--metadata-file images/console.json \
3431
--build-arg APP_VERSION=$(if $(COZYSTACK_VERSION),v$(COZYSTACK_VERSION),) \
35-
--push=$(PUSH) \
36-
--label "org.opencontainers.image.source=https://github.com/cozystack/cozystack" \
37-
--load=$(LOAD)
32+
$(BUILDX_ARGS)
3833

3934
update-values-console:
4035
IMAGE="$(REGISTRY)/cozystack-ui:$(IMAGE_TAG)@$$(yq e '."containerimage.digest"' images/console.json -r)" \
@@ -43,15 +38,10 @@ update-values-console:
4338

4439
image-token-proxy:
4540
docker buildx build images/token-proxy \
46-
--provenance false \
47-
--builder=$(BUILDER) \
48-
--platform=linux/amd64 \
4941
$(call image-tags,token-proxy,v$(COZYSTACK_VERSION)) \
5042
$(call cache-args,token-proxy) \
5143
--metadata-file images/token-proxy.json \
52-
--push=$(PUSH) \
53-
--label "org.opencontainers.image.source=https://github.com/cozystack/cozystack" \
54-
--load=$(LOAD)
44+
$(BUILDX_ARGS)
5545
IMAGE="$(REGISTRY)/token-proxy:$(IMAGE_TAG)@$$(yq e '."containerimage.digest"' images/token-proxy.json -r)" \
5646
yq -i '.tokenProxy.image = strenv(IMAGE)' values.yaml
5747
rm -f images/token-proxy.json

‎packages/system/flux-plunger/Makefile‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ include ../../../hack/package.mk
66

77
image:
88
docker buildx build -f images/flux-plunger/Dockerfile ../../../ \
9-
--provenance false \
10-
$(if $(strip $(BUILDER)),--builder=$(BUILDER)) \
119
$(call image-tags,flux-plunger,v$(COZYSTACK_VERSION)) \
1210
$(call cache-args,flux-plunger) \
1311
--metadata-file images/flux-plunger.json \
14-
--push=$(PUSH) \
15-
--label "org.opencontainers.image.source=https://github.com/cozystack/cozystack" \
16-
--load=$(LOAD)
12+
$(BUILDX_ARGS)
1713
IMAGE="$(REGISTRY)/flux-plunger:$(IMAGE_TAG)@$$(yq e '."containerimage.digest"' images/flux-plunger.json -o json -r)" \
1814
yq -i '.image = strenv(IMAGE)' values.yaml
1915
rm -f images/flux-plunger.json

‎packages/system/kubeovn-plunger/Makefile‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ include ../../../hack/package.mk
66

77
image:
88
docker buildx build -f images/kubeovn-plunger/Dockerfile ../../../ \
9-
--provenance false \
10-
$(if $(strip $(BUILDER)),--builder=$(BUILDER)) \
119
$(call image-tags,kubeovn-plunger,v$(COZYSTACK_VERSION)) \
1210
$(call cache-args,kubeovn-plunger) \
1311
--metadata-file images/kubeovn-plunger.json \
14-
--push=$(PUSH) \
15-
--label "org.opencontainers.image.source=https://github.com/cozystack/cozystack" \
16-
--load=$(LOAD)
12+
$(BUILDX_ARGS)
1713
IMAGE="$(REGISTRY)/kubeovn-plunger:$(IMAGE_TAG)@$$(yq e '."containerimage.digest"' images/kubeovn-plunger.json -o json -r)" \
1814
yq -i '.image = strenv(IMAGE)' values.yaml
1915
rm -f images/kubeovn-plunger.json

‎packages/system/metallb/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ image-controller image-speaker:
1717
$(eval TARGET := $(subst image-,,$@))
1818
$(eval VERSION := $(shell yq '.appVersion' charts/metallb/Chart.yaml))
1919
docker buildx build images/metallb \
20-
--platform=linux/amd64 \
2120
--target $(TARGET) \
2221
--build-arg VERSION=$(VERSION) \
2322
$(call image-tags,metallb-$(TARGET),$(VERSION)) \

0 commit comments

Comments
 (0)