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
+26
View File
@@ -181,6 +181,32 @@ Secrets stay in each product's own `.env`, never in `church.env`.
| `adopt <church> --undo` | Yes (decision 26): goes back to the old folder and the 2.1.x it ran, within the days the old folder is kept |
| `add <church> <product>` | **Later** (phase 3), when there's a second product to add |
**Built 2026-11-12** (branch `feat/crosscode-script`), as above, with these details settled while
writing it:
- **Run as root.** `church.env` is root-only (mode 600), so every command needs root; each app's
commands (git, npm, Prisma, PM2) run as its app user through `sudo -u`.
- `church.env` is read as data, never sourced: only `CHURCH`, `PRODUCTS`, `ADDRESS` and
`<PRODUCT>_*` keys are taken.
- `--allow-local-changes` replaces `ALLOW_LOCAL_CHANGES=1` (the variable still works). `--check`
never passes with changes.
- "Latest" only counts plain `events@x.y.z` tags, so test tags such as `events@2.2.0-test` are
only ever deployed with `--version`.
- `--every-church` stops at the first church that fails (its products roll back as usual), and
names the churches it didn't reach.
- `install`: the app user defaults to `cc-<church>`, PM2 names to `<church>-events-backend` /
`-frontend`, the database to `<church>_events`, and ports to the first free ones from 5000
(API) and 3000 (web), counting every church's `church.env` and anything listening.
- `adopt` writes `church.env` only once the switch has worked, and refuses to start if nginx
refers to the old folder by path (it gets renamed). It also records `EVENTS_OLD_DIR`,
`EVENTS_OLD_REF` and `EVENTS_ADOPTED_AT` for `--undo` and `status`.
- `adopt --undo` refuses if the new checkout has migrations the old release doesn't have, and
moves `/var/www/sites/<church>` aside to `.undone-<church>-<time>` (not deleted), so `adopt`
can be run again.
- Tests: `npm run lint:scripts` (shellcheck) and `npm run test:scripts` (bats: 47 tests,
including deploys against a local git origin with stub hooks for the checks, requirements,
order, rollback and `--every-church`). Both are part of `npm run check`.
**Requirement check** (decision 24): before anything is touched, read the target version's
heading in `apps/<product>/WHATS-NEW.md`. Refuse the deploy if a `— requires <product> <version>`
isn't met by the installed sibling or by this same run. Nothing in 2.2.0 requires anything, but
+1 -1
View File
@@ -25,7 +25,7 @@ for each phase. They moved here from `hope-events/docs/` on 2026-11-05.
|-------|------|-------|
| 0 | contracts 1.0.0 / 1.1.0 | **Released** 2026-11-04 (`contracts@1.0.0`, `contracts@1.1.0`). Not published to a registry (decision 22): the Hub gets a packed release committed to its repo |
| 1 | Hub 2.0.0 | **Released** 2026-11-05 (`events-hub` `v2.0.0`; `docs/HUB-2.0-PLAN.md` there). **Not deployed yet:** `events-hub/deployment.md` → "Upgrading to 2.0" (run `check-hub2` first). crosscode-site's address prices are merged, **not deployed yet** |
| 1b | Cross Events 2.2.0: moves here as `apps/events`, `crosscode` script | **In progress.** Planned in [EVENTS-2.2-PLAN.md](./EVENTS-2.2-PLAN.md). **Steps 1–3 done 2026-11-12** (merged into `main`): history merged in under `apps/events` (from `hope-events` `e6c9670`), workspaces and one root lockfile with versions pinned to 2.1.1, same test results as 2.1.1 (711 backend tests, typecheck, both builds). **Still to do:** the `crosscode` script and `adopt` (§4–5), VM testing (§6), the version bump and `events@2.2.0` tag, adopting each install, archiving `hope-events` (§7). Until then servers keep deploying from `hope-events` `v2.1.1`, and **Events work happens here** (`hope-events` is frozen; a hotfix there as 2.1.2 is cherry-picked into `apps/events`) |
| 1b | Cross Events 2.2.0: moves here as `apps/events`, `crosscode` script | **In progress.** Planned in [EVENTS-2.2-PLAN.md](./EVENTS-2.2-PLAN.md). **Steps 1–3 done 2026-11-12** (merged into `main`): history merged in under `apps/events` (from `hope-events` `e6c9670`), workspaces and one root lockfile with versions pinned to 2.1.1, same test results as 2.1.1 (711 backend tests, typecheck, both builds). **The `crosscode` script and `adopt` (§4–5) are written** (branch `feat/crosscode-script`, 2026-11-12; shellcheck and 47 bats tests pass, not yet run on a server). **Still to do:** VM testing (§6), the version bump and `events@2.2.0` tag, adopting each install, archiving `hope-events` (§7). Until then servers keep deploying from `hope-events` `v2.1.1`, and **Events work happens here** (`hope-events` is frozen; a hotfix there as 2.1.2 is cherry-picked into `apps/events`) |
| 1c | Cross Events 2.3.0: authenticator app 2FA (TOTP + recovery codes) | Not started (`TwoFactorMethod` enum in Events' `prisma/schema.prisma`) |
| 1d | Agent 1.0.0 + Hub 2.1.0 (+ contracts 1.2.0): server agent, installs / scheduled updates / uninstalls from the Hub, server stats | **Planned** 2026-11-12 in [AGENT-1.0-PLAN.md](./AGENT-1.0-PLAN.md) (ROADMAP decisions 27–37). Starts after 1b; can run alongside 1c |
| 2 | Cross Events 2.4.0: protocol v2, Linked products, event feed, `packages/seo` | Not started. Events keeps speaking protocol 1 until then |