sonda/.forgejo/workflows/release.yml
tgiachi b37e3db037 feat: publish the Docker image for ARM as well
The image is now made for amd64 and for arm64, and each tag (X.Y.Z, X.Y,
latest) points at both, so a Raspberry Pi or an ARM NAS pulls the right one.

- Dockerfile: the web and Go stages run on the builder and the Go program is
  cross-compiled (GOARCH from SONDA_ARCH or TARGETARCH); what the image needs
  besides the program (time zones, the user, the folders) is made in a stage
  of the builder, so the last stage runs no command and needs no emulation.
- release workflow: the runner has no Docker and cannot run ARM, and kaniko
  takes the base of every stage for one platform, so the arm64 image starts
  from the arm64 Alpine by digest (found at each release), kaniko builds one
  image per architecture, and crane sets the architecture of each and joins
  them under the tags.
2026-11-16 14:33:41 +01:00

138 lines
5.9 KiB
YAML

# What happens at every merge into main:
# 1. semantic-release reads the commits since the last release (Conventional Commits), works out the next version,
# writes CHANGELOG.md, makes the release on the forge and tags it. A merge with nothing to release (docs, tests, ci)
# makes none.
# 2. When there is a release, the image is built from the tag, for amd64 and for arm64, and pushed to
# git.kmalloc.org/squid/sonda as X.Y.Z-ARCH; then X.Y.Z, X.Y and latest are made to point at both.
# The runner has no Docker and cannot emulate another architecture, so the images are built with kaniko, which needs no
# daemon, and the Dockerfile crosses to arm64 without running anything for it.
# Secret needed: FORGEJO_TOKEN, a token of the owner with the scopes write:repository and write:package.
name: release
on:
push:
branches: [main]
# One release at a time: two merges close together must not make two versions at once.
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: docker
# The commit that the release makes (CHANGELOG.md) says [skip ci]; this is the belt for those braces.
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # the whole history: the next version depends on every commit since the last tag
token: ${{ secrets.FORGEJO_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Release
env:
GITEA_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
GITEA_URL: https://git.kmalloc.org
GIT_AUTHOR_NAME: sonda-release
GIT_AUTHOR_EMAIL: squid@kmalloc.org
GIT_COMMITTER_NAME: sonda-release
GIT_COMMITTER_EMAIL: squid@kmalloc.org
run: >
npx --yes
-p semantic-release@25
-p @semantic-release/commit-analyzer@13.0.1
-p @semantic-release/release-notes-generator@14.1.1
-p @semantic-release/changelog@7.0.0
-p @semantic-release/git@11.0.1
-p conventional-changelog-conventionalcommits@8.0.0
-p @saithodev/semantic-release-gitea@2.1.0
semantic-release
- name: Which version was made, if any
id: version
run: |
# The tag of a release points at the commit the release made, which is where the checkout now is.
tag="$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)"
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
echo "released: ${tag:-nothing}"
# The Alpine of the arm64 image, by digest: kaniko, which has no emulation here, takes the base of every stage for the
# platform of the runner, so the last stage is told which one to use.
base:
needs: release
if: ${{ needs.release.outputs.version != '' }}
runs-on: docker
container:
image: gcr.io/go-containerregistry/crane:debug
outputs:
arm64: ${{ steps.digest.outputs.arm64 }}
steps:
- id: digest
run: echo "arm64=alpine@$(crane digest --platform linux/arm64 alpine:3.22)" >> "$GITHUB_OUTPUT"
# One image for each architecture. The Go program crosses to the other one with no emulation, and the last stage of the
# Dockerfile runs no command (see the Dockerfile).
image:
needs: [release, base]
if: ${{ needs.release.outputs.version != '' }}
runs-on: docker
strategy:
matrix:
arch: [amd64, arm64]
container:
image: gcr.io/kaniko-project/executor:v1.23.2-debug
steps:
- name: Build the image from the tag and push it as X.Y.Z-ARCH
env:
VERSION: ${{ needs.release.outputs.version }}
ARCH: ${{ matrix.arch }}
ARM64_BASE: ${{ needs.base.outputs.arm64 }}
REGISTRY_USER: squid
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
run: |
set -eu
mkdir -p /kaniko/.docker
auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')"
printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json
base=alpine:3.22
if [ "$ARCH" = arm64 ]; then base="$ARM64_BASE"; fi
/kaniko/executor \
--dockerfile Dockerfile \
--context "git://git.kmalloc.org/squid/sonda.git#refs/tags/v${VERSION}" \
--build-arg "VERSION=${VERSION}" \
--build-arg "SONDA_ARCH=${ARCH}" \
--build-arg "RUNTIME_BASE=${base}" \
--label "org.opencontainers.image.version=${VERSION}" \
--destination "git.kmalloc.org/squid/sonda:${VERSION}-${ARCH}" \
--verbosity info
# The tags that people use (X.Y.Z, X.Y, latest) point at a list of the two images, so that each machine takes its own.
manifest:
needs: [release, image]
if: ${{ needs.release.outputs.version != '' }}
runs-on: docker
container:
image: gcr.io/go-containerregistry/crane:debug
steps:
- name: Join the images under X.Y.Z, X.Y and latest
env:
VERSION: ${{ needs.release.outputs.version }}
REGISTRY_USER: squid
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
run: |
set -eu
image=git.kmalloc.org/squid/sonda
crane auth login git.kmalloc.org -u "$REGISTRY_USER" -p "$REGISTRY_TOKEN"
# Kaniko writes the architecture of the runner in both images: say the right one for each.
for arch in amd64 arm64; do
crane mutate "${image}:${VERSION}-${arch}" --set-platform "linux/${arch}" --tag "${image}:${VERSION}-${arch}"
done
crane index append \
--tag "${image}:${VERSION}" \
--manifest "${image}:${VERSION}-amd64" \
--manifest "${image}:${VERSION}-arm64"
crane tag "${image}:${VERSION}" "${VERSION%.*}"
crane tag "${image}:${VERSION}" latest