mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
The CSI, LINSTOR, multus, Harbor and redis-backup images call tools at runtime that their base images or build stages install: mkfs and mount.nfs, drbd, lvm and zfs, the CNI plugins, nginx and trivy under a fixed uid, redis 8. A base or tool bump that drops one still builds, and only fails once the image runs in a cluster. The kubevirt CSI node plugin and its sidecars run inside tenant VMs on whatever vCPU they are given, so their filesystem tools, libc and Go entrypoints must not require more than x86-64-v2. C objects declare that level in a GNU property note and Go binaries in their GOAMD64 build setting; a file that records neither fails the check. Each PR build job runs the checks against the images it pushed, found by diffing the tree's image references before and after the build. Fork PRs are skipped because their images are not in a registry yet, and the unit lane runs no container. A change to kubevirt-csi-node alone, where the node sidecar tags live, now runs the kubevirt CSI build too, and the check fails when either sidecar is missing or the reference file cannot be read. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
110 lines
4.5 KiB
Bash
Executable File
110 lines
4.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Emit the JSON build matrix (the list of package dirs to build) for CI.
|
|
#
|
|
# Single source of truth: the `make -C packages/<dir> image` lines in the root
|
|
# Makefile `build:` target. Parsing them here keeps the CI matrix from drifting
|
|
# away from what `make build` actually builds.
|
|
#
|
|
# Usage: hack/build-matrix.sh [<changed-files>]
|
|
# no arg / empty / "FULL" -> every build unit (full matrix)
|
|
# <changed-files> -> only the units whose package dir has a changed
|
|
# file, UNLESS a shared-dependency path changed, in
|
|
# which case the full matrix is emitted (a change to
|
|
# cozy-lib / the build macros / go.mod / the build
|
|
# workflows can affect any image, so rebuild all).
|
|
#
|
|
# MATRIX_ARCH=arm64 also drops packages/core/testing, which pins linux/amd64
|
|
# (an x86 KVM sandbox): an arm64 leg building it would push a second amd64
|
|
# image under its -arm64 tag.
|
|
#
|
|
# Output: a JSON array of package dirs on stdout, e.g.
|
|
# ["packages/apps/mariadb","packages/system/dashboard"]
|
|
# An empty selection prints `[]` -> the matrix produces zero build jobs.
|
|
set -eu
|
|
|
|
MAKEFILE="${MAKEFILE:-Makefile}"
|
|
|
|
# Paths that force a full rebuild when touched. Kept deliberately broad — a
|
|
# false full-rebuild only costs time, a missed dependent ships a stale image.
|
|
full_rebuild_pattern='^(packages/library/|api/|cmd/|internal/|pkg/|hack/common-envs\.mk|hack/package\.mk|Makefile$|go\.mod$|go\.sum$|\.github/workflows/(pull-requests|build-main)\.yaml$|hack/build-matrix\.sh$)'
|
|
|
|
# The build units, parsed from the `build:` recipe (from `build:` to the next
|
|
# line that starts in column 0).
|
|
#
|
|
# packages/core/talos and packages/core/installer are deliberately excluded from
|
|
# the parallel matrix and handled by dedicated jobs instead:
|
|
# - talos: the installer tarball and Talos image are heavy; the dedicated
|
|
# leg runs when its direct or shared build inputs changed (and
|
|
# remains unconditional for forks). The container e2e lane does
|
|
# not consume a per-PR nocloud disk.
|
|
# - installer: its `flux push artifact --path=packages` bundles the ENTIRE,
|
|
# digest-patched packages tree into the OCI artifact the operator
|
|
# pulls, so it must run in the finalize step AFTER every other
|
|
# unit's digest edits are merged — never concurrently with them.
|
|
all_units() {
|
|
sed -n '/^build:/,/^[^[:space:]]/p' "$MAKEFILE" \
|
|
| grep -oE 'make -C packages/[A-Za-z0-9._/-]+ image' \
|
|
| sed -E 's/^make -C (packages[^ ]+) image$/\1/' \
|
|
| grep -vxE 'packages/core/(talos|installer)' \
|
|
| if [ "${MATRIX_ARCH:-}" = arm64 ]; then grep -vxF packages/core/testing; else cat; fi
|
|
}
|
|
|
|
emit_json() {
|
|
printf '['
|
|
_first=1
|
|
for _u in $1; do
|
|
if [ "$_first" -eq 1 ]; then _first=0; else printf ','; fi
|
|
printf '"%s"' "$_u"
|
|
done
|
|
printf ']\n'
|
|
}
|
|
|
|
units=$(all_units)
|
|
|
|
CHANGED="${1:-}"
|
|
if [ -z "$CHANGED" ] || [ "$CHANGED" = "FULL" ]; then
|
|
emit_json "$units"
|
|
exit 0
|
|
fi
|
|
|
|
# CI-only Go tools that no image builds. Dropped before the full-rebuild check,
|
|
# whose cmd/ would otherwise rebuild everything for an edit no image contains.
|
|
# hack/select-e2e.sh skips the same two, and a diff made only of them and docs/
|
|
# never reaches this script's build jobs (the plan job's `code` is false).
|
|
tooling_pattern='^cmd/(backport-batch|api-gate)/'
|
|
|
|
if grep -vE "$tooling_pattern" "$CHANGED" | grep -qE "$full_rebuild_pattern"; then
|
|
emit_json "$units"
|
|
exit 0
|
|
fi
|
|
|
|
selected=""
|
|
for u in $units; do
|
|
if grep -qE "^$u/" "$CHANGED"; then
|
|
selected="$selected $u"
|
|
fi
|
|
done
|
|
|
|
# Targeted cross-package fan-out that dir-scoping cannot see:
|
|
# objectstorage-controller derives its COSI sidecar tag from
|
|
# packages/system/seaweedfs/values.yaml, so a seaweedfs-only diff must still
|
|
# rebuild objectstorage-controller to regenerate that tag.
|
|
if grep -qE '^packages/system/seaweedfs/' "$CHANGED"; then
|
|
case " $selected " in
|
|
*" packages/system/objectstorage-controller "*) : ;;
|
|
*) selected="$selected packages/system/objectstorage-controller" ;;
|
|
esac
|
|
fi
|
|
|
|
# the kubevirt-csi-node sidecars run on tenant vCPUs and are ISA-checked by
|
|
# hack/image-smoke.bats in the job that builds kubevirt-csi-driver, so a
|
|
# kubevirt-csi-node-only diff must still run the kubernetes build.
|
|
if grep -qE '^packages/system/kubevirt-csi-node/' "$CHANGED"; then
|
|
case " $selected " in
|
|
*" packages/apps/kubernetes "*) : ;;
|
|
*) selected="$selected packages/apps/kubernetes" ;;
|
|
esac
|
|
fi
|
|
|
|
emit_json "$selected"
|