tracker
All repositories: gitoria
11.9 KB
#!/usr/bin/env bash# deploy.sh — tracker.worldapi.org: Loreana (this folder) → Byrodin. Run ON LOREANA.## ./deploy.sh gates → backup → rsync → hand over through the standby (no gap) → public URL 200# ./deploy.sh --dry-run gates → rsync -n (shows what WOULD be sent), no backup, no restart, no URL check# ./deploy.sh --skip-tests skips the gates (LOUD warning) — only when you know why# ./deploy.sh --target DIR|HOST:DIR another destination (default below); a local DIR is# how the script is tested without touching Byrodin# ./deploy.sh --url URL the URL that must answer 200 after the restart (asked for up to 90 s)# (env: DEPLOY_TARGET, DEPLOY_URL, DEPLOY_SSH override the same defaults; DEPLOY_URL_WAIT the seconds the URL may take)# (backup: tars storage/.sessions/.env that exist on the target to Loreana's# /media/SLOW1TB2/deploy-backups/<app>/, keeps newest 2 (Apollo 2026-11-11: ~20 GB each); --target DIR backs up DIR instead)## THE FIRST DEPLOY is done by the architect on Byrodin (folder, .env with this app's ident# API key + secret — registered once in ident's /apps for origin https://tracker.worldapi.org# — nginx vhost, cert, DNS). This script only updates the CODE: storage/, .sessions/, .env,# .scratch/, server.*, tests/ fixtures and logs are never sent, so live data on Byrodin is# never touched. No --delete: a file removed here stays on Byrodin (harmless).set -euo pipefail# ---- the app ------------------------------------------------------------------------------APP=tracker.worldapi.orgCONTAINER=tracker.worldapi.org[email protected]:/CONTAINERS/projects/tracker.worldapi.orgDEFAULT_URL=https://tracker.worldapi.org/GATES=("node tests/browser.mjs""node tests/security.mjs""node tests/kinds.mjs""node tests/franchises.mjs""node tests/pager.mjs""node tests/franchiseseed.mjs""node tests/signin-return.mjs" # ident#31: sign in through the selector panel, back on the same page"node theme/check-theme.mjs .""node tests/person-lookup.mjs" # tracker#46: the person page reads no whole title records per request"node tests/mobile.mjs" # MK: the phone gate (390 px touch: tap targets, /franchises paging, a long season starts closed)"node tests/warmstart.mjs" # T17: the server listens before the boot scan is done (note, 503, then complete))# NEVER SENT (rsync patterns; a leading / anchors at the app folder)EXCLUDES=(/.git/ /.gitignore/storage/ /.sessions/ /.env /.env.* /.scratch/ /server.* '*.log' '*.pid' node_modules/)# ---------------------------------------------------------------------------------------------DRY=0SKIP=0TARGET=${DEPLOY_TARGET:-$DEFAULT_TARGET}URL=${DEPLOY_URL:-$DEFAULT_URL}# Loreana's ssh config may not apply to Byrodin: -F /dev/null (ident STATUS)SSH=${DEPLOY_SSH:-ssh -F /dev/null -o BatchMode=yes -o ConnectTimeout=15}usage() { sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; }while [ $# -gt 0 ]; docase "$1" in--dry-run) DRY=1 ;;--skip-tests) SKIP=1 ;;--target) TARGET=${2:?--target needs a value}; shift ;;--target=*) TARGET=${1#--target=} ;;--url) URL=${2:?--url needs a value}; shift ;;--url=*) URL=${1#--url=} ;;-h|--help) usage; exit 0 ;;*) echo "deploy: unknown argument: $1" >&2; usage >&2; exit 2 ;;esacshiftdoneHERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)cd "$HERE"step() { printf '\n==> %s\n' "$*"; }run() { printf ' $ %s\n' "$*" >&2; "$@"; }die() { printf '\ndeploy: REFUSED — %s\n' "$*" >&2; exit 1; }# a target `host:dir` is remote, a plain path is localif [[ "$TARGET" == *:* ]]; thenREMOTE_HOST=${TARGET%%:*}REMOTE_DIR=${TARGET#*:}elseREMOTE_HOST=REMOTE_DIR=$TARGETfistep "[0/5] $APP → $TARGET (dry run: $DRY, skip tests: $SKIP)"echo " from $HERE"echo " url $URL"[ -x bin/hybriel ] || die "bin/hybriel is missing here"[ -f docker-compose.yml ] || die "docker-compose.yml is missing here"[ -f project.hl ] || die "project.hl is missing here"command -v rsync >/dev/null || die "rsync is not installed"# ---- 1. the gates ---------------------------------------------------------------------------if [ "$SKIP" = 1 ]; thenstep "[1/5] GATES SKIPPED"printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'printf ' !! --skip-tests: NOTHING WAS TESTED. You deploy untested code. !!\n'printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'elsestep "[1/5] gates (${#GATES[@]})"# headless Chromes that exist BEFORE the gates are not ours (other sessions' test runs)chromes() { ps -eo pid=,ppid=,args= | awk '/[h]l-browser-tier/ && /remote-debugging-port/ && !/--type=/ {print $1, $2}'; }before=" $(chromes | awk '{print $1}' | tr '\n' ' ') "# gate ports in Tracker's loreana slot 8716-8719 (the tests' defaults 8700/8701 hit other apps); env overrides winexport LC_ALL=Cexport TRACKER_GATE_PORT="${TRACKER_GATE_PORT:-8717}" TRACKER_GATE_IDENT_PORT="${TRACKER_GATE_IDENT_PORT:-8716}" TRACKER_GATE_TMDB_PORT="${TRACKER_GATE_TMDB_PORT:-8719}"export TRACKER_GATE_CHROME="${TRACKER_GATE_CHROME:-8718-8718}" TRACKER_SIGNIN_PORT="${TRACKER_SIGNIN_PORT:-8716}" TRACKER_SIGNIN_CHROME="${TRACKER_SIGNIN_CHROME:-8718-8718}"export HL_PORT_BASE="${HL_PORT_BASE:-8518}" TRACKER_COLD_MS="${TRACKER_COLD_MS:-180000}"for g in "${GATES[@]}"; doprintf ' $ %s\n' "$g"out=$(mktemp)if ! $g > "$out" 2>&1; thengrep -E '^FAIL|passed,' "$out" | sed 's/^/ /' || trueecho " (full output: $out)"die "gate failed: $g"figrep -E 'passed,' "$out" | tail -1 | sed 's/^/ /' || truerm -f "$out"done# a Chrome our gates LEFT: new since the gates began AND no longer owned by a running node testleaked=""while read -r pid ppid; do[ -z "$pid" ] && continuecase "$before" in *" $pid "*) continue ;; esacps -o args= -p "$ppid" 2>/dev/null | grep -q '^node\|/node ' && continueleaked="$leaked $pid"done < <(chromes)if [ -n "$leaked" ]; thendie "a gate left a headless Chrome (pids:$leaked; ps -eo pid,args | grep hl-browser-tier)"fifi# ---- 2. pre-deploy backup of the LIVE data (before anything is sent) ------------------------BACKUP_ROOT=${DEPLOY_BACKUP_ROOT:-/media/SLOW1TB2/deploy-backups}BACKUP_DIR="$BACKUP_ROOT/$APP"BACKUP_FILE="$BACKUP_DIR/$APP-$(date +%Y%m%d-%H%M).tgz"if [ "$DRY" = 1 ]; thenstep "[2/5] DRY RUN: backup skipped"elsestep "[2/5] backup live data ($APP) → $BACKUP_FILE"mkdir -p "$BACKUP_DIR"if [ -n "$REMOTE_HOST" ]; thenpresent=$($SSH "$REMOTE_HOST" "cd '$REMOTE_DIR' 2>/dev/null && for p in storage .sessions .env; do [ -e \"\$p\" ] && echo \"\$p\"; done; true")elsepresent=$(cd "$REMOTE_DIR" 2>/dev/null && for p in storage .sessions .env; do [ -e "$p" ] && echo "$p"; done; true)fipresent=$(printf '%s' "$present" | tr '\n' ' ' | sed 's/ *$//')if [ -z "$present" ]; thenecho " nothing to back up yet (no storage/.sessions/.env on the target)"elseecho " taring: $present"if [ -n "$REMOTE_HOST" ]; then# Order (Anton #203): directories, then every file except *.mpack (indexes, idxstate, sessions, .env), then the *.mpack# data last — a hot copy then never holds index offsets past the data it copied. tar exit 1 = "file changed as we# read it" / a file gone between find and tar (--ignore-failed-read) — a warning; the archive is checked with gzip -t.run $SSH "$REMOTE_HOST" "cd '$REMOTE_DIR' && { find $present -type d; find $present -type f ! -name '*.mpack' | LC_ALL=C sort; find $present -type f -name '*.mpack' | LC_ALL=C sort; } | tar czf - --hard-dereference --warning=no-file-changed --ignore-failed-read --no-recursion -T -; r=\$?; [ \$r -le 1 ]" > "$BACKUP_FILE" \&& gzip -t "$BACKUP_FILE" \|| { rm -f "$BACKUP_FILE"; die "backup failed (tar/ssh error) — refusing to deploy"; }elserun tar czf "$BACKUP_FILE" -C "$REMOTE_DIR" $present \|| { rm -f "$BACKUP_FILE"; die "backup failed (tar error) — refusing to deploy"; }fi[ -s "$BACKUP_FILE" ] || { rm -f "$BACKUP_FILE"; die "backup is empty — refusing to deploy"; }echo " $(du -h "$BACKUP_FILE" | cut -f1) $BACKUP_FILE"ls -1t "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | tail -n +3 | xargs -r rm -f --echo " keeping $(ls -1 "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | wc -l) archive(s) of $APP"fifi# ---- 3. rsync the code ----------------------------------------------------------------------RSYNC=(rsync -az --no-owner --no-group --itemize-changes)for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); doneif [ -n "$REMOTE_HOST" ]; thenRSYNC+=(-e "$SSH")elsemkdir -p "$REMOTE_DIR"fi# the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in itstep "[3/5] rsync preview (what would be sent)"preview=$(mktemp)run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"sed 's/^/ /' "$preview"echo " ($(grep -c . "$preview" || true) lines)"if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.)|\.log$|\.pid$' ; thendie "the preview holds a path that must never be sent (see above)"firm -f "$preview"if [ "$DRY" = 1 ]; thenstep "[3/5] DRY RUN: nothing sent"elsestep "[3/5] rsync"run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'fi# ---- 4. restart the container, without a gap ------------------------------------------------# Apollo 2026-10-25: the main container is never restarted before the standby (port 45018, compose profile "standby") answers 200.# The shared helper (worldapi-conductor/standby-swap.sh) is piped to Byrodin: it starts the standby with the new code, waits for 200,# restarts the main container, waits for 200 on 45008 and stops the standby. nginx serves from the standby meanwhile. If the standby never# comes up, nothing live was touched and the deploy stops here.SWAP=${DEPLOY_STANDBY_SWAP:-/media/STORAGE/projects/WorldAPI/worldapi-conductor/standby-swap.sh}SWAP_ARGS="tracker tracker tracker-standby / 45008"[ -f "$SWAP" ] || die "the hand-over helper is missing: $SWAP"if [ "$DRY" = 1 ]; thenstep "[4/5] DRY RUN: would hand over $CONTAINER through its standby (no gap)"echo " would run: $SWAP_ARGS with $SWAP on $TARGET"DRY_RUN=1 APP_DIR="$REMOTE_DIR" bash "$SWAP" $SWAP_ARGS 2>&1 | sed 's/^/ /' || trueelsestep "[4/5] hand over $CONTAINER through its standby (no gap)"if [ -n "$REMOTE_HOST" ]; thenprintf ' $ %s %s "APP_DIR=%s bash -s -- %s" < %s\n' "$SSH" "$REMOTE_HOST" "$REMOTE_DIR" "$SWAP_ARGS" "$SWAP" >&2$SSH "$REMOTE_HOST" "APP_DIR='$REMOTE_DIR' bash -s -- $SWAP_ARGS" < "$SWAP" || die "the hand-over failed — see the log above (the standby keeps serving if the main container did not come back)"elseAPP_DIR="$REMOTE_DIR" bash "$SWAP" $SWAP_ARGS || die "the hand-over failed — see the log above"fifi# ---- 5. the URL answers 200 -----------------------------------------------------------------if [ "$DRY" = 1 ]; thenstep "[5/5] DRY RUN: would check $URL answers 200"step "dry run done — nothing was sent, nothing restarted"exit 0fi# tracker#31 (mission 026): the boot is slower now (the search index over ~100k people, the list caches, the slug map) — nginx# answers 502 until the app listens. Ask every 2 s for up to URL_WAIT seconds (default 90), print only changes of the answer.URL_WAIT=${DEPLOY_URL_WAIT:-90}step "[5/5] $URL must answer 200 (waiting up to ${URL_WAIT} s for the boot)"code=000last=start=$(date +%s)while :; docode=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)waited=$(( $(date +%s) - start ))if [ "$code" != "$last" ] || [ "$code" = 200 ]; then echo " after ${waited} s: $code"; last=$code; fi[ "$code" = 200 ] && break[ "$waited" -ge "$URL_WAIT" ] && breaksleep 2doneif [ "$code" != 200 ]; thenif [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200, after ${URL_WAIT} s — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fidie "$URL answered $code, not 200, after ${URL_WAIT} s — look: docker logs --tail 50 $CONTAINER"fistep "deployed $APP → $TARGET, $URL answers 200"
Branches
Latest commits
- 8e174918Merge branch 'records-hm55b' into mainTracker
- b1ecee57|||PR records: HM55 stateTracker
- 28eab08cMerge branch 'records-hm55' into mainTracker
- d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
- 3059f86cMerge branch 'records-design-rule' into mainTracker
- 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
- d1390692Merge branch 'records-dp75b' into mainTracker
- a4d1a7d2|||PR records: later steps checked, branch auditTracker
- e070e16fMerge branch 'records-dp75' into mainTracker
- 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
- b9c7c3c8Merge branch 'records-dp74' into mainTracker
- 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
- b1496147Merge branch 'ap61' into mainTracker
- 2047955bMerge branch 'u12-gateports' into mainTracker
- c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker
- 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
- 0b86324aMerge branch 'records-dp73' into mainTracker
- 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker