feat: add matrix build

This commit is contained in:
Alpha Nerd 2026-04-04 18:46:08 +02:00
parent 403abd5357
commit d4464be581
Signed by: alpha-nerd
SSH key fingerprint: SHA256:QkkAgVoYi9TQ0UKPkiKSfnerZy2h4qhi3SVPXJmBN+M
2 changed files with 144 additions and 38 deletions

View file

@ -20,14 +20,22 @@ env:
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-semantic:
runs-on: docker
build:
runs-on: ${{ matrix.runner }}
container:
image: node:lts-bookworm
options: --privileged
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: docker-amd64
- platform: linux/arm64
runner: docker-arm64
steps:
- name: Install Docker
@ -53,9 +61,6 @@ jobs:
"https://oauth2:${{ github.token }}@bitfreedom.net/code/${{ github.repository }}.git" \
.
- name: Set up QEMU (for multi-arch builds)
uses: https://github.com/docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
with:
@ -68,29 +73,77 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push platform image
id: build
uses: https://github.com/docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
push: true
provenance: false
build-args: |
SEMANTIC_CACHE=true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }},mode=max
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: https://github.com/actions/upload-artifact@v4
with:
name: digest-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: docker-amd64
needs: build
permissions:
contents: read
packages: write
steps:
- name: Download digests
uses: https://github.com/actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digest-semantic-*
merge-multiple: true
- name: Install Docker
run: |
apt-get update -qq
apt-get install -y -qq docker.io
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
- name: Log in to Forgejo Container Registry
uses: https://github.com/docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: https://github.com/docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Versioned semantic tags on git tags (e.g. v0.7.0 → 0.7.0-semantic, 0.7-semantic)
type=semver,pattern={{version}}-semantic
type=semver,pattern={{major}}.{{minor}}-semantic
# latest-semantic only on main branch pushes
type=raw,value=latest-semantic,enable=${{ github.ref == 'refs/heads/main' }}
# SHA-tagged for traceability
type=sha,prefix=sha-,suffix=-semantic
- name: Build and push semantic Docker image
uses: https://github.com/docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
SEMANTIC_CACHE=true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic,mode=max
- name: Create and push multi-arch manifest
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)