gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9bce1f659bce1f65tracker mission 032: STATUS gate files + the hour-boundary flakemre9bce1f65/deploy.sh

9.2 KB

  1. #!/usr/bin/env bash
  2. # deploy.sh — tracker.worldapi.org: Loreana (this folder) → Byrodin. Run ON LOREANA.
  3. #
  4. # ./deploy.sh gates → backup → rsync → restart the container → public URL 200
  5. # ./deploy.sh --dry-run gates → rsync -n (shows what WOULD be sent), no backup, no restart, no URL check
  6. # ./deploy.sh --skip-tests skips the gates (LOUD warning) — only when you know why
  7. # ./deploy.sh --target DIR|HOST:DIR another destination (default below); a local DIR is
  8. # how the script is tested without touching Byrodin
  9. # ./deploy.sh --url URL the URL that must answer 200 after the restart (asked for up to 90 s)
  10. # (env: DEPLOY_TARGET, DEPLOY_URL, DEPLOY_SSH override the same defaults; DEPLOY_URL_WAIT the seconds the URL may take)
  11. # (backup: tars storage/.sessions/.env that exist on the target to Loreana's
  12. # /media/SLOW1TB2/deploy-backups/<app>/, keeps newest 5; --target DIR backs up DIR instead)
  13. #
  14. # THE FIRST DEPLOY is done by the architect on Byrodin (folder, .env with this app's ident
  15. # API key + secret — registered once in ident's /apps for origin https://tracker.worldapi.org
  16. # — nginx vhost, cert, DNS). This script only updates the CODE: storage/, .sessions/, .env,
  17. # .scratch/, server.*, tests/ fixtures and logs are never sent, so live data on Byrodin is
  18. # never touched. No --delete: a file removed here stays on Byrodin (harmless).
  19. set -euo pipefail
  20. # ---- the app ------------------------------------------------------------------------------
  21. APP=tracker.worldapi.org
  22. CONTAINER=tracker.worldapi.org
  23. [email protected]:/CONTAINERS/projects/tracker.worldapi.org
  24. DEFAULT_URL=https://tracker.worldapi.org/
  25. GATES=(
  26. "node tests/browser.mjs"
  27. "node tests/kinds.mjs"
  28. "node tests/franchises.mjs"
  29. "node theme/check-theme.mjs ."
  30. )
  31. # NEVER SENT (rsync patterns; a leading / anchors at the app folder)
  32. EXCLUDES=(
  33. /.git/ /.gitignore
  34. /storage/ /.sessions/ /.env /.env.* /.scratch/ /server.* '*.log' '*.pid' node_modules/
  35. )
  36. # ---------------------------------------------------------------------------------------------
  37. DRY=0
  38. SKIP=0
  39. TARGET=${DEPLOY_TARGET:-$DEFAULT_TARGET}
  40. URL=${DEPLOY_URL:-$DEFAULT_URL}
  41. # Loreana's ssh config may not apply to Byrodin: -F /dev/null (ident STATUS)
  42. SSH=${DEPLOY_SSH:-ssh -F /dev/null -o BatchMode=yes -o ConnectTimeout=15}
  43. usage() { sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; }
  44. while [ $# -gt 0 ]; do
  45. case "$1" in
  46. --dry-run) DRY=1 ;;
  47. --skip-tests) SKIP=1 ;;
  48. --target) TARGET=${2:?--target needs a value}; shift ;;
  49. --target=*) TARGET=${1#--target=} ;;
  50. --url) URL=${2:?--url needs a value}; shift ;;
  51. --url=*) URL=${1#--url=} ;;
  52. -h|--help) usage; exit 0 ;;
  53. *) echo "deploy: unknown argument: $1" >&2; usage >&2; exit 2 ;;
  54. esac
  55. shift
  56. done
  57. HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
  58. cd "$HERE"
  59. step() { printf '\n==> %s\n' "$*"; }
  60. run() { printf ' $ %s\n' "$*" >&2; "$@"; }
  61. die() { printf '\ndeploy: REFUSED — %s\n' "$*" >&2; exit 1; }
  62. # a target `host:dir` is remote, a plain path is local
  63. if [[ "$TARGET" == *:* ]]; then
  64. REMOTE_HOST=${TARGET%%:*}
  65. REMOTE_DIR=${TARGET#*:}
  66. else
  67. REMOTE_HOST=
  68. REMOTE_DIR=$TARGET
  69. fi
  70. step "[0/5] $APP → $TARGET (dry run: $DRY, skip tests: $SKIP)"
  71. echo " from $HERE"
  72. echo " url $URL"
  73. [ -x bin/hybriel ] || die "bin/hybriel is missing here"
  74. [ -f docker-compose.yml ] || die "docker-compose.yml is missing here"
  75. [ -f project.hl ] || die "project.hl is missing here"
  76. command -v rsync >/dev/null || die "rsync is not installed"
  77. # ---- 1. the gates ---------------------------------------------------------------------------
  78. if [ "$SKIP" = 1 ]; then
  79. step "[1/5] GATES SKIPPED"
  80. printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  81. printf ' !! --skip-tests: NOTHING WAS TESTED. You deploy untested code. !!\n'
  82. printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  83. else
  84. step "[1/5] gates (${#GATES[@]})"
  85. # headless Chromes that exist BEFORE the gates are not ours (other sessions' test runs)
  86. chromes() { ps -eo pid=,ppid=,args= | awk '/[h]l-browser-tier/ && /remote-debugging-port/ && !/--type=/ {print $1, $2}'; }
  87. before=" $(chromes | awk '{print $1}' | tr '\n' ' ') "
  88. for g in "${GATES[@]}"; do
  89. printf ' $ %s\n' "$g"
  90. out=$(mktemp)
  91. if ! $g > "$out" 2>&1; then
  92. grep -E '^FAIL|passed,' "$out" | sed 's/^/ /' || true
  93. echo " (full output: $out)"
  94. die "gate failed: $g"
  95. fi
  96. grep -E 'passed,' "$out" | tail -1 | sed 's/^/ /' || true
  97. rm -f "$out"
  98. done
  99. # a Chrome our gates LEFT: new since the gates began AND no longer owned by a running node test
  100. leaked=""
  101. while read -r pid ppid; do
  102. [ -z "$pid" ] && continue
  103. case "$before" in *" $pid "*) continue ;; esac
  104. ps -o args= -p "$ppid" 2>/dev/null | grep -q '^node\|/node ' && continue
  105. leaked="$leaked $pid"
  106. done < <(chromes)
  107. if [ -n "$leaked" ]; then
  108. die "a gate left a headless Chrome (pids:$leaked; ps -eo pid,args | grep hl-browser-tier)"
  109. fi
  110. fi
  111. # ---- 2. pre-deploy backup of the LIVE data (before anything is sent) ------------------------
  112. BACKUP_ROOT=${DEPLOY_BACKUP_ROOT:-/media/SLOW1TB2/deploy-backups}
  113. BACKUP_DIR="$BACKUP_ROOT/$APP"
  114. BACKUP_FILE="$BACKUP_DIR/$APP-$(date +%Y%m%d-%H%M).tgz"
  115. if [ "$DRY" = 1 ]; then
  116. step "[2/5] DRY RUN: backup skipped"
  117. else
  118. step "[2/5] backup live data ($APP) → $BACKUP_FILE"
  119. mkdir -p "$BACKUP_DIR"
  120. if [ -n "$REMOTE_HOST" ]; then
  121. present=$($SSH "$REMOTE_HOST" "cd '$REMOTE_DIR' 2>/dev/null && for p in storage .sessions .env; do [ -e \"\$p\" ] && echo \"\$p\"; done; true")
  122. else
  123. present=$(cd "$REMOTE_DIR" 2>/dev/null && for p in storage .sessions .env; do [ -e "$p" ] && echo "$p"; done; true)
  124. fi
  125. present=$(printf '%s' "$present" | tr '\n' ' ' | sed 's/ *$//')
  126. if [ -z "$present" ]; then
  127. echo " nothing to back up yet (no storage/.sessions/.env on the target)"
  128. else
  129. echo " taring: $present"
  130. if [ -n "$REMOTE_HOST" ]; then
  131. run $SSH "$REMOTE_HOST" "tar czf - -C '$REMOTE_DIR' $present" > "$BACKUP_FILE" \
  132. || { rm -f "$BACKUP_FILE"; die "backup failed (tar/ssh error) — refusing to deploy"; }
  133. else
  134. run tar czf "$BACKUP_FILE" -C "$REMOTE_DIR" $present \
  135. || { rm -f "$BACKUP_FILE"; die "backup failed (tar error) — refusing to deploy"; }
  136. fi
  137. [ -s "$BACKUP_FILE" ] || { rm -f "$BACKUP_FILE"; die "backup is empty — refusing to deploy"; }
  138. echo " $(du -h "$BACKUP_FILE" | cut -f1) $BACKUP_FILE"
  139. ls -1t "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | tail -n +6 | xargs -r rm -f --
  140. echo " keeping $(ls -1 "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | wc -l) archive(s) of $APP"
  141. fi
  142. fi
  143. # ---- 3. rsync the code ----------------------------------------------------------------------
  144. RSYNC=(rsync -az --no-owner --no-group --itemize-changes)
  145. for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); done
  146. if [ -n "$REMOTE_HOST" ]; then
  147. RSYNC+=(-e "$SSH")
  148. else
  149. mkdir -p "$REMOTE_DIR"
  150. fi
  151. # the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in it
  152. step "[3/5] rsync preview (what would be sent)"
  153. preview=$(mktemp)
  154. run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"
  155. sed 's/^/ /' "$preview"
  156. echo " ($(grep -c . "$preview" || true) lines)"
  157. if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.)|\.log$|\.pid$' ; then
  158. die "the preview holds a path that must never be sent (see above)"
  159. fi
  160. rm -f "$preview"
  161. if [ "$DRY" = 1 ]; then
  162. step "[3/5] DRY RUN: nothing sent"
  163. else
  164. step "[3/5] rsync"
  165. run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'
  166. fi
  167. # ---- 4. restart the container ---------------------------------------------------------------
  168. RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"
  169. if [ "$DRY" = 1 ]; then
  170. step "[4/5] DRY RUN: would restart $CONTAINER"
  171. if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fi
  172. else
  173. step "[4/5] restart $CONTAINER"
  174. if [ -n "$REMOTE_HOST" ]; then
  175. run $SSH "$REMOTE_HOST" "$RESTART"
  176. else
  177. run bash -c "$RESTART"
  178. fi
  179. fi
  180. # ---- 5. the URL answers 200 -----------------------------------------------------------------
  181. if [ "$DRY" = 1 ]; then
  182. step "[5/5] DRY RUN: would check $URL answers 200"
  183. step "dry run done — nothing was sent, nothing restarted"
  184. exit 0
  185. fi
  186. # tracker#31 (mission 026): the boot is slower now (the search index over ~100k people, the list caches, the slug map) — nginx
  187. # answers 502 until the app listens. Ask every 2 s for up to URL_WAIT seconds (default 90), print only changes of the answer.
  188. URL_WAIT=${DEPLOY_URL_WAIT:-90}
  189. step "[5/5] $URL must answer 200 (waiting up to ${URL_WAIT} s for the boot)"
  190. code=000
  191. last=
  192. start=$(date +%s)
  193. while :; do
  194. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)
  195. waited=$(( $(date +%s) - start ))
  196. if [ "$code" != "$last" ] || [ "$code" = 200 ]; then echo " after ${waited} s: $code"; last=$code; fi
  197. [ "$code" = 200 ] && break
  198. [ "$waited" -ge "$URL_WAIT" ] && break
  199. sleep 2
  200. done
  201. if [ "$code" != 200 ]; then
  202. if [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200, after ${URL_WAIT} s — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fi
  203. die "$URL answered $code, not 200, after ${URL_WAIT} s — look: docker logs --tail 50 $CONTAINER"
  204. fi
  205. step "deployed $APP → $TARGET, $URL answers 200"

Branches

Latest commits

  • 9bce1f65tracker mission 032: STATUS gate files + the hour-boundary flakemre
  • 718bfb89tracker#37 (mission 032): /people = everyone, last updated first (updatedAt stamped by the person fill; view built at boot, touched people first at once), photo + name tiles (person colour) with the /movies pagination, /people/<letter> removed; photo = our file, tmdbProfile, a cast/crew entry's profile (in-memory map at boot), else the new 'no photo' placeholder; new cast/crew/created_by people keep tmdbProfile; search people rows with the photo; /settings = the heading only; util.hl sortDesc starts from sorted runs (same result, 105k: 1.6 s -> 0.15 s); gates 369/0, 32/0, 52/0, check-theme 0; README/STATUS/LOGmre
  • 96ba683adeploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the scriptmre
  • 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