Files
cozystack/hack/release-build-cache-contract.bats
T
Myasnikov Daniil 09f6fb5757 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>
2026-12-01 02:10:21 +03:00

37 lines
1.9 KiB
Bash

#!/usr/bin/env bats
# The cache settings of the release-line image builds. build-release.yaml runs
# only on a push to a line and tags.yaml only on a tag, so no PR lane would
# notice a change to them.
#
# Test-level EXIT traps replace Bats' own handler and hide failing TAP results.
# Cleanup follows aborting assertions; see docs/agents/e2e-testing.md.
load test_helper
@test "a push to a release line writes the line's cache and imports main's too" {
step='.jobs["build-line"].steps[] | select(.name == "Build line images and publish the packages artifact")'
wf=.github/workflows/build-release.yaml
[ "$(yq "$step | .run" "$wf")" = 'make build-parallel' ]
[ "$(yq "$step | .env.WRITE_CACHE" "$wf")" = 1 ]
[ "$(yq "$step | .env.CACHE_TAG" "$wf")" = 'buildcache-${{ github.ref_name }}' ]
[ "$(yq "$step | .env.CACHE_FROM_TAGS" "$wf")" = 'buildcache-${{ github.ref_name }} buildcache' ]
}
@test "an rc build imports its line's cache and main's, and only arm64 writes one" {
wf=.github/workflows/tags.yaml
amd64='.jobs["build-amd64"].steps[] | select(.name == "Build")'
[ "$(yq "$amd64 | .env.CACHE_FROM_TAGS" "$wf")" = 'buildcache-release-${{ steps.tag.outputs.line }} buildcache' ]
[ "$(yq "$amd64 | .env.WRITE_CACHE" "$wf")" = null ]
arm64='.jobs["build-arm64"].steps[] | select(.name == "Build arm64 images")'
[ "$(yq "$arm64 | .env.WRITE_CACHE" "$wf")" = 1 ]
yq "$arm64 | .run" "$wf" | grep -qxF 'export CACHE_TAG="buildcache-arm64-$line"'
yq "$arm64 | .run" "$wf" | grep -qxF 'export CACHE_FROM_TAGS="buildcache-arm64-$line buildcache-arm64"'
}
@test "the rc build jobs leave their buildx builder to the throwaway runner" {
wf=.github/workflows/tags.yaml
setup='[(.jobs["build-arm64"].steps[], .jobs["build-amd64"].steps[]) | select((.uses // "") | test("^docker/setup-buildx-action@"))]'
[ "$(yq "$setup | length" "$wf")" -eq 2 ]
[ "$(yq "$setup | map(.with.cleanup == false) | all" "$wf")" = true ]
}