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:
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
# crosscode: installs, updates and moves church installs on this server (ROADMAP-v3 §8,
|
||||
# docs/EVENTS-2.2-PLAN.md §4). `crosscode help` lists the commands.
|
||||
#
|
||||
# On a server this is a checkout of crosscode-platform's main in /opt/crosscode/tools, linked as
|
||||
# /usr/local/bin/crosscode. Every run first updates that checkout (git pull --ff-only), then runs
|
||||
# from a copy, so a checkout never changes the script while it runs.
|
||||
#
|
||||
# Environment: CROSSCODE_SITES (default /var/www/sites), CROSSCODE_REPO (the monorepo's git URL),
|
||||
# CROSSCODE_TOOLS_DIR (default /opt/crosscode/tools), CROSSCODE_NO_UPDATE=1 (skip the update).
|
||||
set -Eeuo pipefail
|
||||
|
||||
CROSSCODE_TOOLS_DIR="${CROSSCODE_TOOLS_DIR:-/opt/crosscode/tools}"
|
||||
|
||||
if [ -z "${CROSSCODE_HOME:-}" ]; then
|
||||
src="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
||||
root="$(cd "$src/.." && pwd)"
|
||||
if [ "${CROSSCODE_NO_UPDATE:-}" != 1 ] && [ "$root" = "$CROSSCODE_TOOLS_DIR" ] && [ -d "$root/.git" ]; then
|
||||
git -C "$root" pull --ff-only --quiet ||
|
||||
printf '!!> Couldn'"'"'t update %s; running the version that is there.\n' "$root" >&2
|
||||
fi
|
||||
copy="$(mktemp -d /tmp/crosscode.XXXXXX)"
|
||||
cp -R "$src/." "$copy/"
|
||||
CROSSCODE_HOME="$copy" CROSSCODE_FROM="$root" exec bash "$copy/crosscode" "$@"
|
||||
fi
|
||||
|
||||
# Running from the copy: remove it afterwards (only ever a mktemp folder, never a checkout).
|
||||
if [[ "$CROSSCODE_HOME" == /tmp/crosscode.* ]]; then
|
||||
trap 'rm -rf "$CROSSCODE_HOME"' EXIT
|
||||
fi
|
||||
|
||||
# shellcheck source=lib/common.sh
|
||||
source "$CROSSCODE_HOME/lib/common.sh"
|
||||
# shellcheck source=lib/deploy.sh
|
||||
source "$CROSSCODE_HOME/lib/deploy.sh"
|
||||
# shellcheck source=lib/status.sh
|
||||
source "$CROSSCODE_HOME/lib/status.sh"
|
||||
# shellcheck source=lib/install.sh
|
||||
source "$CROSSCODE_HOME/lib/install.sh"
|
||||
# shellcheck source=lib/adopt.sh
|
||||
source "$CROSSCODE_HOME/lib/adopt.sh"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
crosscode: Cross Code installs on this server ($(git -C "${CROSSCODE_FROM:-.}" rev-parse --short HEAD 2>/dev/null || echo 'unknown version'))
|
||||
|
||||
crosscode deploy <church> [events] [website] [app] update Accounts and the products named
|
||||
crosscode deploy --every-church [events] … the same, for every church here
|
||||
crosscode deploy <church> … --check only the checks; changes nothing
|
||||
crosscode status [<church>] versions, latest releases, health
|
||||
crosscode install <church> --products events --domain <address> a new church
|
||||
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 help [<command>] this, or a command's options
|
||||
|
||||
Churches live in $CROSSCODE_SITES/<church>/ (church.env, one checkout per product).
|
||||
EOF
|
||||
}
|
||||
|
||||
command="${1:-help}"
|
||||
[ $# -gt 0 ] && shift
|
||||
case "$command" in
|
||||
deploy) cmd_deploy "$@" ;;
|
||||
status) cmd_status "$@" ;;
|
||||
install) cmd_install "$@" ;;
|
||||
adopt) cmd_adopt "$@" ;;
|
||||
add) die "\`crosscode add\` comes with the second product (phase 3)." ;;
|
||||
help|-h|--help)
|
||||
case "${1:-}" in
|
||||
deploy) deploy_usage ;;
|
||||
status) status_usage ;;
|
||||
install) install_usage ;;
|
||||
adopt) adopt_usage ;;
|
||||
*) usage ;;
|
||||
esac ;;
|
||||
*) usage; die "Unknown command \"$command\"." ;;
|
||||
esac
|
||||
Reference in New Issue
Block a user