🏡 index : quine-global/quine-linux.git

name: Image, disk image and live ISO

# Builds the quine-linux image on our Aurora build (published by
# quine-global/aurora's workflow to this forge's registry), pushes it to
# forge.in.quineglobal.com/quine-global/quine-linux (`latest`,
# `<date>`, the commit; installed systems pull it as
# registry.quineglobal.com/quine-linux, a pull-only name for it), then
# builds a disk image (qcow2) and the live ISO
# (which is also the installer, as Aurora's) from it and uploads them to MinIO
# as <bucket>/disk/latest/disk.qcow2 and <bucket>/live/latest/live.iso
# (aarch64: disk-aarch64.qcow2, live-aarch64.iso), replacing the last build's.
#
# Once per architecture, each natively on its own runner (host mode, root
# podman; petersweb-infra, nixos/forgejo-runner.nix): x86_64 on
# runner-x86-linux, from aurora:stable, and aarch64 on runner-arm64-linux (a
# Tart VM on the Mac mini), from aurora:stable-arm64. bootc-image-builder
# needs a host of the image's architecture with root podman and ~30 GB of
# free disk. aarch64's image is quine-linux:latest-arm64 (its other tags end
# in -arm64 too), and installs follow that; its files end in -aarch64.
#
# A tag `v*` also publishes a release: each architecture's files go to
# MinIO's public <bucket>/releases/<tag>/, and then the release job writes
# one SHA256SUMS for all of them and makes a Forgejo release on this repo
# that links to them
# (Forgejo's external-URL release files: the images are too big for GitHub's
# 2 GiB limit, and this keeps one copy). The website lists these releases.
#
# Upstream images (Fedora's, bootc-image-builder) are vendored into
# forge.in.quineglobal.com/quine-global/mirror/ first, and pulled
# from there (.forgejo/vendor-images.sh).
#
# Secrets: REGISTRY_TOKEN (a Forgejo token with package write access),
# MINIO_SECRET_KEY. MINIO_ACCESS_KEY is a variable or a secret (it's just the
# MinIO user's name, `quine-linux`).
# Variables (optional): REGISTRY_USER (the token's owner; default: the
# actor), MINIO_ENDPOINT (default https://s3.quineglobal.com), MINIO_BUCKET
# (default quine-linux).

# Also daily, two hours after quine-global/aurora's daily build, so the
# image and ISO pick up its result. Forgejo reads the schedule from pushes to
# main, but not from `[skip ci]` ones: after changing it, push without.
on:
  push:
    branches: [main]
    tags: ['v*']
  schedule:
    - cron: '0 7 * * *'
  workflow_dispatch:

concurrency:
  group: iso-${{ github.ref }}
  cancel-in-progress: true

env:
  REGISTRY: forge.in.quineglobal.com
  IMAGE: forge.in.quineglobal.com/quine-global/quine-linux
  MINIO_ENDPOINT: ${{ vars.MINIO_ENDPOINT || 'https://s3.quineglobal.com' }}
  MINIO_BUCKET: ${{ vars.MINIO_BUCKET || 'quine-linux' }}
  # rclone's remote `store:`, all from the environment (no rclone.conf); each
  # step that uses it adds RCLONE_CONFIG_STORE_ACCESS_KEY_ID/_SECRET_ACCESS_KEY.
  # rclone, not mc: MinIO abandoned mc, and nixpkgs marks it insecure.
  RCLONE_CONFIG_STORE_TYPE: s3
  RCLONE_CONFIG_STORE_PROVIDER: Minio
  RCLONE_CONFIG_STORE_ENDPOINT: ${{ vars.MINIO_ENDPOINT || 'https://s3.quineglobal.com' }}

jobs:
  iso:
    strategy:
      # One architecture failing doesn't stop the other.
      fail-fast: false
      matrix:
        include:
          - arch: amd64
            runner: runner-x86-linux
            platform: linux/amd64
            file-arch: x86_64
            # Appended to the image's tags, and to the latest/ files' names.
            tag-suffix: ''
            latest-suffix: ''
          - arch: arm64
            runner: runner-arm64-linux
            platform: linux/arm64
            file-arch: aarch64
            tag-suffix: -arm64
            latest-suffix: -aarch64
    runs-on: ${{ matrix.runner }}
    timeout-minutes: 300
    env:
      BASE_IMAGE: forge.in.quineglobal.com/quine-global/aurora:stable${{ matrix.tag-suffix }}
      # What installs of this architecture follow for updates (Taskfile.yml).
      UPDATE_IMAGE: registry.quineglobal.com/quine-linux:latest${{ matrix.tag-suffix }}
      # The tasks' architecture settings (Taskfile.yml).
      ARCH_VARS: PLATFORM=${{ matrix.platform }} TARGET_ARCH=${{ matrix.arch }}
      # "Sign the image"'s key, here and not in that step's env: the runner
      # (act_runner 1.0.3, printStepEnvBlock) prints each step's own env:
      # values in its log, and this multi-line secret slipped past the
      # masking, so the key printed in the clear in five runs (2026-11-21).
      # Job-level env is never printed. Never move it back to a step, and
      # don't print the environment (env, printenv, set -x) in this job.
      IMAGE_SIGNING_KEY: ${{ secrets.IMAGE_SIGNING_KEY }}
    steps:
      # No submodules: stage 0 (Aurora) comes from the registry now. Our pull
      # mirror of code.forgejo.org/actions/checkout.
      - uses: https://forge.in.quineglobal.com/quine-global/mirror-actions-checkout@v4

      - name: Install task, rclone, just, yq and cosign
        # Only what the runner doesn't already have: both runners have all
        # five from nixpkgs (petersweb-infra, nixos/forgejo-runner.nix).
        run: |
          bin="$HOME/.local/bin"
          mkdir -p "$bin"
          have() { command -v "$1" >/dev/null; }
          have task || curl -fsSL https://taskfile.dev/install.sh | sh -s -- -d -b "$bin"
          # --force: on a host-mode runner $HOME outlives the job.
          have just || curl -fsSL https://just.systems/install.sh | bash -s -- --force --to "$bin"
          have yq || { curl -fsSL -o "$bin/yq" https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 && chmod +x "$bin/yq"; }
          have cosign || { curl -fsSL -o "$bin/cosign" https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 && chmod +x "$bin/cosign"; }
          have rclone || { curl -fsSL -o /tmp/rclone.zip https://downloads.rclone.org/rclone-current-linux-amd64.zip && unzip -joq /tmp/rclone.zip '*/rclone' -d "$bin" && rm /tmp/rclone.zip; }
          echo "$bin" >> "$GITHUB_PATH"
          for t in task just yq cosign rclone; do printf '%s: ' "$t"; command -v "$t"; done

      - name: Remove what failed builds left behind
        # A build that fails or is cancelled can leave its build containers
        # (`podman ps --external`), and they keep their images, ~11 GB each,
        # from every prune (run 48 ran out of disk). One job per runner
        # (petersweb-infra, nixos/forgejo-runner.nix), so none is ours. And a
        # cancelled run skips the cleanup at the end: its images, 25 GB on
        # arm64, left too little of the 50 GB disk for bootc-image-builder
        # (run 50, attempt 2). Every job ends with prune -af anyway.
        #
        # And the temp files: podman stages a whole image in /var/tmp to
        # commit a build step, and a build killed partway leaves its
        # container_images_storage* behind. On arm64 /var/tmp is the 54 GB
        # root disk, not the 49 GB containers disk: 14 GB of leftovers there
        # and the live ISO's commit ran out of space (run 60). Staging on the
        # containers disk instead (TMPDIR) filled that one, which also holds
        # the images (run 61). So the staging stays on /var/tmp, without
        # leftovers.
        run: |
          ids=$(podman ps -aq --external)
          [ -z "$ids" ] || { echo "removing leftover build containers: $ids"; podman rm -f $ids || true; }
          podman image prune -af >/dev/null || true
          rm -rf /var/tmp/container_images_storage* /var/lib/containers/tmp
          df -h /var/lib/containers/storage / | tail -2

      - name: Log in to the registry
        env:
          REGISTRY_USER: ${{ vars.REGISTRY_USER || github.actor }}
          REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
        run: printf %s "$REGISTRY_TOKEN" | podman login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin

      - name: Vendor upstream images
        # Into the forge's mirror/ (.forgejo/vendor-images.sh), which the
        # pulls below then read: bootc-image-builder (Taskfile.yml) and what
        # Titanoboa's ISO step runs in (Taskfile.yml, FEDORA_IMAGE).
        run: |
          .forgejo/vendor-images.sh \
            quay.io/fedora/fedora:latest \
            ghcr.io/osbuild/bootc-image-builder:latest

      - name: Pull base images
        # Before the builds, with retries: quay.io's CDN cuts off multi-GB
        # layers now and then ("unexpected EOF"), and a pull inside
        # `buildah build` gives up after one reconnect. Already-pulled
        # images cost only a manifest check. The upstream ones come from the
        # forge's mirror/ when it has them (runner-x86-linux's
        # registries.conf).
        run: |
          for img in \
            "$BASE_IMAGE" \
            quay.io/fedora/fedora:latest \
            ghcr.io/osbuild/bootc-image-builder:latest; do
            start=$SECONDS
            for try in 1 2 3 4 5; do
              echo "== pulling $img (attempt $try/5)"
              # A pull can also stall without failing (run 64: three hours on
              # aurora:stable-arm64 from the forge). 60 minutes: the arm64
              # runner reaches the forge through a Tailscale relay, and its
              # 10 GB Aurora pull took 29.5 minutes (run 71).
              timeout -k 60 60m podman pull --retry 5 --retry-delay 20s "$img" && break
              [ "$try" != 5 ] || { echo "== giving up on $img after 5 attempts"; exit 1; }
              echo "== pull of $img failed, retrying in 30s"; sleep 30
            done
            podman image inspect --format \
              "== $img: {{.Digest}} {{.Os}}/{{.Architecture}}, {{.Size}} bytes, $((SECONDS - start))s" \
              "$img"
          done

      # The build steps retry on network errors and stalls (any fetch,
      # anywhere in the build): .forgejo/retry-on-network-error.sh.
      - name: Build image
        run: .forgejo/retry-on-network-error.sh task build-image CONTAINER_RUNTIME=podman BASE_IMAGE="$BASE_IMAGE" $ARCH_VARS

      - name: Push image
        env:
          SUFFIX: ${{ matrix.tag-suffix }}
        run: |
          tags=(latest "$(date -u +%Y%m%d)" "${GITHUB_SHA::12}")
          [ "$GITHUB_REF_TYPE" != tag ] || tags+=("$GITHUB_REF_NAME")
          for t in "${tags[@]}"; do
            podman tag localhost/quine-linux "$IMAGE:$t$SUFFIX"
            podman push --retry 5 "$IMAGE:$t$SUFFIX"
          done

      - name: Sign the image
        # Installed systems check each update's GPG signature (README "Signed
        # images"): by the "Quine Global Packages" key, as a "lookaside" file
        # per image digest on MinIO (public: sigstore/), which
        # overlay/etc/containers/registries.d/quine-linux.yaml points them at.
        # Secrets: IMAGE_SIGNING_KEY (the key, armored; in the job's env, see
        # there), and IMAGE_SIGNING_PASSPHRASE if it has one (petersweb-infra
        # docs/TOKENS.md).
        env:
          SUFFIX: ${{ matrix.tag-suffix }}
          IMAGE_SIGNING_PASSPHRASE: ${{ secrets.IMAGE_SIGNING_PASSPHRASE }}
          RCLONE_CONFIG_STORE_ACCESS_KEY_ID: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
          RCLONE_CONFIG_STORE_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }}
        run: |
          set -euo pipefail
          : "${IMAGE_SIGNING_KEY:?IMAGE_SIGNING_KEY secret not set}"
          # Masking matches a secret's whole value within one log line, so
          # a multi-line key printed line by line would slip through: mask
          # each line of it too (each ::add-mask:: line logs as "***").
          while IFS= read -r line; do
            [ "${#line}" -lt 16 ] || printf '::add-mask::%s\n' "$line"
          done <<<"$IMAGE_SIGNING_KEY"
          # gpg (skopeo signs through it): the runners' own once they have it
          # (petersweb-infra forgejo-runner.nix), Nix's until then (by its full path:
          # the job's PATH has the runner's tools only, not the system's).
          # gnupg^out: plain nixpkgs#gnupg prints its man output's path too,
          # and the two lines made one broken PATH entry (2026-11-21).
          command -v gpg >/dev/null ||
            export PATH="$(/run/current-system/sw/bin/nix --extra-experimental-features 'nix-command flakes' build --no-link --print-out-paths 'nixpkgs#gnupg^out')/bin:$PATH"
          gpg --version | head -1
          export GNUPGHOME=$(mktemp -d); work=$(mktemp -d)
          trap 'rm -rf "$GNUPGHOME" "$work"' EXIT
          printf '%s\n' "$IMAGE_SIGNING_KEY" | gpg --batch --quiet --import
          fpr=$(gpg --batch --list-secret-keys --with-colons | awk -F: '$1 == "fpr" {print $10; exit}')
          public="${UPDATE_IMAGE%:*}"
          skopeo --registries-conf /dev/null inspect --raw "docker://$IMAGE:${GITHUB_SHA::12}$SUFFIX" >"$work/manifest.json"
          digest="sha256:$(sha256sum "$work/manifest.json" | cut -d' ' -f1)"
          pass=()
          if [ -n "${IMAGE_SIGNING_PASSPHRASE:-}" ]; then
            printf '%s' "$IMAGE_SIGNING_PASSPHRASE" >"$work/passphrase"
            pass=(--passphrase-file "$work/passphrase")
          fi
          skopeo standalone-sign "${pass[@]}" -o "$work/signature-1" "$work/manifest.json" "$public:latest$SUFFIX" "$fpr"
          skopeo standalone-verify "$work/manifest.json" "$public:latest$SUFFIX" "$fpr" "$work/signature-1"
          rclone copyto "$work/signature-1" "store:${MINIO_BUCKET}/sigstore/quine-linux@${digest/:/=}/signature-1"
          echo "signed $digest with $fpr"

      - name: Check the public name serves this image
        # Installed systems update from UPDATE_IMAGE's name
        # (registry.quineglobal.com, a proxy on mainframe, petersweb-infra
        # edge.nix), not from IMAGE. Until 2026-11-21 that proxy served an old
        # copy (quine-global-labs/quine-linux) and every machine was stuck on
        # 2026-11-13's image while these pushes went fine: so this compares
        # what the public name serves for this commit's tag with what was
        # just pushed, and fails the build if they differ.
        env:
          SUFFIX: ${{ matrix.tag-suffix }}
        run: |
          public="${UPDATE_IMAGE%:*}"
          tag="${GITHUB_SHA::12}$SUFFIX"
          digest() { skopeo --registries-conf /dev/null inspect --format '{{.Digest}}' "docker://$1"; }
          pushed=$(digest "$IMAGE:$tag")
          for try in 1 2 3 4 5; do
            served=$(digest "$public:$tag" 2>&1) && [ "$served" = "$pushed" ] && break
            echo "== try $try: $public:$tag gives '$served', pushed $pushed"; sleep 20
          done
          echo "pushed $IMAGE:$tag = $pushed"
          echo "public $public:$tag = $served"
          [ "$served" = "$pushed" ] || { echo "::error::$public doesn't serve what was pushed: installed systems won't get this build (petersweb-infra edge.nix, registry.quineglobal.com)"; exit 1; }
          # And its signature, where installed systems look for it.
          sig="https://s3.quineglobal.com/quine-linux/sigstore/quine-linux@${pushed/:/=}/signature-1"
          curl -fsS -o /dev/null "$sig" || { echo "::error::no signature at $sig: installed systems will refuse this build"; exit 1; }
          echo "signature $sig"

      - name: Build disk image
        run: .forgejo/retry-on-network-error.sh task build-disk-image CONTAINER_RUNTIME=podman BASE_IMAGE="$BASE_IMAGE" UPDATE_IMAGE="$UPDATE_IMAGE" $ARCH_VARS

      - name: Build live ISO
        # Installs UPDATE_IMAGE (quine-linux:latest, or latest-arm64), which
        # "Push image" just updated. Pulled into the ISO straight from the
        # forge, under this commit's tag (PAYLOAD_PULL): through the
        # registry.quineglobal.com proxy (Hetzner and back) it ran at ~1 MB/s
        # against ~100 MB/s direct, and took most of this step.
        env:
          SUFFIX: ${{ matrix.tag-suffix }}
        run: >-
          .forgejo/retry-on-network-error.sh task build-live-iso CONTAINER_RUNTIME=podman BASE_IMAGE="$BASE_IMAGE"
          UPDATE_IMAGE="$UPDATE_IMAGE" PAYLOAD_PULL="$IMAGE:${GITHUB_SHA::12}$SUFFIX" $ARCH_VARS

      - name: Upload to MinIO
        env:
          RCLONE_CONFIG_STORE_ACCESS_KEY_ID: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
          RCLONE_CONFIG_STORE_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }}
          SUFFIX: ${{ matrix.latest-suffix }}
        run: |
          rclone mkdir "store:${MINIO_BUCKET}"
          # Latest only: each file is 5-8 GB, and the forge VM's disk is
          # shared. Tagged releases keep their own copies (releases/<tag>/).
          ls -lh output/qcow2/disk.qcow2
          rclone copyto output/qcow2/disk.qcow2 "store:${MINIO_BUCKET}/disk/latest/disk$SUFFIX.qcow2"
          ls -lh output/live/Quine-Linux-Live.iso
          rclone copyto output/live/Quine-Linux-Live.iso "store:${MINIO_BUCKET}/live/latest/live$SUFFIX.iso"

      - name: Upload the release's files
        # The release job below lists them in the release, with one
        # SHA256SUMS for both architectures from the SHA256SUMS.<arch> parts.
        if: github.ref_type == 'tag'
        env:
          RCLONE_CONFIG_STORE_ACCESS_KEY_ID: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
          RCLONE_CONFIG_STORE_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }}
          ARCH: ${{ matrix.file-arch }}
        run: |
          tag=$GITHUB_REF_NAME
          mkdir -p release
          ln -f output/qcow2/disk.qcow2 "release/quine-linux-$tag-$ARCH.qcow2"
          ln -f output/live/Quine-Linux-Live.iso "release/quine-linux-$tag-live-$ARCH.iso"
          (cd release && sha256sum -- * > "SHA256SUMS.$ARCH")
          cat "release/SHA256SUMS.$ARCH"

          rclone copy release/ "store:${MINIO_BUCKET}/releases/$tag/"

      - name: Clean up
        if: always()
        run: |
          rm -rf output release
          podman logout "$REGISTRY" || true
          # Each build leaves ~100 GB of images and stages; the runner's daily
          # prune keeps a day's worth, and a second build that day filled the
          # disk. The next build pulls its bases from the forge again.
          ids=$(podman ps -aq --external)
          [ -z "$ids" ] || podman rm -f $ids || true
          podman image prune -af >/dev/null || true
          rm -rf /var/tmp/container_images_storage*

  release:
    # After both architectures, even if one failed: the release gets
    # whatever was built (SHA256SUMS says which).
    needs: iso
    if: always() && github.ref_type == 'tag'
    runs-on: runner-x86-linux
    steps:
      - name: Publish the release
        env:
          RCLONE_CONFIG_STORE_ACCESS_KEY_ID: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
          RCLONE_CONFIG_STORE_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }}
          TOKEN: ${{ github.token }}
        run: |
          tag=$GITHUB_REF_NAME
          dir="store:${MINIO_BUCKET}/releases/$tag"
          sums=$(mktemp)
          for part in $(rclone lsf --files-only --include 'SHA256SUMS.*' "$dir/" | sort); do
            rclone cat "$dir/$part" >>"$sums"
          done
          [ -s "$sums" ] || { echo "::error::no architecture uploaded its files"; exit 1; }
          cat "$sums"
          rclone copyto "$sums" "$dir/SHA256SUMS"
          files=(SHA256SUMS)
          mapfile -t -O 1 files < <(awk '{print $2}' "$sums")

          api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases"
          auth=(-H "Authorization: token $TOKEN")
          # v1.2.3-alpha.1 and the like: a pre-release.
          pre=false; [[ $tag != *-* ]] || pre=true
          id=$(jq -n --arg tag "$tag" --arg image "$IMAGE:$tag" --argjson pre "$pre" '{tag_name: $tag, name: $tag,
                 prerelease: $pre, body: "Container images: `\($image)` (x86_64), `\($image)-arm64` (aarch64).\nFiles are checked by SHA256SUMS."}' |
               curl -fsS "${auth[@]}" -H 'Content-Type: application/json' -d @- "$api" | jq -er .id)
          for name in "${files[@]}"; do
            curl -fsS "${auth[@]}" -F "external_url=${MINIO_ENDPOINT}/${MINIO_BUCKET}/releases/$tag/$name" \
              "$api/$id/assets?name=$name" >/dev/null
            echo "linked $name"
          done
          echo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$tag"