gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd1ae2701d1ae2701sync components.hybriel 4922f9c: modal and pagination 44 px targets (vendored copies, verbatim) (SY)mred1ae2701/deploy.sh

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

Branches

Latest commits

  • d1ae2701sync components.hybriel 4922f9c: modal and pagination 44 px targets (vendored copies, verbatim) (SY)mre
  • 05d89fd0deploy: security gate (tests/security.mjs)mre
  • 2ae8a47bMerge branch 'sk-sec'mre
  • 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 944ad51eSK: report reports/SK-sec.md, LOGsk
  • 415487c1SK: import budget per user + id type check, gate checkssk
  • 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
  • f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
  • d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
  • 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
  • 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
  • 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre