name: Image, disk image and live ISO
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-labs/quine-linux
MINIO_ENDPOINT: ${{ vars.MINIO_ENDPOINT || 'https://s3.quineglobal.com' }}
MINIO_BUCKET: ${{ vars.MINIO_BUCKET || 'quine-linux' }}
jobs:
iso:
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: runner-x86-linux
platform: linux/amd64
file-arch: x86_64
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-labs/aurora:stable${{ matrix.tag-suffix }}
UPDATE_IMAGE: registry.quineglobal.com/quine-linux:latest${{ matrix.tag-suffix }}
ARCH_VARS: PLATFORM=${{ matrix.platform }} TARGET_ARCH=${{ matrix.arch }}
steps:
- uses: https://forge.in.quineglobal.com/quine-global-labs/mirror-actions-checkout@v4
- name: Install task, mc, just, yq and cosign
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"
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 mc || { curl -fsSL -o "$bin/mc" https://dl.min.io/client/mc/release/linux-amd64/mc && chmod +x "$bin/mc"; }
echo "$bin" >> "$GITHUB_PATH"
for t in task just yq cosign mc; do printf '%s: ' "$t"; command -v "$t"; done
- 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
run: |
.forgejo/vendor-images.sh \
quay.io/fedora/fedora:latest \
ghcr.io/osbuild/bootc-image-builder:latest
- name: Pull base images
run: |
for img in \
"$BASE_IMAGE" \
quay.io/fedora/fedora:latest \
ghcr.io/osbuild/bootc-image-builder:latest; do
for try in 1 2 3 4 5; do
podman pull --retry 5 --retry-delay 20s -q "$img" && break
[ "$try" != 5 ] || exit 1
echo "retrying $img in 30s"; sleep 30
done
done
- name: Build image
run: 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: Build disk image
run: task build-disk-image CONTAINER_RUNTIME=podman BASE_IMAGE="$BASE_IMAGE" UPDATE_IMAGE="$UPDATE_IMAGE" $ARCH_VARS
- name: Build live ISO
run: task build-live-iso CONTAINER_RUNTIME=podman BASE_IMAGE="$BASE_IMAGE" UPDATE_IMAGE="$UPDATE_IMAGE" $ARCH_VARS
- name: Upload to MinIO
env:
MINIO_ACCESS_KEY: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }}
SUFFIX: ${{ matrix.latest-suffix }}
run: |
mc alias set store "$MINIO_ENDPOINT" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY"
mc mb --ignore-existing "store/${MINIO_BUCKET}"
ls -lh output/qcow2/disk.qcow2
mc cp output/qcow2/disk.qcow2 "store/${MINIO_BUCKET}/disk/latest/disk$SUFFIX.qcow2"
ls -lh output/live/Quine-Linux-Live.iso
mc cp output/live/Quine-Linux-Live.iso "store/${MINIO_BUCKET}/live/latest/live$SUFFIX.iso"
- name: Upload the release's files
if: github.ref_type == 'tag'
env:
MINIO_ACCESS_KEY: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
MINIO_SECRET_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"
mc alias set store "$MINIO_ENDPOINT" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY"
for f in release/*; do mc cp "$f" "store/${MINIO_BUCKET}/releases/$tag/${f#release/}"; done
- name: Clean up
if: always()
run: |
rm -rf output release
podman logout "$REGISTRY" || true
podman image prune -af >/dev/null || true
release:
needs: iso
if: always() && github.ref_type == 'tag'
runs-on: runner-x86-linux
steps:
- name: Publish the release
env:
MINIO_ACCESS_KEY: ${{ vars.MINIO_ACCESS_KEY || secrets.MINIO_ACCESS_KEY }}
MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }}
TOKEN: ${{ github.token }}
run: |
tag=$GITHUB_REF_NAME
mc alias set store "$MINIO_ENDPOINT" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY"
dir="store/${MINIO_BUCKET}/releases/$tag"
sums=$(mktemp)
for part in $(mc ls --json "$dir/" | jq -r 'select(.key | startswith("SHA256SUMS.")) | .key' | sort); do
mc cat "$dir/$part" >>"$sums"
done
[ -s "$sums" ] || { echo "::error::no architecture uploaded its files"; exit 1; }
cat "$sums"
mc cp "$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")
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"