sector-f-linux

Sector F Linux
git clone https://git.sectorflabs.com/sector-f-linux.git
Log | Files | Refs | README | LICENSE

build.sh (4942B)


      1 #!/usr/bin/env bash
      2 # Builds the live ISO (ADR-0014, ADR-0010): the Containerfile's `live` stage, turned into an ISO by
      3 # image-builder's bootc-generic-iso. The ISO is built inside the test VM (vm/), not on this host:
      4 # image-builder runs osbuild in a bubblewrap sandbox, which a host with AppArmor (Ubuntu) confines
      5 # so that it cannot mount the image ("permission denied"; seen in the kernel log as
      6 # apparmor="DENIED" profile="unpriv_bwrap"). The VM is Fedora with SELinux, as the tool expects
      7 # (and the container runs with its own SELinux label: image-builder labels its store itself).
      8 # The VM's second disk, formatted on first use, holds the container storage and the work.
      9 #
     10 #   linux/live/build.sh
     11 #
     12 # The ISO lands in linux/out/iso/. It carries the published image (the real one, no test login) as
     13 # the offline install payload (ADR-0010). The payload and TARGET_IMGREF
     14 # (what installed machines follow for updates) are both the published name,
     15 # ghcr.io/sector-f-labs/sector-f-linux:latest, and the VM pulls it, so `make publish` comes first
     16 # and the ISO carries exactly what was published (the same digest, which the updater compares).
     17 # LIVE_DEBUG=1 (make iso DEBUG=1) lets root log in over SSH with the test rig's key, for driving
     18 # the ISO in QEMU; an ISO made without it has no SSH access.
     19 set -euo pipefail
     20 
     21 source "$(dirname "$0")/../vm/common.sh"
     22 VM="$ROOT/vm/vm.sh"
     23 OUT="$ROOT/out/iso"
     24 FEDORA=quay.io/fedora/fedora:45
     25 say() { printf '==> %s\n' "$*"; }
     26 
     27 "$ROOT/installer-build.sh"
     28 
     29 say "building the live image"
     30 PAYLOAD=${PAYLOAD:-$VM_IMAGE}
     31 TARGET_IMGREF=${TARGET_IMGREF:-$VM_IMAGE}
     32 debug_key=""
     33 [[ -z "${LIVE_DEBUG:-}" ]] || debug_key=$(cat "$ROOT/out/id_ed25519.pub")
     34 docker build -q --target live -t sectorf-live-installer -f "$ROOT/Containerfile" \
     35   --build-arg PAYLOAD_REF="$PAYLOAD" --build-arg TARGET_IMGREF="$TARGET_IMGREF" --build-arg DEBUG_SSH_KEY="$debug_key" "$ROOT" >/dev/null
     36 
     37 say "the build VM"
     38 # Cleaning up in the block below (no apostrophes in it: it is one single-quoted string): each run
     39 # sends or pulls what it needs again, so what earlier runs left (old payloads are several GB each)
     40 # only fills the disk. Containers a stopped run left behind hold their images, so they go first.
     41 # The osbuild cache is cleared when less than 30 GB is free.
     42 pid="$ROOT/out/qemu.pid"
     43 if [[ -f "$pid" ]] && kill -0 "$(cat "$pid")" 2>/dev/null; then :; else "$VM" start; "$VM" wait; fi
     44 "$VM" ssh '
     45   set -e
     46   mkdir -p /var/builder
     47   mountpoint -q /var/builder || {
     48     dev=/dev/disk/by-id/virtio-patina-data
     49     blkid "$dev" >/dev/null 2>&1 || mkfs.ext4 -q -L builder "$dev"
     50     mount "$dev" /var/builder
     51   }
     52   mkdir -p /var/builder/containers /var/builder/out
     53   mountpoint -q /var/lib/containers || mount --bind /var/builder/containers /var/lib/containers
     54   podman rm -af -t 0 >/dev/null 2>&1 || true
     55   podman rmi -af >/dev/null 2>&1 || true
     56   [ "$(findmnt -b -n -o AVAIL /var/builder)" -ge 32212254720 ] || rm -rf /var/builder/cache/*
     57   df -h /var/builder | tail -1'
     58 
     59 say "sending the live image to the VM"
     60 docker save sectorf-live-installer | "$VM" ssh 'podman load -q >/dev/null && podman tag docker.io/library/sectorf-live-installer:latest localhost/sectorf-live-installer:latest'
     61 
     62 # The payload is pulled from the registry, not sent from Docker: docker save and podman load rewrite
     63 # the image's manifest, so its digest would differ from the published one, and a machine installed
     64 # from the ISO would be told an update was waiting for the build it already runs. A pull keeps the
     65 # manifest as published. So publish first (make build, make publish, make iso).
     66 say "pulling the payload $PAYLOAD into the VM"
     67 "$VM" ssh "podman pull -q $PAYLOAD >/dev/null && df -h /var/builder | tail -1"
     68 # The ISO is named after the date and the first 8 digits of the payload's digest, so a file says
     69 # which published image it carries.
     70 digest=$("$VM" ssh "podman image inspect $PAYLOAD --format '{{.Digest}}'")
     71 digest=${digest#sha256:}
     72 [[ ${#digest} -ge 8 ]] || { echo "error: no digest for $PAYLOAD" >&2; exit 1; }
     73 NAME="sector-f-linux-$(date -u +%Y%m%d)-${digest:0:8}.iso"
     74 
     75 say "building the ISO (in the VM)"
     76 "$VM" ssh "
     77   rm -rf /var/builder/out/*
     78   mkdir -p /var/builder/cache
     79   podman run --rm --privileged \
     80     -v /var/lib/containers/storage:/var/lib/containers/storage -v /var/builder/cache:/var/cache/image-builder \
     81     -v /var/builder/out:/output $FEDORA sh -c '
     82       dnf -y -q install image-builder podman >/dev/null 2>&1
     83       image-builder build --output-dir /output --bootc-ref localhost/sectorf-live-installer \
     84         --bootc-default-fs btrfs --bootc-installer-payload-ref $PAYLOAD bootc-generic-iso' 2>&1 | tail -25
     85   find /var/builder/out -name '*.iso' -exec ls -lh {} \;"
     86 
     87 say "copying the ISO out"
     88 mkdir -p "$OUT"
     89 iso=$("$VM" ssh "find /var/builder/out -name '*.iso' | head -1")
     90 [[ -n "$iso" ]] || { echo "error: no ISO was made" >&2; exit 1; }
     91 "$VM" ssh "cat '$iso'" > "$OUT/$NAME"
     92 ls -lh "$OUT/$NAME"