crosscode script: deploy, status, install, adopt (Events 2.2.0, plan §4-5)

One script for installing, updating and moving church installs, replacing
hope-events' scripts/deploy.sh and install.sh:

- deploy <church> [events] / --every-church, with --version, --main, --check
  and --allow-local-changes: checks every product first (files changed by
  hand, Node, release requirements from WHATS-NEW.md headings), then each
  product in order with backup, checkout, install, migrate, build, PM2 reload
  and a /health version check; a failure rolls that product back and stops.
- status [<church>]: checked-out and latest release, /health, and the old
  folder kept after adopt.
- install <church> --products events --domain <address>: a new church under
  /var/www/sites/<church>, writing church.env.
- adopt <church> --events-dir <old> builds the monorepo checkout next to the
  running install and switches PM2 over; adopt --undo goes back to it.

Product hooks live in scripts/products/events.sh. shellcheck (lint:scripts)
and 47 bats tests (test:scripts) are part of npm run check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 19:17:06 +02:00
co-authored by Claude Opus 5.5
parent f174285711
commit c442fe0d42
16 changed files with 3111 additions and 7 deletions
+79
View File
@@ -0,0 +1,79 @@
# shellcheck shell=bash
# Cross Events' hooks for the crosscode script (from hope-events' scripts/deploy.sh 2.1.x).
# Every hook takes the product's checkout (EVENTS_DIR, a checkout of crosscode-platform) and the
# app user, and runs the app's commands as that user. Values come from church.env (CENV).
#
# Adding a product means adding a file like this one with the same hooks, and its name in
# SUPPORTED_PRODUCTS (lib/common.sh).
events_app() { printf '%s/apps/events' "$1"; }
events_pm2_names() { pvar events PM2; }
events_pm2_config() { printf '%s/ecosystem.config.js' "$(events_app "$1")"; }
# EVENTS_PORTS="<api> <web>"
events_api_port() { local p; read -r p _ <<< "$(pvar events PORTS)"; printf '%s' "${p:-5000}"; }
events_web_port() { local p; read -r _ p <<< "$(pvar events PORTS)"; printf '%s' "${p:-3000}"; }
events_health_url() { printf 'http://127.0.0.1:%s/health' "$(events_api_port)"; }
# The version /health reports once this checkout runs (the backend's package.json).
events_expected_version() {
node -p 'require(process.argv[1]).version' "$(events_app "$1")/backend/package.json"
}
events_backup() {
local dir="$1" user="$2"
# shellcheck disable=SC2016
run_as "$user" "$(events_app "$dir")/backend" node -e '
require("dotenv").config();
require("./src/utils/backupUtils").runBackup()
.then(r => console.log(" " + r.filename))
.catch(e => { console.error(" Backup failed: " + e.message); process.exit(1); });'
}
# Only this app's workspaces, never the other products'. --include=dev: the TypeScript and Next
# builds need type and build packages even where NODE_ENV=production.
events_install_deps() {
run_as "$2" "$1" npm ci --include=dev --no-audit --no-fund -w apps/events/backend -w apps/events/frontend
}
events_migrate() {
run_as "$2" "$(events_app "$1")/backend" npm run prisma:deploy
}
events_pending_migrations() {
# prisma migrate status exits non-zero when migrations are pending (or the DB can't be read).
! run_as "$2" "$(events_app "$1")/backend" npx prisma migrate status >/dev/null 2>&1
}
events_build() {
run_as "$2" "$(events_app "$1")/backend" npm run build &&
run_as "$2" "$(events_app "$1")/frontend" npm run build
}
# After going back to the previous tag: install and build it again. Migrations aren't undone
# (the backup taken first has the database as it was).
events_rollback_build() {
events_install_deps "$1" "$2" && events_build "$1" "$2"
}
# The install's own PM2 config (not in git). Created from the example the first time, with this
# church's PM2 names and web port.
events_ensure_pm2_config() {
local dir="$1" user="$2" app conf backend frontend
app="$(events_app "$dir")"
conf="$app/ecosystem.config.js"
[ -f "$conf" ] && return 0
read -r backend frontend <<< "$(events_pm2_names)"
sed -e "s/'hope-events-backend'/'${backend}'/" \
-e "s/'hope-events-frontend'/'${frontend}'/" \
-e "s/-p 3000/-p $(events_web_port)/" \
"$app/ecosystem.config.example.js" > "$conf"
chown "$user:$user" "$conf" 2>/dev/null || true
info "Created $conf from the example."
}
events_reload() {
events_ensure_pm2_config "$1" "$2"
run_as "$2" "$(events_app "$1")" pm2 reload ecosystem.config.js --update-env
}