Files
cozystack/hack/build-units.sh
T
Myasnikov Daniil 5e29156c73 perf(ci): build release lines from their own cache, in parallel
Release-line image builds read only main's build cache. Once main moved
its builder and base images, release-1.7's Dockerfiles stopped matching
that cache, and the rc Build step went from 19 to 53 minutes on amd64
and from 10 to 46 on arm64 between v1.7.1-rc.2 and v1.7.2-rc.2.

Each line now keeps a cache of its own. build-release.yaml writes
buildcache-release-X.Y on every push to the line, and rc builds import
it together with main's buildcache. The arm64 rc build, the only arm64
build a line has, keeps buildcache-arm64-release-X.Y itself.
CACHE_FROM_TAGS lists every cache a build imports; unset, it is
CACHE_TAG, as before.

The units of hack/build-matrix.sh now build four at a time (make build-
parallel, hack/build-units.sh), since they spend most of their time on
registry round trips, one image after another. Every output line carries
its unit and is written as it comes, so a job that times out still shows
where it stopped. objectstorage-controller waits for the rest because it
writes seaweedfs' values.yaml. The rc jobs also leave their buildx
builder to the throwaway runner: removing it took up to 11 minutes on
arm64.

A cache write that fails no longer fails the build (ignore-error=true on
every --cache-to): OCIR refuses a blob upload now and then, which
already failed the arm64 nightly twice in its last thirty runs, and rc
and line builds now write a cache too.

Tested with bats: the cache macro, the unit builder against a fake make
(the BUILD_JOBS limit, ordering, a failing unit, a failing
objectstorage-controller, a unit list that cannot be generated, and
output that shows while a unit still builds) and the workflow settings,
plus a dry run of hack/build-units.sh over the real units with make -n.

Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
(cherry picked from commit 12eaa49521)
2026-11-27 13:22:51 +00:00

35 lines
1006 B
Bash
Executable File

#!/usr/bin/env bash
# Builds the image units hack/build-matrix.sh lists, BUILD_JOBS at a time.
# Several build at once, so every output line starts with its unit.
#
# Run from the repository root. Talos and the installer are not in the list;
# `make build-parallel` builds them afterwards.
set -euo pipefail
jobs="${BUILD_JOBS:-4}"
# It rewrites packages/system/seaweedfs/values.yaml, which the seaweedfs build
# rewrites too, so it waits until the others are done.
last=packages/system/objectstorage-controller
units="$(hack/build-matrix.sh | jq --raw-output '.[]')"
[ -n "$units" ]
build() {
set -o pipefail
if make -C "$1" image 2>&1 | sed --unbuffered "s|^|$1: |"; then
echo "built $1"
else
echo "::error::$1 failed"
return 1
fi
}
export -f build
grep --invert-match --line-regexp --fixed-strings "$last" <<< "$units" |
xargs --max-procs="$jobs" --max-args=1 bash -c 'build "$1"' _
if grep --quiet --line-regexp --fixed-strings "$last" <<< "$units"; then
build "$last"
fi