Website 1.3.0, agent 1.6.0, contracts 1.19.0: demo data for the Church Website

Eight demo churches, two per template (the second on the template's other
recommended variants and header), loaded from the Hub on demo sites with
`crosscode demo <church> website --profile <p>`. A profile replaces the
content only: the church's profile from Accounts, the site settings, the
site icon and the admins stay, and the copy names the church.

- contracts: WEBSITE_DEMO_PROFILES, DEMO_PRODUCTS, SEED_WEBSITE_DEMO_MIN_AGENT;
  seed-demo takes an optional product (events by default)
- agent: a Website seed-demo job runs `crosscode demo <church> website`
- crosscode script: backup, demo as the site's user, reload, health check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 09:20:09 +02:00
co-authored by Claude Opus 5.5
parent 81c01d8a9f
commit 2fb7ac57da
22 changed files with 813 additions and 115 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ crosscode: Cross Code installs on this server ($(git -C "${CROSSCODE_FROM:-.}" r
crosscode adopt <church> --events-dir <old folder> move an existing Cross Events install here
crosscode adopt <church> --undo go back to the old folder (within 14 days)
crosscode restart <church> [events] reload the PM2 processes
crosscode demo <church> --profile <profile> replace Events' data with a demo set
crosscode demo <church> [website] --profile <p> replace Events' (or the Website's) data with a demo
crosscode env <church> <product> [--set NAME=value] show or change a product's .env values
crosscode export <church> [product …] --out <zip> the church's data and uploads
crosscode uninstall <church> [product …] --confirm <church>
+46 -1
View File
@@ -10,6 +10,12 @@ crosscode demo <church> --profile <profile> [--admin-email <email>]
replace Cross Events' data with a demo set
(small, events, ministry, multicampus); a backup
is taken first, one admin account is kept
crosscode demo <church> website --profile <profile>
replace the Website's content with a demo church
(heritage-parish, heritage-city, bold-youth,
bold-plant, community-family, community-town,
clean-modern, clean-campus); a backup is taken
first; the church's profile, settings and admins stay
crosscode env <church> <product> the product's .env values (secrets hidden)
crosscode env <church> <product> [--file backend/.env] --set NAME=value … [--unset NAME …] [--restart]
change values (a copy is kept; never secrets or
@@ -83,22 +89,32 @@ cmd_restart() {
}
DEMO_PROFILES="small events ministry multicampus"
# The Website's (contracts WEBSITE_DEMO_PROFILES): two per template.
WEBSITE_DEMO_PROFILES="heritage-parish heritage-city bold-youth bold-plant community-family community-town clean-modern clean-campus"
# Replaces Events' data with a demo set (apps/events/backend/scripts/set-demo.js), as the site's
# user (its .env is readable only by that user). The Hub sends it only for installs marked as demo
# sites. Afterwards Events is reloaded: the demo switches campuses on or off.
# `crosscode demo <church> website --profile <p>`: the Website's content instead (cmd_demo_website).
cmd_demo() {
local church="" profile="" email="" dir user app
local church="" product="events" profile="" email="" dir user app
while [ $# -gt 0 ]; do
case "$1" in
--profile) [ $# -ge 2 ] || die "--profile needs a value."; profile="$2"; shift 2 ;;
--admin-email) [ $# -ge 2 ] || die "--admin-email needs a value."; email="$2"; shift 2 ;;
-h|--help) manage_usage; return 0 ;;
-*) die "Unknown option $1 (crosscode help demo)." ;;
events|website) [ -n "$church" ] || die "Name the church first (crosscode demo hope website …)."; product="$1"; shift ;;
*) [ -z "$church" ] || die "One church at a time."; church="$1"; shift ;;
esac
done
[ -n "$church" ] || die "Name the church."
if [ "$product" = website ]; then
[[ " $WEBSITE_DEMO_PROFILES " == *" $profile "* ]] || die "--profile: one of $WEBSITE_DEMO_PROFILES."
[ -z "$email" ] || die "--admin-email: the Website's demo keeps every admin."
cmd_demo_website "$church" "$profile"
return
fi
[[ " $DEMO_PROFILES " == *" $profile "* ]] || die "--profile: one of $DEMO_PROFILES."
[ -z "$email" ] || [[ "$email" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]] || die "--admin-email: not an email address."
require_root
@@ -128,6 +144,35 @@ cmd_demo() {
die "Events didn't answer after the reload (sudo -u $user pm2 logs)."
}
# The Website's demo (Website 1.3.0+, backend/src/demo/seeds.ts): its content replaced with one of
# the eight demo churches, keeping the church's profile, the site settings and the admins. Backup
# first; then reloaded, so nothing cached from before is shown.
cmd_demo_website() {
local church="$1" profile="$2" dir user app
require_root
load_church "$church"
church_has_product website || die "$church has no Church Website."
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/website.sh"
dir="$(pvar website DIR)"
user="$(pvar website USER)"
app="$(website_app "$dir")"
[ -f "$app/backend/src/demo/seeds.ts" ] || die "This release of the Website ($(checkout_ref "$dir" website)) has no demo profiles (1.3.0 or later has)."
step "Website: backup first"
website_backup "$dir" "$user" || die "The backup failed, so the demo wasn't loaded."
step "Website: demo ($profile)"
run_as "$user" "$app/backend" npm run --silent demo -- --profile "$profile" --force ||
die "The demo wasn't loaded (see above). If it got as far as changing anything, the backup from just now has the content from before."
step "Website: reloading PM2"
website_reload "$dir" "$user"
step "Website: waiting for it to answer"
wait_for_version "$(website_health_url)" "$(website_expected_version "$dir")" 60 ||
die "The Website didn't answer after the reload (sudo -u $user pm2 logs)."
}
# crosscode env <church> <product>: the product's .env values, secrets hidden (the Hub's env-read).
# With --set / --unset (the Hub's env-set): changes one file (--file, default backend/.env), keeping
# a copy first; when the frontend's file changed, the frontend is rebuilt (Next.js builds its values
+41 -8
View File
@@ -17,6 +17,15 @@ setup() {
export CROSSCODE_HOME="$TMP/home"
mkdir -p "$CROSSCODE_HOME/products" "$TMP/sites/hope/events/apps/events/backend/scripts"
touch "$TMP/sites/hope/events/apps/events/backend/scripts/set-demo.js"
mkdir -p "$TMP/sites/hope/website/apps/website/backend/src/demo"
touch "$TMP/sites/hope/website/apps/website/backend/src/demo/seeds.ts"
cat > "$CROSSCODE_HOME/products/website.sh" <<EOF2
website_app() { printf '%s/apps/website' "\$1"; }
website_backup() { echo "backup \$2" >> "$CALLS"; [ -z "\${FAIL_BACKUP:-}" ]; }
website_reload() { echo "reload \$2" >> "$CALLS"; }
website_health_url() { echo http://127.0.0.1:5300/api/health; }
website_expected_version() { echo 1.3.0; }
EOF2
cat > "$CROSSCODE_HOME/products/events.sh" <<EOF
events_app() { printf '%s/apps/events' "\$1"; }
events_backup() { echo "backup \$2" >> "$CALLS"; [ -z "\${FAIL_BACKUP:-}" ]; }
@@ -26,9 +35,9 @@ events_expected_version() { echo 2.4.1; }
EOF
require_root() { :; }
load_church() { [ "$1" = hope ] || die "There's no church $1 here."; }
church_has_product() { [ "$1" = events ]; }
pvar() { case "$2" in DIR) echo "$TMP/sites/hope/events" ;; USER) echo cc-hope ;; esac; }
checkout_ref() { echo events@2.4.1; }
church_has_product() { [ "$1" = events ] || [ "$1" = website ]; }
pvar() { case "$2" in DIR) echo "$TMP/sites/hope/$1" ;; USER) echo "cc-hope-$1" ;; esac; }
checkout_ref() { echo "$2@1.0.0"; }
wait_for_version() { echo "wait $2" >> "$CALLS"; }
run_as() { local user="$1" dir="$2"; shift 2; echo "run $user ${dir#"$TMP"/} $*" >> "$CALLS"; [ -z "${FAIL_SEED:-}" ]; }
}
@@ -49,23 +58,23 @@ EOF
@test "backup, then the demo as the site's user (no prompt), then a reload" {
run cmd_demo hope --profile ministry
[ "$status" -eq 0 ]
[ "$(cat "$CALLS")" = "backup cc-hope
run cc-hope sites/hope/events/apps/events/backend env node scripts/set-demo.js --profile=ministry --yes
reload cc-hope
[ "$(cat "$CALLS")" = "backup cc-hope-events
run cc-hope-events sites/hope/events/apps/events/backend env node scripts/set-demo.js --profile=ministry --yes
reload cc-hope-events
wait 2.4.1" ]
}
@test "the admin to keep goes in DEMO_ADMIN_EMAIL (older releases only read that)" {
run cmd_demo hope --profile small --admin-email jane@hope.test
[ "$status" -eq 0 ]
grep -qx 'run cc-hope sites/hope/events/apps/events/backend env DEMO_ADMIN_EMAIL=jane@hope.test node scripts/set-demo.js --profile=small --yes' "$CALLS"
grep -qx 'run cc-hope-events sites/hope/events/apps/events/backend env DEMO_ADMIN_EMAIL=jane@hope.test node scripts/set-demo.js --profile=small --yes' "$CALLS"
}
@test "a failed backup stops it before the data is touched" {
FAIL_BACKUP=1 run cmd_demo hope --profile small
[ "$status" -eq 1 ]
[[ "$output" == *"The backup failed"* ]]
[ "$(cat "$CALLS")" = "backup cc-hope" ]
[ "$(cat "$CALLS")" = "backup cc-hope-events" ]
}
@test "a failed demo isn't followed by a reload" {
@@ -81,3 +90,27 @@ wait 2.4.1" ]
[[ "$output" == *"has no demo data"* ]]
[ ! -s "$CALLS" ]
}
@test "website: backup, then the demo profile as the site's user, then a reload" {
run cmd_demo hope website --profile bold-plant
[ "$status" -eq 0 ]
[ "$(cat "$CALLS")" = "backup cc-hope-website
run cc-hope-website sites/hope/website/apps/website/backend npm run --silent demo -- --profile bold-plant --force
reload cc-hope-website
wait 1.3.0" ]
}
@test "website: only its own profiles, no admin email, and only a release that has them" {
run cmd_demo hope website --profile small
[ "$status" -eq 1 ]
[[ "$output" == *"heritage-parish"* ]]
run cmd_demo hope website --profile clean-campus --admin-email jane@hope.test
[ "$status" -eq 1 ]
run cmd_demo hope --profile clean-campus
[ "$status" -eq 1 ]
rm "$TMP/sites/hope/website/apps/website/backend/src/demo/seeds.ts"
run cmd_demo hope website --profile clean-campus
[ "$status" -eq 1 ]
[[ "$output" == *"no demo profiles"* ]]
[ ! -s "$CALLS" ]
}