crosscode: --json reports, --config, env templates, frpc tunnels, restart/export/uninstall/purge

- Every command takes --json (crosscode.script-report/1 on stdout, the
  log on stderr) and --config (the .env values by layer, from the agent).
- .env files come from the release's env.template.json (lib/envtpl.js):
  written whole on install; on deploy only new variables are appended,
  and a new required one with no value stops the deploy at the checks.
- install --frp: Hub-given ports, a marked frpc.ini block (backup,
  frpc verify, reload; [common] admin lines added once), no nginx.
  A database on another server via DB_ADMIN_URL. Refuses an existing
  database or role. Everything the run made is removed if it fails.
- restart, export (crosscode.church-export/1 ZIP), uninstall (final
  backup, uploads and .env kept 30 days) and purge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 12:50:19 +02:00
co-authored by Claude Opus 5.5
parent 350ab9f4e8
commit e9e9b5a97f
17 changed files with 1308 additions and 88 deletions
+38
View File
@@ -209,3 +209,41 @@ cc() { bash "$CROSSCODE_HOME/crosscode" "$@"; }
[ "$status" -eq 1 ]
[[ "$output" == *'No church "nowhere"'* ]]
}
@test "deploy --json: a rolled-back release is reported as rolled-back, with each product's result" {
out="$(FAIL_HEALTH=2.2.1 cc deploy hope events --version events@2.2.1 --json 2>/dev/null || true)"
node -e '
const r = JSON.parse(process.argv[1]);
if (r.schema !== "crosscode.script-report/1" || r.status !== "rolled-back") throw new Error(r.status);
if (r.result.products.events.to !== "events@2.2.1" || r.result.products.events.from !== "events@2.2.0") throw new Error("products");
if (!r.steps.some(s => s.name.includes("reloading PM2"))) throw new Error("steps");' "$out"
[ "$(on hope)" = events@2.2.0 ]
}
@test "a release with a new required setting and no value for it stops at the checks" {
echo 'events_env_vars() { printf "%s\n" --var domain=events.hope.co.za --var apiPort=5000; }' >> "$CROSSCODE_HOME/products/events.sh"
mkdir -p "$CROSSCODE_SITES/hope/events/apps/events/backend"
printf 'DATABASE_URL=x\n' > "$CROSSCODE_SITES/hope/events/apps/events/backend/.env"
# As in the real repo, .env files are ignored by git.
echo .env >> "$CROSSCODE_SITES/hope/events/.git/info/exclude"
cat > "$TMP/origin/apps/events/env.template.json" <<'TPL'
{ "schema": "crosscode.env-template/1", "product": "events", "files": { "backend/.env": [
{ "name": "DATABASE_URL", "layer": "generated", "required": true },
{ "name": "NEW_SERVER_SETTING", "layer": "server", "required": true },
{ "name": "NEW_DEFAULT", "layer": "defaults", "default": "on" } ] } }
TPL
release 2.2.2 "## 2.2.2"
run cc deploy hope events --version events@2.2.2
[ "$status" -eq 1 ]
[[ "$output" == *"NEW_SERVER_SETTING (server, backend/.env)"* ]]
[[ "$output" == *"Nothing was changed"* ]]
[ "$(on hope)" = events@2.2.0 ]
echo '{ "server": { "NEW_SERVER_SETTING": "yes" } }' > "$TMP/config.json"
run cc deploy hope events --version events@2.2.2 --config "$TMP/config.json"
[ "$status" -eq 0 ]
[ "$(on hope)" = events@2.2.2 ]
grep -qx 'DATABASE_URL=x' "$CROSSCODE_SITES/hope/events/apps/events/backend/.env"
grep -qx 'NEW_SERVER_SETTING=yes' "$CROSSCODE_SITES/hope/events/apps/events/backend/.env"
grep -qx 'NEW_DEFAULT=on' "$CROSSCODE_SITES/hope/events/apps/events/backend/.env"
}