: nply/foundationpkgs

commit 0ec84fd2393f2729f6329b0c6fa4dacabf7c6e8d
parent 4e13e009252dd8fbd772e9b264a55504eeeb9a90
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Thu, 29 Oct 2026 23:01:43 +0530

Add manifest-driven Debian CI host preparation
5 files changed, 208 insertions(+), 1 deletion(-)
A
.config/ci-packages.list
|
20
++++++++++++++++++++
M
AGENTS.md
|
3
+++
M
docs/ci.md
|
49
++++++++++++++++++++++++++++++++++++++++++++++++-
A
scripts/prepare-ci-host.sh
|
71
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A
tests/prepare-ci-host.sh
|
66
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/.config/ci-packages.list b/.config/ci-packages.list
@@ -0,0 +1,20 @@
+# Debian 13 (trixie), amd64 build-host packages.
+# apt NAME: from the host's configured signed Debian repositories.
+# deb PATH SHA256: relative to a supplied bootstrap-binaries checkout/snapshot.
+# Custom artifacts: bootstrap-binaries d82b595d7822e05b2819425862084fd0153284b9.
+# Runtime tools (BusyBox, fakeroot, scanelf, getcap, bc, etc.) are dependencies
+# of the custom abuild .deb; APT resolves them rather than duplicating that list.
+apt build-essential
+apt ca-certificates
+apt git
+apt curl
+apt patch
+apt pkgconf
+apt rsync
+apt bmake
+apt scdoc
+apt libssl-dev
+apt zlib1g-dev
+apt libzstd-dev
+deb packages/debian/trixie/amd64/apk-tools_2.14.12-1_amd64.deb 8580d05d05148097eafcca3bc03141ba231ee2d4b301edd899a6d59311716355
+deb packages/debian/trixie/amd64/abuild_3.18.0~rc5+git20260823-1_amd64.deb 50867af7151b9f39d4bb242649f27c81c6eaf2a15f38a6d05fd2e93f6c62c2ea
diff --git a/AGENTS.md b/AGENTS.md
@@ -40,6 +40,9 @@
   extract into a temporary directory, then install selected files. Never extract
   CI tarballs directly over `/`; their parent metadata belongs to the builder.
 
+For CI host provisioning, maintain `.config/ci-packages.list` and use
+[the administrator preparation workflow](docs/ci.md#prepare-the-debian-ci-host).
+
 ## Builder or CI changes
 
 Read `CONTEXT.md` before changing recipe layout, naming, artifact paths, or CI
diff --git a/docs/ci.md b/docs/ci.md
@@ -12,7 +12,7 @@ checks and offline backend/publication/staged-install regressions. Linux builds
 default to APK and an Alpine-musl target; `FPKGS_FORMAT=tar.gz` explicitly retains
 legacy output. `FPKGS_TARGETS` selects targets independently. Before deploying
 this backend to CI, provision native abuild/apk-tools, an unprivileged build user,
-signing configuration and target dependencies. This code does not provision the
+signing configuration and target dependencies. Package jobs do not provision the
 live host or rewrite existing recipes; keep legacy CI explicitly on tar.gz until
 its packages and toolchain have been migrated.
 Package builds are sequential;

@@ -20,6 +20,53 @@ your package may be queued behind others. One package can be published even if
 other packages fail and the overall job fails. Verify the requested package,
 target, and revision rather than inferring availability from overall job state.
 
+## Prepare the Debian CI host
+
+The maintained host package list is [`.config/ci-packages.list`](../.config/ci-packages.list).
+It covers the **Debian 13 amd64 build host**, not the Alpine target filesystem.
+Ordinary packages come from the machine's configured signed Debian repositories;
+custom packages come from a supplied `bootstrap-binaries` checkout or snapshot.
+Each custom `.deb` is pinned by its versioned relative path and SHA-256 in this
+manifest. Its source repository revision is recorded in the manifest comments.
+Debian packages track the configured repositories rather than a frozen snapshot.
+
+```sh
+# Portable, read-only validation: show the list and verify custom package bytes.
+scripts/prepare-ci-host.sh --plan ../bootstrap-binaries
+
+# On Debian 13 amd64: ask APT to resolve the combined transaction, without changes.
+scripts/prepare-ci-host.sh --simulate ../bootstrap-binaries
+
+# Explicit administrator action, after reviewing the simulation:
+sudo scripts/prepare-ci-host.sh --install /absolute/path/to/bootstrap-binaries
+```
+
+The default action is `--plan`. Use a trusted foundationpkgs checkout: its script
+and manifest authorize privileged installation. No remote is fetched implicitly;
+provide the approved bootstrap snapshot (the initial artifacts are from
+`d82b595d7822e05b2819425862084fd0153284b9`). The bootstrap repository's own
+checksum file is not substituted for the pins maintained here.
+
+Both custom packages and all manifest entries are validated before invoking APT.
+Verified `.deb` files are copied to temporary staging, so APT can read them even
+when the source checkout is private. Their runtime dependencies are resolved
+from the `.deb` metadata rather than repeated in this list. A single APT install
+transaction handles Debian and custom packages together, with **no removals**,
+no recommended extras, and normal interactive confirmation for `--install`.
+APT can still upgrade installed packages/dependencies; review the entire plan.
+Repeated installation uses APT's existing package state. There is no extraction
+over `/`, automatic `apt-get update`, or `autoremove`. Update APT indexes
+separately when required before simulating/installing.
+
+This command is not called by the Jobfile or ordinary package builds. It does
+not create users, signing keys, credentials, target APK databases or cross
+compilers, migrate recipes, or enable the APK CI backend. Configure those
+separately before cutting over live CI. Keep private signing keys outside Git.
+
+To change a custom version, update its path and SHA-256 together in the manifest,
+then rerun validation and simulation. The offline check is
+`sh tests/prepare-ci-host.sh`; it needs neither root nor bootstrap artifacts.
+
 ## Jobfile selection
 
 The deployed runner selects the first applicable source:
diff --git a/scripts/prepare-ci-host.sh b/scripts/prepare-ci-host.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+# Explicit administrator action, never called from package builds or Jobfile.
+set -eu
+root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
+die() { printf 'prepare-ci-host: %s\n' "$*" >&2; exit 1; }
+mode=${1:---plan}
+case "$mode" in
+--plan | --simulate | --install) [ "$#" -eq 0 ] || shift ;;
+*) die 'usage: prepare-ci-host.sh [--plan|--simulate|--install] [BOOTSTRAP_DIR]' ;;
+esac
+[ "$#" -le 1 ] || die 'expected at most one bootstrap-binaries directory'
+bootstrap=${1:-$root/../bootstrap-binaries}
+[ -d "$bootstrap" ] || die "bootstrap-binaries directory not found: $bootstrap"
+bootstrap=$(CDPATH= cd -- "$bootstrap" && pwd)
+if [ "$mode" != --plan ]; then
+	[ -r /etc/os-release ] || die 'Debian 13 amd64 is required'
+	(. /etc/os-release; [ "$ID" = debian ] && [ "$VERSION_ID" = 13 ]) || die 'Debian 13 is required'
+	[ "$(dpkg --print-architecture)" = amd64 ] || die 'amd64 is required'
+	[ "$mode" != --install ] || [ "$(id -u)" -eq 0 ] || die '--install requires root'
+fi
+work=$(mktemp -d "${TMPDIR:-/tmp}/fpkgs-host.XXXXXX")
+trap 'rm -rf "$work"' EXIT
+trap 'exit 1' HUP INT TERM
+set --
+count=0
+while read -r kind item digest extra || [ -n "$kind" ]; do
+	case "$kind" in '' | \#*) continue ;; esac
+	[ -z "$extra" ] || die 'unexpected extra manifest fields'
+	case "$kind" in
+	apt)
+		case "$item" in '' | [!a-z0-9]* | *[!a-z0-9+.-]*) die "invalid Debian package name: $item" ;; esac
+		[ -z "$digest" ] || die "unexpected checksum for Debian package: $item"
+		set -- "$@" "$item"
+		printf 'apt %s\n' "$item"
+		;;
+	deb)
+		case "$item" in
+		/* | ../* | */../* | */.. | *[!a-zA-Z0-9_./+~:-]*) die "unsafe custom package path: $item" ;;
+		esac
+		case "$item" in packages/*.deb) ;; *) die "expected packages/.../*.deb: $item" ;; esac
+		[ "${#digest}" -eq 64 ] || die "invalid SHA-256 for $item"
+		case "$digest" in *[!0-9a-f]*) die "invalid SHA-256 for $item" ;; esac
+		file=$work/$(basename "$item")
+		[ ! -e "$file" ] || die "duplicate custom package filename: $item"
+		cp "$bootstrap/$item" "$file"
+		if command -v sha256sum >/dev/null 2>&1; then
+			sum=$(sha256sum "$file")
+		else
+			sum=$(shasum -a 256 "$file")
+		fi
+		[ "${sum%% *}" = "$digest" ] || die "checksum mismatch: $item"
+		chmod 0644 "$file"
+		set -- "$@" "$file"
+		printf 'deb %s %s\n' "$item" "$digest"
+		;;
+	*) die "unknown manifest entry: $kind" ;;
+	esac
+	count=$((count + 1))
+done <"$root/.config/ci-packages.list"
+[ "$count" -gt 0 ] || die 'empty package manifest'
+[ "$mode" != --plan ] || exit 0
+# APT's _apt user must be able to read these verified, non-secret staged files.
+# The source checkout may be private; APT never needs access to it.
+chmod 0755 "$work"
+if [ "$mode" = --simulate ]; then
+	export LC_ALL=C
+	apt-get --simulate --no-remove --no-install-recommends install "$@"
+else
+	# Interactive APT confirmation; no unattended -y or implicit apt-get update.
+	apt-get --no-remove --no-install-recommends install "$@"
+fi
diff --git a/tests/prepare-ci-host.sh b/tests/prepare-ci-host.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+# Offline manifest/staging validation; never installs packages or needs root.
+set -eu
+root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
+work=$(mktemp -d)
+trap 'rm -rf "$work"' EXIT
+trap 'exit 1' HUP INT TERM
+mkdir -p "$work/repo/scripts" "$work/repo/.config" "$work/bootstrap/packages" "$work/bin"
+cp "$root/scripts/prepare-ci-host.sh" "$work/repo/scripts/"
+export APT_LOG=$work/apt.log
+cat >"$work/bin/apt-get" <<'APT'
+#!/bin/sh
+printf '%s\n' "$@" >"$APT_LOG"
+exit 19
+APT
+chmod +x "$work/bin/apt-get"
+export PATH=$work/bin:$PATH
+printf 'synthetic deb\n' >"$work/bootstrap/packages/fixture.deb"
+if command -v sha256sum >/dev/null 2>&1; then
+	sum=$(sha256sum "$work/bootstrap/packages/fixture.deb")
+else
+	sum=$(shasum -a 256 "$work/bootstrap/packages/fixture.deb")
+fi
+sum=${sum%% *}
+manifest=$work/repo/.config/ci-packages.list
+cli=$work/repo/scripts/prepare-ci-host.sh
+printf '# example\n\napt build-essential\ndeb packages/fixture.deb %s\n' "$sum" >"$manifest"
+sh "$cli" --plan "$work/bootstrap" >"$work/result"
+grep -q '^apt build-essential$' "$work/result"
+grep -q "^deb packages/fixture.deb $sum$" "$work/result"
+[ ! -e "$APT_LOG" ]
+fail() {
+	if sh "$cli" --plan "$work/bootstrap" >"$work/result" 2>&1; then
+		echo 'Invalid manifest unexpectedly accepted' >&2; exit 1
+	fi
+	[ ! -e "$APT_LOG" ]
+}
+printf 'changed\n' >>"$work/bootstrap/packages/fixture.deb"
+fail
+printf 'deb packages/missing.deb %s\n' "$sum" >"$manifest"
+fail
+printf 'deb packages/../escape.deb %s\n' "$sum" >"$manifest"
+fail
+printf 'deb /tmp/escape.deb %s\n' "$sum" >"$manifest"
+fail
+printf 'deb packages/fixture.deb invalid\n' >"$manifest"
+fail
+printf 'apt --allow-unauthenticated\n' >"$manifest"
+fail
+printf 'apt git extra\n' >"$manifest"
+fail
+printf 'unknown git\n' >"$manifest"
+fail
+printf '# only a comment\n' >"$manifest"
+fail
+# Check a final record without a newline, and duplicate staging filenames.
+printf 'synthetic deb\n' >"$work/bootstrap/packages/fixture.deb"
+printf 'deb packages/fixture.deb %s' "$sum" >"$manifest"
+sh "$cli" --plan "$work/bootstrap" >"$work/result"
+printf '\ndeb packages/fixture.deb %s\n' "$sum" >>"$manifest"
+fail
+if sh "$cli" --unexpected "$work/bootstrap" >"$work/result" 2>&1; then
+	echo 'Unknown setup action unexpectedly accepted' >&2; exit 1
+fi
+[ ! -e "$APT_LOG" ]
+echo 'PASS: host manifest, pinned byte verification, invalid inputs, duplicate detection, plan never invokes APT'