gitoriaLog in with ident

tracker

All repositories: gitoria

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

Branches

Latest commits

  • b638e99dMerge t38 (tracker#38 pagination, #35 Returning/Airing label) into main: LOG/STATUS keep both sides; pager gate follows #37's /people (everyone, last updated first: seed updatedAt); gates pager 229/0, browser 374/0mre
  • f8ffa4dbtracker: report 032 + The Remaining + #39mre
  • 7565a863tracker: LOG timemre
  • b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mre
  • 9448d643tracker#35 follow-up (mission 033): TVmaze 'Running' is labelled 'Returning', or 'Airing' while a non-special episode of the two newest seasons is released within today +-7 days (data unchanged); gate fixtures Running/Airing/Aired + a special; browser 366/0, kinds 32/0, franchises 52/0, pager 229/0, check-theme 0mre
  • 8751adb8tracker: report 032mre
  • 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
  • 03ec792ftracker#38 (mission 033): pagination goes exactly to the clicked page — tilelist read the clicked button's text after pagination.hl's own handler had rebuilt the buttons (real clicks only); now li.current, else the button's own text; new gate tests/pager.mjs (5 lists x 11 pages, 390/1280, real + script clicks, Back/Forward) 229/0; browser 365/0, kinds 32/0, franchises 52/0, check-theme 0mre
  • 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