Files
computer-playbook/scripts/tests/deploy/ci/all.sh
T
kevinveenbirkenbachandClaude Opus 4.7 8e293bd921 fix(compose-deploy): stop persisting runtime routing knobs into .env
Root cause of step-08 deploy failures across all 4 test-development
distros in run 26572559126: `make compose-deploy mode=reinstall
apps=web-app-dashboard INFINITO_SERVICES_DISABLED=matomo` (step 07)
made make export the cmdline var into the recipe's shell env, which
reached `runner.py` → `make setup` → `make dotenv`. The dotenv
generator's `setdefault` then baked the runtime-only value into the
on-disk `.env`. Step 08 sourced that .env, filtered `web-app-matomo`
out of its primary apps, and exited with "All primary apps disabled".

Fix:

- Drop the 7 routing knobs (apps, mode, purge, bundles, disable,
  full_cycle, variant) from `passthrough.STATIC_KEYS` and from
  `default.env`. They are per-invocation; .env is the persistent SPOT
  and must not capture them.
- Switch every consumer from `os.environ["KEY"]` strict access to
  `os.environ.get("KEY", "")` so the missing-key path stops at "no
  filter" instead of a KeyError.
- Rename the env-var surface to match the make-alias surface 1:1
  (lowercase): INFINITO_APPS → apps, INFINITO_SERVICES_DISABLED →
  disable, INFINITO_BUNDLES → bundles, INFINITO_FULL_CYCLE →
  full_cycle, INFINITO_VARIANT → variant, INFINITO_DEPLOY_MODE → mode,
  INFINITO_PURGE_ENTITIES → purge. The make alias was the user-facing
  name in every doc; routing-knob env vars now use the same name so
  the cmdline form, the recipe env-prefix, and the consumer reads
  all line up.
- Collapse the Makefile `compose-deploy` recipe to just the two
  knobs whose alias differs from the env name (`type` →
  INFINITO_DEPLOY_TYPE, `debug` → INFINITO_DEBUG). GNU Make
  auto-exports cmdline variables into the recipe's shell env, so the
  identical-name `$(if $(apps),apps="$(apps)")` lines were pure
  noise.
- Drop `disable: ${disable}` from compose.yml. The dev CLI builds
  `extra_env` per `docker exec` call and forwards `disable` via
  `-e`, so the container env never needs the value frozen at
  compose-up time.
- Update the 3 actual leak call sites
  (07/08/09_deploy_*.sh) to the make-alias form
  (`disable=matomo`, `full_cycle=true`, `variant=1`).
- Add `SIM112` to ruff's ignore set: the lowercase env names are
  the deliberate make/env parity, not a typo.

Repro before fix: `INFINITO_SERVICES_DISABLED=matomo make dotenv`
wrote `INFINITO_SERVICES_DISABLED=matomo` to `.env`. After fix:
`disable=matomo make dotenv` leaves `.env` untouched.

Tests: `make test` and `make autoformat` green (2711 tests, 8 lint
sub-targets).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 17:47:03 +02:00

187 lines
5.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# SPOT: Deploy exactly ONE app across all distros (serial).
#
# Additionally:
# - Track duration per distro
# - Enforce a global time budget for the whole run (env: MAX_TOTAL_SECONDS)
# - Skip a distro if remaining time is smaller than the max duration of any previous distro run
#
# Required env:
# apps="web-app-keycloak"
# INFINITO_DEPLOY_TYPE="server|workstation|universal"
# INFINITO_DISTROS="arch debian ubuntu fedora centos"
# INFINITO_INVENTORY_DIR="/path/to/inventory"
#
# Optional env:
# PYTHON="python3"
# MAX_TOTAL_SECONDS="5400" # override the script default of 19800 seconds
#
# Script-local defaults preserved from the old Make wrapper:
# MISSING_ONLY=true
# MAX_TOTAL_SECONDS=19800
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../.." && pwd)"
cd "${REPO_ROOT}"
if [[ -f "scripts/meta/env/load.sh" ]]; then
# shellcheck source=scripts/meta/env/load.sh
source "scripts/meta/env/load.sh"
else
echo "[ERROR] Missing env file: scripts/meta/env/load.sh" >&2
exit 2
fi
: "${apps:?apps is required (e.g. apps=web-app-keycloak)}"
: "${INFINITO_DEPLOY_TYPE:?INFINITO_DEPLOY_TYPE is required (server|workstation|universal)}"
: "${INFINITO_DISTROS:?INFINITO_DISTROS is required (e.g. 'arch debian ubuntu fedora centos')}"
: "${INFINITO_INVENTORY_DIR:?INFINITO_INVENTORY_DIR is required}"
case "${INFINITO_DEPLOY_TYPE}" in
server | workstation | universal) ;;
*)
echo "[ERROR] Invalid INFINITO_DEPLOY_TYPE: ${INFINITO_DEPLOY_TYPE}" >&2
exit 2
;;
esac
: "${PYTHON:=python3}"
: "${MISSING_ONLY:=true}"
if [[ -z "${MAX_TOTAL_SECONDS+x}" ]]; then
MAX_TOTAL_SECONDS=19800
fi
export INFINITO_INVENTORY_DIR MISSING_ONLY MAX_TOTAL_SECONDS
if [[ -n "${MAX_TOTAL_SECONDS}" ]]; then
if ! [[ "${MAX_TOTAL_SECONDS}" =~ ^[0-9]+$ ]]; then
echo "[ERROR] MAX_TOTAL_SECONDS must be an integer (seconds), got: '${MAX_TOTAL_SECONDS}'" >&2
exit 2
fi
fi
read -r -a distro_arr <<<"${INFINITO_DISTROS}"
mapfile -t distro_arr < <(printf '%s\n' "${distro_arr[@]}" | shuf)
echo "=== Distro execution order: ${distro_arr[*]} ==="
global_start="$(date +%s)"
deadline=""
if [[ -n "${MAX_TOTAL_SECONDS}" ]]; then
deadline="$((global_start + MAX_TOTAL_SECONDS))"
echo "=== Global time budget enabled: ${MAX_TOTAL_SECONDS}s (deadline epoch=${deadline}) ==="
else
echo "=== Global time budget disabled (MAX_TOTAL_SECONDS was set empty) ==="
fi
max_seen=0
skipped=0
ran=0
failed=0
durations=() # store "distro=seconds" lines
sync_ci_image_for_run() {
local owner tag repo_name
if [[ -n "${OWNER:-}" || -n "${GITHUB_REPOSITORY_OWNER:-}" || -n "${GITHUB_REPOSITORY:-}" ]]; then
owner="$(OWNER="${OWNER:-}" GITHUB_REPOSITORY_OWNER="${GITHUB_REPOSITORY_OWNER:-}" GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-}" scripts/meta/resolve/repository/owner.sh)"
else
owner=""
fi
tag="${INFINITO_IMAGE_TAG}"
repo_name="${INFINITO_IMAGE_REPOSITORY:-}"
# Keep local/dev workflows untouched; only adjust image when CI owner context exists.
if [[ -z "${owner}" ]]; then
return 0
fi
if [[ -z "${repo_name}" ]]; then
repo_name="$(scripts/meta/resolve/repository/name.sh)"
fi
export INFINITO_IMAGE="ghcr.io/${owner}/${repo_name}/${INFINITO_DISTRO}:${tag}"
echo ">>> CI image synced: ${INFINITO_IMAGE}"
}
echo ">>> Installing CI dependencies"
"${PYTHON}" -m pip install ruamel.yaml PyYAML
for distro in "${distro_arr[@]}"; do
now="$(date +%s)"
remaining=""
if [[ -n "${deadline}" ]]; then
remaining="$((deadline - now))"
if ((remaining <= 0)); then
echo "[WARN] Global budget exhausted (remaining=${remaining}s). Stopping further distro runs."
break
fi
# Skip logic: only if we already have a max_seen from a prior run
if ((max_seen > 0 && remaining < max_seen)); then
echo "[WARN] Skipping distro=${distro}: remaining=${remaining}s < max_seen=${max_seen}s (fast-fail heuristic)"
skipped=$((skipped + 1))
continue
fi
fi
echo "=== Running dedicated distro deploy: distro=${distro} app=${apps} type=${INFINITO_DEPLOY_TYPE} ==="
if [[ -n "${remaining}" ]]; then
echo ">>> Time budget: remaining=${remaining}s max_seen=${max_seen}s"
fi
export INFINITO_DISTRO="${distro}"
# Re-source defaults.sh so its always-derived INFINITO_CONTAINER block
# (outside the load-once guard) refreshes from the current INFINITO_DISTRO.
# This is the single spot that owns the derivation; consumers below
# (dedicated.sh, python deploy → entity.sh) just inherit the env.
source "scripts/meta/env/load.sh"
sync_ci_image_for_run
distro_start="$(date +%s)"
set +e
scripts/tests/deploy/ci/dedicated.sh \
--apps "${apps}"
rc=$?
set -e
distro_end="$(date +%s)"
dur="$((distro_end - distro_start))"
durations+=("${distro}=${dur}s")
ran=$((ran + 1))
if ((dur > max_seen)); then
max_seen="$dur"
fi
echo ">>> Duration: distro=${distro} took ${dur}s (max_seen=${max_seen}s)"
if [[ $rc -ne 0 ]]; then
echo "[ERROR] Deploy failed for distro=${distro} app=${apps} (rc=${rc})" >&2
failed=$((failed + 1))
exit "$rc"
fi
done
global_end="$(date +%s)"
total="$((global_end - global_start))"
echo
echo "=== Summary ==="
echo "app=${apps} type=${INFINITO_DEPLOY_TYPE}"
echo "ran=${ran} skipped=${skipped} failed=${failed}"
echo "total_runtime=${total}s max_seen_duration=${max_seen}s"
if [[ -n "${deadline}" ]]; then
now="$(date +%s)"
remaining="$((deadline - now))"
echo "budget=${MAX_TOTAL_SECONDS}s remaining=${remaining}s"
fi
echo "per-distro:"
for line in "${durations[@]}"; do
echo " - ${line}"
done