tracker
All repositories: gitoria
9.2 KB
#!/usr/bin/env bash# deploy.sh — tracker.worldapi.org: Loreana (this folder) → Byrodin. Run ON LOREANA.## ./deploy.sh gates → backup → rsync → restart the container → 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 5; --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/kinds.mjs""node tests/franchises.mjs""node theme/check-theme.mjs .")# 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' ' ') "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/^/ /'rm -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" ]; thenrun $SSH "$REMOTE_HOST" "tar czf - -C '$REMOTE_DIR' $present" > "$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 +6 | 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 ---------------------------------------------------------------RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"if [ "$DRY" = 1 ]; thenstep "[4/5] DRY RUN: would restart $CONTAINER"if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fielsestep "[4/5] restart $CONTAINER"if [ -n "$REMOTE_HOST" ]; thenrun $SSH "$REMOTE_HOST" "$RESTART"elserun bash -c "$RESTART"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
- mainmain branch
Latest commits
- eb3b9205tracker: report 031mre
- 9b5d2e89tracker mission 031: README (What it does, Test: four gates + the #32 checks, Files: theme/, new pages), STATUS (real copy, A/B load, how to repeat, open points), LOGmre
- 39950e4ctracker#32 (mission 031): the WorldAPI theme (theme/ vendored verbatim from layouts.worldapi.org 85b5654; styles.hl inherits it: accent green-dark, type colours 1-6; own base/header rules, row lines, genre-pill and inverted-button frames removed, the season foldable keeps its line; check-theme 21 -> 0, 4th deploy gate; main actions class primary) and the #32 header (theme AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst: desktop brand, search, Series|Shows|Movies|Genres|People, user icon with Unwatched..Settings, Logout; signed out the ident selector, phone the iD icon dropdown; phone menu in the sidebar overlay; marked entry by :has); /find -> /search/<q>, /genres, /people(/<letter>), /settings; main { ContentFirst { slot } } works around the hl:web one-line slot bug; gates 365/0, 32/0, 52/0, check-theme 0mre
- a386dc92tracker: reports 029 + 030mre
- 71e0fd7dtracker missions 029 + 030: README (What it does, Files, gate count), STATUS (real-copy numbers, how to repeat, open points), LOGmre
- d36ea6eatracker#34 + #35 (mission 030): Follow directly under the poster, as wide as the poster (show.hl, styles.hl); the status pill next to a series' title — TVmaze's status (new tvmazeStatus, stored by the sync's TVmaze merge) else TMDB's, TVmaze Ended + TMDB Canceled = Canceled, inverted (filled, dark text, no border), green running / yellow pending / red canceled / muted ended (shows.hl statusOf); the daily delta asks TVmaze's status of an unfollowed series TVmaze's change list names (dailysync.hl syncRunStep, sync.hl syncTvmazeStatus); the status backfill after the details repair (backfill.hl, jobs.hl statusTick; resumable, 550 ms per TVmaze request); gates 354/0, 32/0, 52/0mre
- 7d7d4487tracker#33 (mission 029): reduced titles — every title TMDB's details never went through this app (no detailsAt, no tmdbSync) is incomplete (shows.hl isIncomplete; the old tracker's migrated rows passed #26's test: 5,697 non-adult on the live copy, 691 series without seasons); the repair job does the visibly reduced first (shows.hl missingParts), the page completes one on open; a title TMDB has no poster for (The Remaining) shows the placeholder; tools/count-incomplete.hl; gate fixtures stand for synced titles (tmdbSync), tests/seed-reduced.hl + #33 checks; gates 347/0, 32/0, 52/0mre
- 661c2592tracker: report 028mre
- 27c916fatracker mission 028: README ("Code order", the new file map), STATUS (counts before/after, tests, how to repeat, open), LOGmre
- d924f398tracker mission 028: comments name the new files (sync.hl, dailysync.hl, backfill.hl, credits.hl, jobs.hl, images.hl …); tools/ref-params.py + tools/lambda-audit.py also scan lib/ (they globbed the root only), lambda-audit counts a plain `x = p` alias like `let x = p`mre
- 2e89b968tracker mission 028 (code order) 5/5 let: `let` only where a variable is reassigned — 667 never-reassigned lets became plain declarations (project.hl, lib/, components/, tools/, tests/); kept: 264 in loop bodies (a plain declaration there is 'Cannot reassign' on the 2nd pass), 234 reassigned, 27 whose name is also a member/outer/free name (a plain write would rebind it); tools/let-audit.py decides and fixes (README 'Code order'); tests/realdata-m028.{sh,mjs} = the page-output diff on a real copy; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 54796ff2tracker mission 028 (code order) 4/5 thin faces + last copies: the show page's check/follow faces call lib/watches.hl toggleWatched / toggleSeasonWatched (seasonAllWatched moved there) and lib/follows.hl toggleFollowed; both logins (header selector face, /login/callback) share lib/users.hl userOfCode; todayStr/listOf copies in components and the export readers copied into tools/migrate.hl + tools/old-short-ids.hl now once (lib/util.hl, lib/export.hl); gates 342/0, 32/0, 52/0; old-short-ids output byte-identical, migrate output identicalmre
- 06b078e3tracker mission 028 (code order) 3/5 project.hl is the map: config, routes, wiring and a feature → file index (914 → 258 lines); the background jobs (daily sync run, backfills, details repair, credits job, merge, short ids, collection seed) moved unchanged into lib/jobs.hl (a class: their state is reassigned every step, a static cannot be; one instance made after the server), the login callback into lib/users.hl, poster/photo serving into lib/images.hl, the /shows/<slug> rule into lib/shows.hl showsMovedPath; route handlers are thin wrappers; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 94716fd2tracker mission 028 (code order) 2/5 util + topics: lib/util.hl holds envOr, storageDir, postersDir, profilesDir, newId, hexDigits, todayStr, dateOr, textOr, hasId, listOr, firstOf, sortDesc once (were copied into up to 5 files); tmdbsync.hl split into tmdb.hl (TMDB/TVmaze requests), sync.hl (one title's sync), sync-helpers.hl, backfill.hl; details.hl split into details.hl, credits.hl, credits-helpers.hl (isIncomplete to shows.hl); search-helpers.hl (words, query, ranking, slugs); collections.hl (the TMDB collection seed, out of franchises.hl); deltasync.hl renamed dailysync.hl; no behaviour change: gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 186079b0tracker mission 028 (code order) 1/5 move: every root .hl except project.hl into lib/ (styles.hl into components/), import paths only; gates 342/0, 32/0, 52/0; real-copy pages identicalmre
- 4f47f181tracker: report 027mre
- dc1d4be4tracker mission 027: Hybriel master 06617221 vendored (plugin allocator fixes 3a781359 + 413f60e4); real copy RSS through first-start jobs + 400 loads flat ~2.55 GB (190aa11d 2.3 -> 5.6 GB), page times <= 1.1x; gates 342/0, 32/0, 52/0mre
- 84e1b3e1tracker: reports 025 + 026mre
- dc40d859tracker#31 (mission 026): duplicate titles merged — the 68 type+tmdbId pairs held by 157 records were the old tracker's (all migrated); merge.hl repair job (own clock, before the TMDB jobs) keeps one keeper per title (follows/watches > old short id > oldest), moves follows, watches, seasons, cast, credits, timelines, tombstones the rest (mergedInto, never deleted), slugs + short ids 301 to the keeper; stray seasons merged into their listed twin (Reacher S3 watches) or linked when watched; search import re-checks before its put; deploy.sh waits up to 90 s for 200; real copy 68 -> 0 dup ids, az5b2 follows/watches equal; gates 342/0, 32/0, 52/0mre
- 2667da05tracker#30 (mission 025): /my/ pages from slim cached title cards, episode rows and watch sets (after the jobs /my/series 1.8 s -> 0.06 s, /my/unwatched 4.1 -> 0.18 s); timeline page shows its name once; franchise widget under the poster/title; movies with TV leftovers (First Contact) go through the details repair; tools/count-tmdb-ids.hl; gates 327/0, 52/0, 32/0mre