Files
cozystack/.github/workflows/build-main.yaml
T
Aleksei Sviridkin 6d759cc73e feat(build): build package images for amd64 and arm64 (#4498)
## What this PR does

Package images can now be built for amd64 and arm64 in one `make image`,
and a published build is multi-arch unless `PLATFORM` says otherwise.
This is the build half of arm64 support from #1961 and #903. CI still
publishes amd64 only until it gets a native arm64 leg, which comes in a
separate PR.

Builder stages now run on the build platform and compile for the target
one, so Go never runs under emulation. Under emulation it is slow and it
crashes: the migration-controller Dockerfile already records a "bad
pointer in Go heap" from exactly that. On top of this, `PLATFORM`
defaults to `linux/amd64,linux/arm64`. A build on an arm64 workstation
can't publish an arm64-only digest any more. That happened once already,
the cilium pin was arm64-only until 3f36a1b45 rebuilt it by hand.

Two images were only right because they were emulated. On a native
builder they would ship the wrong architecture. token-proxy ran `go
build` with no GOARCH, and kube-ovn calls upstream `make build-go`,
which hardcodes `GOARCH=amd64`. Both are fixed now. The new bats test
wants every compiling stage on `$BUILDPLATFORM` and actually using
`TARGETARCH`. A bare `ARG TARGETARCH` does not count, this is how
token-proxy got through.

Some things stay amd64. talos and testing pin it with `override`,
because matchbox serves amd64 Talos assets and the sandbox runs
`qemu-system-x86_64`. `LOAD=1` builds for the host only, since the
classic docker image store can't load an index. Every CI build job pins
`PLATFORM: linux/amd64`, so CI output does not change.

This changes local builds. A `make image` on the default docker driver
with the classic image store now fails with "Multi-platform build is not
supported for the docker driver", where before it built for the host.
Use a `docker-container` builder (`BUILDER=<name>`), or pass
`PLATFORM=linux/amd64` (or `LOAD=1`) to build one architecture.

I checked it on an arm64 host with a docker-container builder.
cozystack-api, dashboard, kubeovn, platform-migrations, cilium and
capi-providers-cpprovider build and push as amd64+arm64 indexes.
Binaries pulled from each platform are x86-64 and aarch64:
cozystack-api, token-proxy, the kamaji provider manager, cilium-agent
and all four kube-ovn binaries. piraeus-server builds for both
platforms, but the push to my test registry failed on registry 500s. The
capi-providers-cpprovider inline cache works with a multi-platform push.
Not covered is running the arm64 images on an arm64 cluster, CI has
none.

This is stacked on #4485 and targets its branch, so the diff here is
only the two commits on top.

### Screenshots

No UI changes.

### Downstream repositories

- [ ] No downstream repository is affected by this change
- [x] [cozystack/website](https://github.com/cozystack/website) -
follow-up: cozystack/website#711
- [ ]
[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
feat(build): package images build for linux/amd64 and linux/arm64 by default, with Go builders cross-compiling on the build platform; a local `make image` now needs a docker-container builder, or PLATFORM=linux/amd64 / LOAD=1 for a single architecture. CI still publishes amd64.
```


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

## Summary by CodeRabbit

* **Build Improvements**
* Container image builds now target both amd64 and arm64 by default when
building without loading images locally.
* CI and release builds are pinned to amd64; Talos and testing images
remain amd64-only.
* Cross-platform builds now compile on the builder’s native platform
while targeting the requested architecture.
* **Documentation**
* Clarified platform defaults and architecture requirements for local
and CI builds.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-28 19:43:47 +03:00

125 lines
5.2 KiB
YAML

name: Build cache (main)
# Warms the shared mode=max build cache so PR builds start hot.
#
# PR builds (pull-requests.yaml) read the cache but never write it
# (WRITE_CACHE unset -> 0). Only this serialized main build writes
# CACHE_REGISTRY/<img>:buildcache, so concurrent PR builds never race on the
# cache manifest -- the 409 collisions PR #2711 fixed for image tags would
# otherwise reappear on the cache ref. Cache is mode=max so all multistage
# `builder` stages are cached, not just the final stage as with inline.
#
# This job builds on a docker-container buildx builder, NOT the host's default
# embedded `docker` driver: `--cache-to type=registry,mode=max` is unsupported
# on the docker driver unless the daemon runs the containerd image store, so on
# a classic store the warmer would otherwise fail to export any cache. The
# container driver also gives this build its own buildkit (separate bbolt), so
# the warmer never contends with PR builds on the shared embedded buildkit.
env:
# Same per-CI registry as pull-requests.yaml; the cache is co-located here.
REGISTRY: iad.ocir.io/idyksih5sir9/cozystack
on:
push:
branches: [main]
paths-ignore:
- 'docs/**'
# Only the newest main commit's cache matters; cancel older in-flight warmers.
concurrency:
group: build-main-cache
cancel-in-progress: true
# Top-level token defaults to read-only; the warm-cache job below narrows to the
# packages:write scope it actually needs to push the build cache.
permissions:
contents: read
jobs:
warm-cache:
name: Warm build cache
# Runs on the ephemeral pool, not the dedicated self-hosted runner, so the
# build path no longer depends on that host (#2937 decommission). Serial
# `make build` is CPU-bound, so use the large shape; the warmer is a
# background main-push job, latency is not critical.
runs-on: oracle-vm-24cpu-96gb-x86-64
timeout-minutes: 120
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
fetch-tags: true
# This privileged workflow has packages:write and an OCIR push token;
# it never pushes git, so don't leave the checkout's GITHUB_TOKEN in
# .git/config where a later build step could read it.
persist-credentials: false
# Ephemeral runners lack the flux CLI the installer's image-packages step
# shells out to; install the pinned version when it is not already present.
- name: Set up build toolchain
env:
FLUX_VERSION: "2.8.6"
run: |
if ! flux version --client 2>/dev/null | grep -Fqx "flux: v${FLUX_VERSION}"; then
install_script="$(mktemp)"
curl -fsSL https://fluxcd.io/install.sh -o "$install_script"
sudo env "FLUX_VERSION=$FLUX_VERSION" bash "$install_script"
rm -f "$install_script"
fi
- name: Set up Docker config
run: |
if [ -d ~/.docker ]; then
cp -r ~/.docker "${{ runner.temp }}/.docker"
fi
- name: Login to OCIR
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
with:
username: ${{ secrets.OCIR_USER }}
password: ${{ secrets.OCIR_TOKEN }}
registry: iad.ocir.io
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
# docker-container driver: required for `--cache-to type=registry,mode=max`
# (unsupported on the host's default docker driver) and gives this build an
# isolated buildkit so it never contends with PR builds on the shared one.
- name: Set up Buildx (docker-container driver)
id: buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
with:
driver: docker-container
env:
# buildx stores builder instances under $DOCKER_CONFIG/buildx/instances/.
# Create the builder in the SAME config the build step reads
# (runner.temp/.docker, seeded above and holding the OCIR auth); without
# this the builder lands in the default ~/.docker and the build step fails
# with `no builder "<name>" found`.
DOCKER_CONFIG: ${{ runner.temp }}/.docker
- name: Build all images and write mode=max cache
run: make build
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
# Build on the docker-container builder created above (BUILDX_ARGS adds
# --builder=$(BUILDER)); buildx forwards the OCIR auth from DOCKER_CONFIG
# to the container builder for cache reads/writes and image pushes.
BUILDER: ${{ steps.buildx.outputs.name }}
# common-envs.mk defaults to amd64+arm64. Nothing here sets up QEMU,
# and on this x86-64 runner the arm64 half would be emulated anyway;
# CI builds amd64 until arm64 has a native leg of its own.
PLATFORM: linux/amd64
# WRITE_CACHE=1 turns on --cache-to (mode=max) for every image.
WRITE_CACHE: '1'
# Publish a floating :main handle; do not move :latest (releases do).
IMAGE_TAG: main
PUBLISH_VERSIONED: '0'
PUBLISH_FLOATING: '0'