Promote v0.6.0 to production

This commit is contained in:
GPU Kitchen delivery
2026-10-16 04:56:42 +00:00
parent 9d6118e2c0
commit 07f2739a89
3 changed files with 150 additions and 83 deletions
+133 -67
View File
@@ -27,7 +27,7 @@
# --image repo.byterain.io/gpukitchen/gpukitchen-controller:vX.Y.Z
# # worker (enroll against a controller with a single-use token from its UI):
# sudo ./deployments/install/gpuk install --mode worker \
# --controller wss://controller.lan:8443 --enroll-token gk_enroll_... \
# --controller wss://controller.lan:8443 --enroll-token - \
# --cache-dir /mnt/models --binary apps/worker/target/release/gpu-kitchen-worker
#
# Control:
@@ -193,24 +193,12 @@ install_binary() { # [local-path]
echo "==> installed $BIN_DEST from $1"
elif [ -n "$GPUK_RELEASE_BASE" ]; then
command -v curl >/dev/null || die "curl is required to download the binary"
_url="$GPUK_RELEASE_BASE/$(arch_asset)"
echo "==> downloading $_url"
# Not -s: the binary is tens of MB and a silent download reads as a hang.
curl -fL --progress-bar "$_url" -o "$BIN_DEST.new" \
|| { rm -f "$BIN_DEST.new"; die "cannot download $_url"; }
# The root daemon is swapped in only once its minisign signature verifies
# against the release key pinned in this gpuk (OPS-20, INS-05).
if [ "${GPUK_CHANNEL_INSECURE:-}" = "1" ]; then
echo "WARNING: GPUK_CHANNEL_INSECURE=1 — $_url NOT verified" >&2
else
require_release_key
curl -fsSL "$_url.minisig" -o "$BIN_DEST.new.minisig" \
|| { rm -f "$BIN_DEST.new" "$BIN_DEST.new.minisig"; die "no signature at $_url.minisig — refusing an unsigned daemon binary"; }
"$MINISIGN" -Vq -m "$BIN_DEST.new" -x "$BIN_DEST.new.minisig" -P "$CHANNEL_PUBKEY" >/dev/null 2>&1 \
|| { rm -f "$BIN_DEST.new" "$BIN_DEST.new.minisig"; die "$_url: signature verification FAILED — refusing it (OPS-20)"; }
rm -f "$BIN_DEST.new.minisig"
echo "==> signature verified"
fi
# [OPS-20] A mirror changes WHERE the daemon comes from, never WHICH build: the
# signed channel names it, exactly as for `gpuk update`, and an older one is refused.
channel_fetch || die "cannot read the signed release channel at $CHANNEL_URL"
_build=$(channel_worker_build) || exit 1
refuse_daemon_downgrade "$_build"
fetch_signed_daemon "$GPUK_RELEASE_BASE/$(arch_asset)" "$_build"
chmod 0755 "$BIN_DEST.new"
check_candidate_release "$BIN_DEST.new" "$BIN_DEST.new"
mv "$BIN_DEST.new" "$BIN_DEST"
@@ -755,6 +743,7 @@ cmd_install() {
if [ "$MODE" = "worker" ] && [ -n "$PROFILE" ]; then
die "--profile applies only to --mode controller; workers do not have an installation profile"
fi
if [ "$ENROLL_TOKEN" = "-" ]; then ENROLL_TOKEN=$(enroll_token_from_tty) || exit 1; fi
for _pv in "$HTTP_PORT" "$MTLS_PORT" "$INFERENCE_PORT" "$HEALTH_PORT" \
"$DATA_PORT" "$TRANSFER_PORT" "$HANDOVER_PORT"; do
@@ -999,8 +988,7 @@ cmd_install() {
if [ -n "$ENROLL_TOKEN" ]; then
[ -n "$CONTROLLER_URL" ] || die "--controller wss://<controller>:<port> is required to enroll"
echo "==> enrolling against $CONTROLLER_URL ..."
GPUK_IDENTITY_DIR="$IDENTITY_DIR" GPUK_MACHINE_ID_FILE="$MACHINE_ID_FILE" "$BIN_DEST" enroll \
--controller "$CONTROLLER_URL" --token "$ENROLL_TOKEN" \
enroll_worker "$CONTROLLER_URL" "$ENROLL_TOKEN" \
|| die "enrollment failed (bad/expired token, or controller unreachable)"
else
if [ -n "$CONTROLLER_URL" ]; then
@@ -1436,6 +1424,23 @@ restart_controller() {
# embedded pgdata — back the real database up with pg_dump/backup-compose.sh.
# The finished directory still has to be copied to encrypted off-host storage,
# next to the recovery set (OPS-04/OPS-05: ENCRYPTION_KEY above all).
# [OPS-10] The database must be at rest: only a container Docker CONFIRMS stopped, or
# confirms absent, lets a copy or a second server open pgdata. A Docker that cannot say
# (daemon down, timeout) is a refusal, never "absent".
stop_app_container() {
docker stop "$1" >/dev/null 2>&1 || true
if ! _state=$(docker inspect -f '{{.State.Status}}' "$1" 2>&1); then
case "$_state" in
*"No such object"*|*"No such container"*) return 0 ;;
esac
die "cannot read the state of $1 — refusing $2"
fi
case "$_state" in
exited|created|dead) ;;
*) die "container $1 is $_state — refusing $2" ;;
esac
}
cmd_backup() {
need_root
lifecycle_lock
@@ -1468,23 +1473,25 @@ cmd_backup() {
command -v sha256sum >/dev/null 2>&1 || die "sha256sum is required"
_out="${_out:-$_root/backups/$(date -u +%Y%m%dT%H%M%SZ)}"
[ -e "$_out" ] && die "refusing to overwrite existing $_out"
# A dangling link is something too: never write through a path someone else prepared.
if [ -e "$_out" ] || [ -L "$_out" ]; then die "refusing to overwrite existing $_out"; fi
mkdir -p "$(dirname "$_out")"
_tmp="$_out.partial"
rm -rf "$_tmp"; mkdir -p "$_tmp"
# [OPS-109] Private BEFORE the first byte: a local user who opens the archive while it is
# written keeps reading it after a later chmod. The restart gets the caller's umask back.
_umask=$(umask)
umask 077
# rm removes a planted link itself, and mkdir without -p refuses whatever reappears.
rm -rf "$_tmp"; mkdir -m 0700 "$_tmp" || die "cannot create $_tmp"
_cn=$(container_name)
echo "==> Stopping $SERVICE_NAME (its reconciler would restart the container mid-snapshot)..."
systemctl stop "$SERVICE_NAME" || die "could not stop $SERVICE_NAME"
_restart_daemon() { restart_controller 2>/dev/null || true; }
_restart_daemon() { umask "$_umask"; restart_controller 2>/dev/null || true; }
trap _restart_daemon EXIT
if [ -n "$_cn" ]; then
echo "==> Stopping $_cn (cold snapshot — OPS-10)..."
docker stop "$_cn" >/dev/null 2>&1 || true
_state=$(docker inspect -f '{{.State.Status}}' "$_cn" 2>/dev/null || echo absent)
case "$_state" in
running) die "container $_cn is still running — refusing a hot snapshot" ;;
esac
stop_app_container "$_cn" "a hot snapshot"
fi
echo "==> Snapshotting $_root/pgdata..."
@@ -1500,10 +1507,11 @@ cmd_backup() {
} > "$_tmp/backup-manifest.json"
(cd "$_tmp" && sha256sum ./* > SHA256SUMS) || die "checksums failed"
chmod 0700 "$_tmp"
mv "$_tmp" "$_out"
mv -T "$_tmp" "$_out" || die "cannot publish $_out"
echo "==> Restarting $SERVICE_NAME and the app container..."
trap - EXIT
umask "$_umask"
restart_controller || die "could not restart GPU Kitchen — run: sudo gpuk apply"
echo "backup: $_out"
if [ "$_offsite" -eq 1 ]; then
@@ -1540,6 +1548,10 @@ checksum_line() { # $1 = folder, $2 = file name
}
cmd_carry_over() {
# [OPS-109] Whatever this writes beside the copied database stays private; the
# restart gets the caller's umask back.
_umask=$(umask)
umask 077
need_root
lifecycle_lock
_archive=""
@@ -1613,19 +1625,17 @@ cmd_carry_over() {
_carry_over_cleanup() {
docker rm -f "$CARRY_OVER_CONTAINER" >/dev/null 2>&1 || true
rm -rf "$_work"
umask "$_umask"
restart_controller 2>/dev/null \
|| echo "gpuk: GPU Kitchen did not restart — run: sudo gpuk apply" >&2
}
trap _carry_over_cleanup EXIT
if [ -n "$_cn" ]; then
echo "==> Stopping $_cn..."
docker stop "$_cn" >/dev/null 2>&1 || true
case "$(docker inspect -f '{{.State.Status}}' "$_cn" 2>/dev/null || echo absent)" in
running) die "container $_cn is still running — refusing to open its database twice" ;;
esac
stop_app_container "$_cn" "to open its database twice"
fi
# Traversable, not listable: the copy's server runs as the image's postgres user.
mkdir -m 0711 "$_work"
mkdir -m 0711 "$_work" || die "cannot create $_work"
_mount=""
if [ "$_kind" = pgdata ]; then
echo "==> Unpacking the backup..."
@@ -1646,6 +1656,7 @@ cmd_carry_over() {
exit "$_rc"
fi
trap - EXIT
umask "$_umask"
rm -rf "$_work"
echo "==> Restarting $SERVICE_NAME and the app container..."
restart_controller || die "could not restart GPU Kitchen — run: sudo gpuk apply"
@@ -1849,12 +1860,43 @@ cmd_enroll() {
esac
done
[ -n "$_url" ] || die "enroll needs --controller wss://<controller>:<port>"
[ -n "$_tok" ] || die "enroll needs --token gk_enroll_..."
GPUK_IDENTITY_DIR="$IDENTITY_DIR" GPUK_MACHINE_ID_FILE="$MACHINE_ID_FILE" \
"$BIN_DEST" enroll --controller "$_url" --token "$_tok"
[ -n "$_tok" ] || die "enroll needs --token - (asked on the terminal, or read from a pipe) or --token gk_enroll_..."
if [ "$_tok" = "-" ] && [ -t 0 ]; then
_tok=$(enroll_token_from_tty) || exit 1
elif [ "$_tok" = "-" ]; then
# [WRK-237] A script pipes it: printf '%s\n' "$TOKEN" | sudo gpuk enroll ... --token -
IFS= read -r _tok || true
# A token has no blank in it: strip any, so a line of spaces is no token.
_tok=$(printf '%s' "$_tok" | tr -d '[:space:]')
[ -n "$_tok" ] || die "--token - read no enrollment token on stdin"
fi
enroll_worker "$_url" "$_tok"
systemctl restart "$SERVICE_NAME" 2>/dev/null || true
}
# [WRK-237] `--token -` asks for the enrollment token on the terminal, without echo: it
# never enters a command line (`ps`) nor the shell history. Prompts go to the terminal,
# only the token to stdout.
enroll_token_from_tty() {
(: </dev/tty) 2>/dev/null || die "--token - needs a terminal to ask for the enrollment token"
printf 'Enrollment token: ' >/dev/tty
_stty=$(stty -g </dev/tty 2>/dev/null) || _stty=""
stty -echo </dev/tty 2>/dev/null || true
IFS= read -r _entered </dev/tty || _entered=""
[ -z "$_stty" ] || stty "$_stty" </dev/tty 2>/dev/null || true
printf '\n' >/dev/tty
_entered=$(printf '%s' "$_entered" | tr -d '[:space:]')
[ -n "$_entered" ] || die "no enrollment token entered"
printf '%s' "$_entered"
}
# [WRK-237] The token reaches the worker on stdin: printf is a shell builtin, so the
# secret never appears in a process's arguments.
enroll_worker() {
printf '%s\n' "$2" | GPUK_IDENTITY_DIR="$IDENTITY_DIR" GPUK_MACHINE_ID_FILE="$MACHINE_ID_FILE" \
"$BIN_DEST" enroll --controller "$1" --token-stdin
}
# ── apply ──────────────────────────────────────────────────────────────────────
# Controller: reconcile the app container from the manifest, in-process. A worker
# has no app container — `apply` there is a no-op with a clear message.
@@ -1879,47 +1921,69 @@ cmd_apply() {
# architecture, never older than the daemon already installed. Sets DAEMON_UPDATED.
DAEMON_UPDATED=0
DAEMON_CANDIDATE_READY=0
prepare_daemon() {
_base=$(channel_field "$CHANNEL_DOC" workerBase)
# The gpu-kitchen-worker build the verified channel ($CHANNEL_DOC) names for this host.
channel_worker_build() {
case "$(uname -m)" in
x86_64|amd64) _bkey="workerBuildIdX86_64" ;;
aarch64|arm64) _bkey="workerBuildIdAarch64" ;;
*) die "unsupported architecture: $(uname -m)" ;;
esac
_build=$(channel_field "$CHANNEL_DOC" "$_bkey")
if [ -z "$_base" ] || [ -z "$_build" ]; then
die "the signed release channel names no gpu-kitchen-worker build for $(uname -m) — refusing to leave the daemon on another release (OPS-20)"
_named=$(channel_field "$CHANNEL_DOC" "$_bkey")
[ -n "$_named" ] \
|| die "the signed release channel names no gpu-kitchen-worker build for $(uname -m) — refusing to leave the daemon on another release (OPS-20)"
printf '%s' "$_named"
}
# Never older than the daemon already installed.
refuse_daemon_downgrade() {
_installed=$("$BIN_DEST" --version 2>/dev/null | sed -n 's/^gpu-kitchen-worker //p' | head -1)
case "$_installed" in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-*)
# buildId = YYYYMMDDHHMMSS-<commit>: the timestamp orders builds.
[ "${1%%-*}" -ge "${_installed%%-*}" ] \
|| die "the channel's gpu-kitchen-worker $1 is OLDER than the installed $_installed — refusing a downgrade" ;;
esac
}
# Downloads <url> to $BIN_DEST.new and keeps it only if it is signed by the pinned
# release key FOR gpu-kitchen-worker@<build> (OPS-20, INS-05): a valid signature of
# another, older build is refused too.
fetch_signed_daemon() {
echo "==> downloading $1"
# Not -s: the binary is tens of MB and a silent download reads as a hang.
curl -fL --progress-bar "$1" -o "$BIN_DEST.new" \
|| { rm -f "$BIN_DEST.new"; die "cannot download $1"; }
if [ "${GPUK_CHANNEL_INSECURE:-}" = "1" ]; then
echo "WARNING: GPUK_CHANNEL_INSECURE=1 — $1 NOT verified" >&2
return 0
fi
require_release_key
curl -fsSL "$1.minisig" -o "$BIN_DEST.new.minisig" \
|| { rm -f "$BIN_DEST.new" "$BIN_DEST.new.minisig"; die "no signature at $1.minisig — refusing an unsigned daemon binary"; }
_verified=$("$MINISIGN" -V -m "$BIN_DEST.new" -x "$BIN_DEST.new.minisig" -P "$CHANNEL_PUBKEY" 2>/dev/null) \
|| { rm -f "$BIN_DEST.new" "$BIN_DEST.new.minisig"; die "$1: signature verification FAILED — refusing it (OPS-20)"; }
rm -f "$BIN_DEST.new.minisig"
_comment=$(printf '%s\n' "$_verified" | sed -n 's/^Trusted comment: //p' | head -1)
[ "$_comment" = "gpu-kitchen-worker@$2" ] \
|| { rm -f "$BIN_DEST.new"; die "$1 is signed for '${_comment:-nothing}', not gpu-kitchen-worker@$2 — refusing it (OPS-20)"; }
echo "==> signature verified (build $2)"
}
prepare_daemon() {
_base=$(channel_field "$CHANNEL_DOC" workerBase)
[ -n "$_base" ] \
|| die "the signed release channel names no gpu-kitchen-worker base — refusing to leave the daemon on another release (OPS-20)"
_build=$(channel_worker_build) || exit 1
_installed=$("$BIN_DEST" --version 2>/dev/null | sed -n 's/^gpu-kitchen-worker //p' | head -1)
if [ "$_installed" = "$_build" ]; then
check_candidate_release "$BIN_DEST"
echo "==> worker daemon already on build $_build"
return 0
fi
case "$_installed" in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-*)
# buildId = YYYYMMDDHHMMSS-<commit>: the timestamp orders builds.
[ "${_build%%-*}" -ge "${_installed%%-*}" ] \
|| die "the channel's gpu-kitchen-worker $_build is OLDER than the installed $_installed — refusing a downgrade" ;;
esac
_url="$_base/$(arch_asset)"
refuse_daemon_downgrade "$_build"
echo "==> gpu-kitchen-worker ${_installed:-(unknown build)} → $_build"
command -v curl >/dev/null || die "curl is required to download the daemon"
curl -fL --progress-bar "$_url" -o "$BIN_DEST.new" \
|| { rm -f "$BIN_DEST.new"; die "cannot download $_url"; }
if [ "${GPUK_CHANNEL_INSECURE:-}" = "1" ]; then
echo "WARNING: GPUK_CHANNEL_INSECURE=1 — $_url NOT verified" >&2
else
require_release_key
curl -fsSL "$_url.minisig" -o "$BIN_DEST.new.minisig" \
|| { rm -f "$BIN_DEST.new" "$BIN_DEST.new.minisig"; die "no signature at $_url.minisig — refusing an unsigned daemon binary"; }
_comment=$("$MINISIGN" -V -m "$BIN_DEST.new" -x "$BIN_DEST.new.minisig" -P "$CHANNEL_PUBKEY" 2>/dev/null \
| sed -n 's/^Trusted comment: //p' | head -1)
rm -f "$BIN_DEST.new.minisig"
[ "$_comment" = "gpu-kitchen-worker@$_build" ] \
|| { rm -f "$BIN_DEST.new"; die "$_url is signed for '${_comment:-nothing}', not gpu-kitchen-worker@$_build — refusing it (OPS-20)"; }
echo "==> signature verified (build $_build)"
fi
fetch_signed_daemon "$_base/$(arch_asset)" "$_build"
chmod 0755 "$BIN_DEST.new"
check_candidate_release "$BIN_DEST.new" "$BIN_DEST.new"
DAEMON_CANDIDATE_READY=1
@@ -2399,12 +2463,14 @@ gpuk — GPU Kitchen host daemon (gpu-kitchen-worker)
--domain: the name the UI is reached by through a reverse proxy, any
profile — allowed as a host, trusted proxy on, filled Caddyfile written;
kept by a re-run, dropped with --no-domain
gpuk install --mode worker --controller wss://<host>:<port> --enroll-token gk_enroll_...
gpuk install --mode worker --controller wss://<host>:<port> --enroll-token -
(asks for the token on the terminal: never on a command line)
[--cluster N] [--cache-dir P] [--binary <path>]
[--health-port P] [--data-port P] [--transfer-port P] [--handover-port P]
gpuk install ... --dry-run Validate inputs and print the manifest without changing the host
gpuk status Service state, enrollment, /health, app container status
gpuk enroll --controller wss://<host>:<port> --token gk_enroll_...
gpuk enroll --controller wss://<host>:<port> --token -
(asks on the terminal; a script pipes the token into --token - instead)
gpuk apply (controller) Reconcile the app container, then the proxy container
by handover, from the manifest
gpuk update Move gpuk, the daemon and (controller) the app to the current release