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
+28
View File
@@ -0,0 +1,28 @@
{
"schema": "crosscode.env-template/1",
"product": "events",
"files": {
"backend/.env": [
{ "name": "NODE_ENV", "layer": "generated", "required": true, "description": "production" },
{ "name": "PORT", "layer": "install", "from": "{apiPort}", "required": true, "description": "The backend's port (from the Hub's port list)" },
{ "name": "DATABASE_URL", "layer": "generated", "required": true, "description": "Made on the server with a new password; never leaves it" },
{ "name": "JWT_SECRET", "layer": "generated", "required": true, "description": "Also encrypts stored secrets: never change it" },
{ "name": "FRONTEND_URL", "layer": "install", "from": "https://{domain}", "required": true },
{ "name": "APP_BASE_URL", "layer": "install", "from": "https://{domain}", "required": true },
{ "name": "BACKEND_URL", "layer": "install", "from": "https://{domain}", "required": true, "description": "The same address: the backend is under /api (2.2.0+)" },
{ "name": "TRUST_PROXY", "layer": "server", "required": true, "description": "Behind frp: loopback" },
{ "name": "APP_TIMEZONE", "layer": "install", "default": "Africa/Johannesburg" },
{ "name": "HUB_URL", "layer": "defaults", "default": "https://hub.crosscode.co.za" },
{ "name": "HUB_HEARTBEAT_ENABLED", "layer": "defaults", "default": "true" },
{ "name": "HUB_LICENCE_KEY", "layer": "install", "description": "With it the site registers with the Hub by itself when it first starts" },
{ "name": "HUB_ADMIN_NAME", "layer": "install", "description": "The site admin, sent to the Hub on registering" },
{ "name": "HUB_ADMIN_EMAIL", "layer": "install" },
{ "name": "BACKUP_ENABLED", "layer": "defaults", "default": "true" },
{ "name": "DAILY_SUMMARY_ENABLED", "layer": "defaults", "default": "true" },
{ "name": "SENTRY_DSN", "layer": "defaults" }
],
"frontend/.env.production": [
{ "name": "NEXT_PUBLIC_API_URL", "layer": "install", "from": "https://{domain}", "required": true }
]
}
}
+37
View File
@@ -77,3 +77,40 @@ events_reload() {
events_ensure_pm2_config "$1" "$2"
run_as "$2" "$(events_app "$1")" pm2 reload ecosystem.config.js --update-env
}
# The church's data as crosscode.church-export/1 into <out dir> (owned by the app user). Releases
# from before the export (events@2.2.0) don't have the script.
events_export() {
local dir="$1" user="$2" out="$3" app
app="$(events_app "$dir")"
[ -f "$app/backend/scripts/export-church.ts" ] ||
die "This release of Events ($(checkout_ref "$dir" events)) has no export yet. Update it first."
run_as "$user" "$app/backend" npx tsx scripts/export-church.ts --out-dir "$out"
}
# Uploaded files into <dest> (WhatsApp ticket PDFs waiting to be sent are left out).
events_copy_uploads() {
local src
src="$(events_app "$1")/backend/public/uploads"
mkdir -p "$2"
[ -d "$src" ] || return 0
rsync -a --exclude tickets-temp/ "$src/" "$2/"
}
# What uninstall keeps for 30 days in <dest>: the backups (the last is the final one), the
# uploads, and the .env files (the backup's stored secrets are encrypted with its JWT_SECRET).
events_keep() {
local app dest="$2"
app="$(events_app "$1")"
mkdir -p "$dest"
[ ! -d "$app/backend/backups" ] || rsync -a "$app/backend/backups/" "$dest/backups/"
[ ! -d "$app/backend/public/uploads" ] || tar -czf "$dest/uploads.tar.gz" -C "$app/backend/public" uploads
cp -p "$app/backend/.env" "$dest/backend.env" 2>/dev/null || true
cp -p "$app/frontend/.env.production" "$dest/frontend.env.production" 2>/dev/null || true
chmod -R go-rwx "$dest"
}
# --var arguments for the env template (envtpl.js), from church.env.
events_env_vars() {
printf '%s\n' --var "domain=$(pvar events DOMAIN)" --var "apiPort=$(events_api_port)" --var "webPort=$(events_web_port)" --var "church=$(cenv CHURCH)"
}