perf(ci): build release lines from their own cache, in parallel (#5484)

## What this PR does

Release-line image builds read only main's build cache. After main moved
its builder and base images, release-1.7 Dockerfiles stopped matching
that cache, and rc Build step went from 19 to 53 minutes on amd64 and
from 10 to 46 on arm64
(https://github.com/cozystack/cozystack/actions/runs/43213142925 for
v1.7.1-rc.2,
https://github.com/cozystack/cozystack/actions/runs/45853634981 for
v1.7.2-rc.2).

Each line now keeps own cache. `build-release.yaml` writes
`buildcache-release-X.Y` on every push to the line, and rc builds import
it together with main's `buildcache` through new `CACHE_FROM_TAGS`
(defaults to `CACHE_TAG`, so other builds don't change). Lines have no
arm64 push build, so arm64 rc build writes
`buildcache-arm64-release-X.Y` itself.

Image units now build four at a time (`make build-parallel`,
`hack/build-units.sh`), most of their time is registry round trips
anyway. Every output line carries its unit and is written as it comes.
`objectstorage-controller` waits for the rest because it writes
seaweedfs `values.yaml`. Local `make build` stays sequential. rc jobs
also set `cleanup: false` on buildx, teardown took up to 11 minutes on
arm64 (682s in v1.7.2-rc.2).

Known limits: two rc tags of the same line building at the same time
write the same arm64 cache ref, last one wins and only cache hits
suffer. `capi-providers-cpprovider` keeps its own inline cache, as
before.

This gets real check only after merge: `build-release.yaml` on next push
to a line, `tags.yaml` on next rc. Both run from line's own copy, so
lines need ports, I'll open them after this one.

Tests: bats for the cache macro (lists every import, writes only
`CACHE_TAG`, writes nothing without `WRITE_CACHE=1`), for
`hack/build-units.sh` against fake make (the `BUILD_JOBS` limit,
ordering, failing unit, failing `objectstorage-controller`, failing unit
list, output that shows while a unit still builds) and for the workflow
settings. I also ran `hack/build-units.sh` over the real units with
`make -n`.

### 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
perf(ci): release lines build images from their own build cache, several units at a time, so rc builds no longer rebuild most images from scratch once main's Dockerfiles move on
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Build Improvements**
* Release builds now compile eligible components in parallel, while
retaining the required order for dependent components. Build parallelism
can be configured.
* Release-line builds use line-specific caches alongside shared caches.
Release-candidate builds reuse available caches, with arm64 builds
writing to an architecture-specific cache. Cache-write errors no longer
interrupt builds.
* **Documentation**
* Build guidance now covers parallel build settings, cache behavior, and
release build steps.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-12-01 06:32:29 +03:00
commit ce04ec3fb8
12 files changed
+251 -35

No files matched your search

+14 -12
View File
@@ -3,7 +3,7 @@ name: Build release line
# Publishes the per-line equivalent of what build-main.yaml publishes for main:
# every image tagged with the line's branch name, and the whole packages tree as
# the `cozystack-packages:<branch>` OCI artifact with each image reference
# digest-pinned to the images this run just pushed (`make build` ->
# digest-pinned to the images this run just pushed (`make build-parallel` ->
# packages/core/installer image-packages does the `flux push artifact`).
#
# Why it exists: pull-requests.yaml overlays image refs for every package a PR
@@ -16,9 +16,9 @@ name: Build release line
# artifact published per line, the overlay reads the PR's own base branch and the
# generations match.
#
# Cost: one full `make build` per push to a maintained line, i.e. per merged
# backport. That is the price of release-line PRs testing their line's tip rather
# than its last release.
# Cost: one full `make build-parallel` per push to a maintained line, i.e. per
# merged backport. That is the price of release-line PRs testing their line's
# tip rather than its last release.
env:
# Same per-CI registry as pull-requests.yaml and build-main.yaml.
@@ -140,19 +140,21 @@ jobs:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
- name: Build line images and publish the packages artifact
run: make build
run: make build-parallel
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
BUILDER: ${{ steps.buildx.outputs.name }}
# amd64 only, as in build-main.yaml.
PLATFORM: linux/amd64
# READ the shared mode=max cache, never write it. CACHE_REGISTRY/<img>:
# buildcache is a single ref per image and build-main.yaml is
# deliberately its only writer, serialized, precisely so concurrent
# builds cannot race on the cache manifest (the 409 collision class
# #2711 fixed for image tags). A line build can overlap a main build, so
# writing here would reintroduce exactly that race.
WRITE_CACHE: '0'
# The line keeps a mode=max cache of its own, which its rc builds in
# tags.yaml import too: main's cache (:buildcache, written only by
# build-main.yaml) misses more with every Dockerfile main changes after
# the line branched. The concurrency group above runs one build per
# line, so this is the only writer of the line's ref, and main's ref is
# only read.
CACHE_TAG: buildcache-${{ github.ref_name }}
CACHE_FROM_TAGS: buildcache-${{ github.ref_name }} buildcache
WRITE_CACHE: '1'
# Floating per-line handle: images and the packages artifact both land
# under the branch name (e.g. :release-1.6). Versioned and :latest tags
# belong to releases (tags.yaml / finalize), never to this workflow.
+20 -15
View File
@@ -101,6 +101,9 @@ jobs:
with:
driver: docker-container
buildkitd-config: hack/buildkitd.toml
# The runner is thrown away after the job; removing the builder only
# costs time.
cleanup: false
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
@@ -108,14 +111,13 @@ jobs:
if: steps.check_release.outputs.release_exists == 'false'
run: |
set -euo pipefail
# Assigned and checked before the loop: a build-matrix.sh failure
# inside `for unit in $(...)` would run no iteration and leave a
# green job that built nothing.
units="$(MATRIX_ARCH=arm64 hack/build-matrix.sh | jq -r '.[]')"
[ -n "$units" ]
for unit in $units; do
make -C "$unit" image
done
# The rc builds are the only arm64 builds a release line has, so they
# keep the line's arm64 cache themselves. They import main's nightly
# cache too, which is all the first rc of a line has.
line="release-$(echo "${GITHUB_REF_NAME#v}" | cut --delimiter=. --fields=1-2)"
export CACHE_TAG="buildcache-arm64-$line"
export CACHE_FROM_TAGS="buildcache-arm64-$line buildcache-arm64"
MATRIX_ARCH=arm64 hack/build-units.sh
make -C packages/core/installer image-operator
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
@@ -123,10 +125,7 @@ jobs:
SBOM: '1'
PLATFORM: linux/arm64
CACHE_REGISTRY: iad.ocir.io/idyksih5sir9/cozystack
# Read the arm64 cache build-arm64-nightly.yaml keeps warm; a release
# build never writes one.
CACHE_TAG: buildcache-arm64
WRITE_CACHE: '0'
WRITE_CACHE: '1'
IMAGE_TAG: ${{ github.ref_name }}-arm64
PUBLISH_VERSIONED: '0'
PUBLISH_FLOATING: '0'
@@ -143,8 +142,8 @@ jobs:
if: github.repository == 'cozystack/cozystack'
name: Build amd64 images and assets
# Ephemeral pool, not the dedicated self-hosted runner (#2937 decommission).
# Serial `make build` + `make assets` is CPU-bound, so use the large shape —
# same as the main cache warmer (build-main.yaml).
# `make build-parallel` runs several image builds at once, so use the large
# shape, as the main cache warmer (build-main.yaml) does.
runs-on: oracle-vm-24cpu-96gb-x86-64
# The budget prepare-release had while it also built; the stitch and the
# uploads it no longer runs moved to prepare-release with their own.
@@ -305,6 +304,9 @@ jobs:
driver: docker-container
buildkitd-config: hack/buildkitd.toml
use: false
# The runner is thrown away after the job; removing the builder only
# costs time.
cleanup: false
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
@@ -313,7 +315,7 @@ jobs:
if: steps.check_release.outputs.release_exists == 'false'
run: |
mkdir -p "${PUSHED_TAGS_LOG%/*}"
make build
make build-parallel
# The arm64 assets published below install this image, and building
# its arm64 half needs no QEMU, so it is pushed again as both arches.
make -C packages/core/talos image-talos PLATFORM=linux/amd64,linux/arm64
@@ -329,6 +331,9 @@ jobs:
# them from OCIR while pushing images to GHCR. A missing :buildcache
# ref 404s harmlessly into a cold build.
CACHE_REGISTRY: iad.ocir.io/idyksih5sir9/cozystack
# The line's own cache, which build-release.yaml writes on every push
# to the line, and main's.
CACHE_FROM_TAGS: buildcache-release-${{ steps.tag.outputs.line }} buildcache
# amd64 here; build-arm64 builds arm64 natively.
PLATFORM: linux/amd64
# Push the release tag as :IMAGE_TAG (vX.Y.Z-rc.N) and the component
+9
View File
@@ -54,6 +54,15 @@ build: build-deps
make -C packages/core/installer image
make manifests
# The same images as `build`, with the units in hack/build-matrix.sh built
# BUILD_JOBS at a time. The installer goes last because it packs the tree every
# other unit stamps.
build-parallel: build-deps
hack/build-units.sh
make -C packages/core/talos image
make -C packages/core/installer image
make manifests
manifests:
mkdir -p _out/assets
cat internal/crdinstall/manifests/*.yaml > _out/assets/cozystack-crds.yaml
+4 -1
View File
@@ -68,6 +68,7 @@ Root targets (run from the repo root):
```bash
make build # Build all Docker images (needs: docker, skopeo, jq, gh, helm, yq, GNU tar/sed/awk)
make build-parallel # The same images, BUILD_JOBS units at a time (hack/build-units.sh); what CI runs for release lines
make unit-tests # Run unit tests (requires bats-core >= 1.5; GNU parallel is optional)
make test-controllers # Run the Go tests under ./internal/... (controllers, contract tests)
make generate # Code generation (hack/update-codegen.sh) — CRDs, DeepCopy, clients, RBAC
@@ -95,7 +96,9 @@ Build environment variables:
- `LOAD=1 PUSH=0` — load images locally instead of pushing. Builds for the host architecture only, because the classic docker image store cannot load a multi-platform index.
- `PLATFORM` — the buildx platforms. Defaults to `linux/amd64,linux/arm64` for anything but `LOAD=1`, so a push from either architecture publishes an index both can run. Needs a `docker-container` builder (`BUILDER`) or a docker daemon on the containerd image store, with QEMU registered for the non-native half. Compiling builder stages run natively on `$BUILDPLATFORM` and cross-compile for the target, but every `RUN` step of a stage that runs on the target platform (package installs, `setcap`, install scripts, patch steps) still runs emulated. `packages/core/testing` pins `linux/amd64`, because it carries an x86 KVM sandbox. `packages/core/talos` builds the Talos installer and release assets for the arches in `PLATFORM` with the upstream imager, which needs no QEMU for either; its matchbox image carries the amd64 and arm64 kernel and initramfs whatever `PLATFORM` says, because it network-boots machines of either arch.
- `PUSHED_TAGS_LOG` — a file the `image-tags` macro appends every pushed `<repo>:<tag>` to, one per line. Unset by default; the release build sets it so `hack/stitch-multiarch.sh` can move every tag it pushed, versioned ones included, onto the multi-arch index. The append happens at recipe expansion, so `make -n` writes it too.
- `CACHE_TAG` — the tag of the mode=max build cache each image reads (and writes under `WRITE_CACHE=1`). Defaults to `buildcache`. Apart from the Talos installer and matchbox in the release job, CI builds one architecture per job, and builds arm64 images only for pre-release tags and in a nightly build of main: the images are built again on native arm64 runners under `<tag>-arm64` with `CACHE_TAG=buildcache-arm64`, which only the nightly writes. The talos and testing packages get no arm64 leg: the release job builds the Talos installer and matchbox for both arches itself, and testing is amd64 only. For a pre-release, `hack/stitch-multiarch.sh` then joins each pair into one index, `hack/verify-multiarch.sh` fails the rc on any pinned image that is not an amd64+arm64 index, and the packages artifact is republished pinned on the index digests; see `docs/release/ci-pipeline.md`. The stitch skips any image whose digest is also pinned in a file it does not rewrite, which then fails that gate; the kamaji control-plane provider's gzipped manifest is the one such copy it does rewrite (see `docs/agents/image-refs.md`).
- `CACHE_TAG` — the tag of the mode=max build cache each image reads (and writes under `WRITE_CACHE=1`). Defaults to `buildcache`. Apart from the Talos installer and matchbox in the release job, CI builds one architecture per job, and builds arm64 images only for pre-release tags and in a nightly build of main: the images are built again on native arm64 runners under `<tag>-arm64` with `CACHE_TAG=buildcache-arm64`, which the nightly writes. An rc build writes the arm64 cache of its own line, `buildcache-arm64-release-X.Y`, and imports the nightly's as well. The talos and testing packages get no arm64 leg: the release job builds the Talos installer and matchbox for both arches itself, and testing is amd64 only. For a pre-release, `hack/stitch-multiarch.sh` then joins each pair into one index, `hack/verify-multiarch.sh` fails the rc on any pinned image that is not an amd64+arm64 index, and the packages artifact is republished pinned on the index digests; see `docs/release/ci-pipeline.md`. The stitch skips any image whose digest is also pinned in a file it does not rewrite, which then fails that gate; the kamaji control-plane provider's gzipped manifest is the one such copy it does rewrite (see `docs/agents/image-refs.md`).
- `CACHE_FROM_TAGS` — every cache a build imports; defaults to `CACHE_TAG`. A release line imports its own `buildcache-release-X.Y`, which `build-release.yaml` writes on every push to the line, and main's `buildcache`, since main's Dockerfiles drift away from the line's.
- `BUILD_JOBS` — how many units `make build-parallel` builds at a time. Defaults to 4. `packages/system/objectstorage-controller` waits for the others, because it writes `packages/system/seaweedfs/values.yaml`, which the seaweedfs build rewrites too.
### Values schema generation
+1 -1
View File
@@ -12,7 +12,7 @@ The numbered process of a [regular release](./regular-releases.md#regular-releas
### Phase 1 — `build-amd64`, `build-arm64` and `prepare-release` (hard gate)
On an rc tag push: builds images for both architectures, commits digest pins, creates the draft release, and pushes the `release-X.Y.Z-rc.N` staging branch. `build-amd64` holds the release-exists no-op and the rejection of a hand-pushed stable tag, and builds the amd64 images and the release assets (its `make build` also pushes the packages artifact and the installer chart, pinned on amd64 digests); `prepare-release` stitches, gates, republishes those two from the repinned tree, and publishes the release. (The stable promote PR is opened later by `promote-rc.yaml`, not here. When the stable tag itself is pushed by finalize, a draft already exists, so this job is a no-op — see [Phase 5](#phase-5--pull-requests-releaseyaml-finalize).)
On an rc tag push: builds images for both architectures, commits digest pins, creates the draft release, and pushes the `release-X.Y.Z-rc.N` staging branch. `build-amd64` holds the release-exists no-op and the rejection of a hand-pushed stable tag, and builds the amd64 images and the release assets (its `make build-parallel` also pushes the packages artifact and the installer chart, pinned on amd64 digests); `prepare-release` stitches, gates, republishes those two from the repinned tree, and publishes the release. (The stable promote PR is opened later by `promote-rc.yaml`, not here. When the stable tag itself is pushed by finalize, a draft already exists, so this job is a no-op — see [Phase 5](#phase-5--pull-requests-releaseyaml-finalize).)
The commit (`Prepare release vX.Y.Z`, authored by `cozystack-ci[bot]`) is **digest pins and image tags only**:
+34
View File
@@ -0,0 +1,34 @@
#!/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
+97
View File
@@ -0,0 +1,97 @@
#!/usr/bin/env bats
# Unit tests for hack/build-units.sh, run against a fake unit list and a fake
# `make` that records when each unit starts and ends and how many build at once.
#
# 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
# Copies the script into an empty tree with a five-unit matrix and a fake make.
# Every fake build takes half a second, so builds allowed to overlap do overlap.
fake_tree() {
work="$(mktemp -d)"
mkdir -p "$work/hack" "$work/bin"
cp hack/build-units.sh "$work/hack/"
echo 0 > "$work/active"
cat > "$work/hack/build-matrix.sh" <<'EOF'
#!/bin/sh
[ -z "${MATRIX_FAILS:-}" ] || exit 1
echo '["packages/system/seaweedfs","packages/system/objectstorage-controller","packages/apps/a","packages/apps/b","packages/apps/c"]'
EOF
cat > "$work/bin/make" <<'EOF'
#!/bin/sh
unit="$2"
add() {
flock "$WORK/lock" sh -c 'n=$(( $(cat "$1/active") + $2 )); echo "$n" > "$1/active"; echo "$n" >> "$1/running"' _ "$WORK" "$1"
}
echo "start $unit" >> "$WORK/order"
echo "working on $unit"
add 1
[ "$unit" != "${HANG_UNIT:-}" ] || sleep 3
if [ "$unit" = packages/system/objectstorage-controller ] && ! grep -qx 'end packages/system/seaweedfs' "$WORK/order"; then
echo "objectstorage-controller started while seaweedfs was still building"
exit 1
fi
sleep 0.5
add -1
if [ "$unit" = "${FAIL_UNIT:-}" ]; then
echo "boom from $unit"
exit 1
fi
echo "end $unit" >> "$WORK/order"
EOF
chmod +x "$work/hack/build-matrix.sh" "$work/bin/make"
}
run_units() {
run bash -c 'cd "$1" && WORK="$1" PATH="$1/bin:$PATH" BUILD_JOBS=2 timeout "${TIMEOUT:-60}" hack/build-units.sh' _ "$work"
echo "$output"
}
@test "every unit is built once, two at a time, and objectstorage-controller after seaweedfs" {
fake_tree
run_units
[ "$status" -eq 0 ]
for unit in packages/system/seaweedfs packages/system/objectstorage-controller packages/apps/a packages/apps/b packages/apps/c; do
[ "$(grep -cx "start $unit" "$work/order")" -eq 1 ]
[ "$(grep -cx "end $unit" "$work/order")" -eq 1 ]
done
[ "$(sort -n "$work/running" | tail -n 1)" -eq 2 ]
rm -rf "$work"
}
@test "a failing unit fails the build, its output is shown, and objectstorage-controller is not built" {
fake_tree
FAIL_UNIT=packages/apps/b run_units
[ "$status" -ne 0 ]
echo "$output" | grep -qF 'boom from packages/apps/b'
if grep -qx 'start packages/system/objectstorage-controller' "$work/order"; then
echo "FAIL: objectstorage-controller was built after another unit failed"; false
fi
rm -rf "$work"
}
@test "a unit list that cannot be generated fails the build before anything is built" {
fake_tree
MATRIX_FAILS=1 run_units
[ "$status" -ne 0 ]
if [ -e "$work/order" ]; then echo "FAIL: units were built without a unit list"; false; fi
rm -rf "$work"
}
@test "a failing objectstorage-controller, built after the others, fails the build too" {
fake_tree
FAIL_UNIT=packages/system/objectstorage-controller run_units
[ "$status" -ne 0 ]
echo "$output" | grep -qF 'packages/system/objectstorage-controller: boom from packages/system/objectstorage-controller'
rm -rf "$work"
}
@test "a unit's output shows while it builds, so a job that times out keeps it" {
fake_tree
HANG_UNIT=packages/apps/a TIMEOUT=1 run_units
[ "$status" -eq 124 ]
echo "$output" | grep -qF 'packages/apps/a: working on packages/apps/a'
rm -rf "$work"
}
+6 -1
View File
@@ -148,12 +148,17 @@ endef
# so ALL stages are cached -- including the multistage `builder` layers that
# `--cache-to type=inline` could never export. oci-mediatypes + image-manifest
# keep the cache manifest portable across registries (OCIR/ghcr/ECR).
# ignore-error: OCIR refuses a blob upload now and then, and a lost cache
# write should cost the next build time, not fail this one.
# CACHE_TAG lets a build for another platform keep a cache of its own
# (buildcache-arm64) instead of overwriting the amd64 one with every write.
# CACHE_FROM_TAGS lists every cache a build imports; a release line imports its
# own as well as main's, since main's Dockerfiles drift away from the line's.
# $(comma) (defined above) escapes the literal commas in the --cache-to value so
# make does not mis-parse them as $(if ...) argument separators.
CACHE_TAG ?= buildcache
cache-args = --cache-from type=registry,ref=$(CACHE_REGISTRY)/$(1):$(CACHE_TAG)$(if $(filter 1,$(WRITE_CACHE)), --cache-to type=registry$(comma)ref=$(CACHE_REGISTRY)/$(1):$(CACHE_TAG)$(comma)mode=max$(comma)oci-mediatypes=true$(comma)image-manifest=true)
CACHE_FROM_TAGS ?= $(CACHE_TAG)
cache-args = $(foreach t,$(CACHE_FROM_TAGS),--cache-from type=registry$(comma)ref=$(CACHE_REGISTRY)/$(1):$(t))$(if $(filter 1,$(WRITE_CACHE)), --cache-to type=registry$(comma)ref=$(CACHE_REGISTRY)/$(1):$(CACHE_TAG)$(comma)mode=max$(comma)oci-mediatypes=true$(comma)image-manifest=true$(comma)ignore-error=true)
ifeq ($(COZYSTACK_VERSION),)
$(shell git remote add upstream https://github.com/cozystack/cozystack.git || true)
+24
View File
@@ -202,6 +202,30 @@ load test_helper
echo "$out" | grep -q -- '--cache-to type=registry,ref=[^ ]*/img:buildcache-arm64,'
}
@test "CACHE_FROM_TAGS imports every cache it lists and the build still writes only CACHE_TAG" {
# A release line imports its own cache and main's, whose Dockerfiles drift
# away from the line's over time.
pkg=packages/system/cozystack-controller
out=$(make -n -C "$pkg" image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b WRITE_CACHE=1 CACHE_TAG=buildcache-release-1.7 'CACHE_FROM_TAGS=buildcache-release-1.7 buildcache')
echo "$out" | grep -q -- '--cache-from type=registry,ref=[^ ]*/cozystack-controller:buildcache-release-1.7 '
echo "$out" | grep -q -- '--cache-from type=registry,ref=[^ ]*/cozystack-controller:buildcache '
echo "$out" | grep -q -- '--cache-to type=registry,ref=[^ ]*/cozystack-controller:buildcache-release-1.7,'
# A failed cache write must not fail the build: OCIR refuses a blob upload now
# and then.
echo "$out" | grep -q -- '--cache-to type=registry,ref=[^ ]*/cozystack-controller:buildcache-release-1.7,[^ ]*ignore-error=true'
[ "$(echo "$out" | grep -o -- '--cache-to' | wc -l)" -eq 1 ]
# Importing from several caches writes none of them unless WRITE_CACHE=1:
# PR builds and the amd64 rc build only read.
for write in '' WRITE_CACHE=0; do
out=$(make -n -C "$pkg" image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b $write 'CACHE_FROM_TAGS=buildcache-release-1.7 buildcache')
[ "$(echo "$out" | grep -o -- '--cache-from' | wc -l)" -eq 2 ]
[ "$(echo "$out" | grep -o -- '--cache-to' | wc -l)" -eq 0 ]
done
# Without it, a build imports exactly the one cache it would write.
out=$(make -n -C "$pkg" image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b)
[ "$(echo "$out" | grep -o -- '--cache-from' | wc -l)" -eq 1 ]
}
@test "the kamaji provider image is pushed under the build's IMAGE_TAG like every other image" {
# An IMAGE_TAG assigned in a package Makefile beats the value CI puts in the
# environment, so every PR, main and line build would push the same
+5 -4
View File
@@ -322,10 +322,11 @@ load test_helper
# It must not write the shared mode=max cache: that ref has exactly one
# serialized writer (build-main.yaml) so concurrent builds cannot race on the
# cache manifest. A line build can overlap a main build.
printf '%s\n' "$code" | grep -qF "WRITE_CACHE: '0'" || {
echo "build-release.yaml must set WRITE_CACHE: '0' — writing the shared" >&2
echo ":buildcache ref races build-main.yaml on the cache manifest." >&2
# cache manifest. A line build can overlap a main build, so it writes only
# the line's own ref.
printf '%s\n' "$code" | grep -qF 'CACHE_TAG: buildcache-${{ github.ref_name }}' || {
echo "build-release.yaml must write only its line's cache ref — writing the" >&2
echo "shared :buildcache ref races build-main.yaml on the cache manifest." >&2
exit 1; }
}
+36
View File
@@ -0,0 +1,36 @@
#!/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 ]
}
+1 -1
View File
@@ -383,7 +383,7 @@ _make_world() {
amd_steps=$(yq -r '.jobs.build-amd64.steps[].name' "$wf")
echo "$amd_steps" | grep -qx 'Check if release already exists'
echo "$amd_steps" | grep -qx 'Reject hand-pushed stable tags'
[ "$(yq -r '.jobs.build-arm64.steps[] | select(.run // "" | test("build-matrix")) | .env.IMAGE_TAG' "$wf")" = '${{ github.ref_name }}-arm64' ]
[ "$(yq -r '.jobs.build-arm64.steps[] | select(.run // "" | test("build-units")) | .env.IMAGE_TAG' "$wf")" = '${{ github.ref_name }}-arm64' ]
[ "$(yq -r '.jobs.prepare-release.needs | sort | join(" ")' "$wf")" = 'build-amd64 build-arm64' ]
cond=$(yq -r '.jobs.prepare-release.if' "$wf")
echo "$cond" | grep -qF '!cancelled()'