gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb7e11e3bb7e11e3bvirtual-list: the first resetKey is the baseline, so centerId and scrollTop keep their place at mount; gate for itAtlasb7e11e3b/deploy.sh

10.7 KB

  1. #!/usr/bin/env bash
  2. # deploy.sh — components.hybriel.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
  10. # (env: DEPLOY_TARGET, DEPLOY_URL, DEPLOY_SSH override the same defaults; DEPLOY_URL_WAIT seconds the
  11. # URL may take after the restart, default 120 — a cold start compiles the app first, 18–41 s, hybriel#148)
  12. # (backup: tars storage/.sessions/.env that exist on the target to Loreana's
  13. # /media/SLOW1TB2/deploy-backups/<app>/, keeps newest 5; --target DIR backs up DIR instead)
  14. #
  15. # THE FIRST DEPLOY is done by the architect on Byrodin (folder, data, nginx vhost, cert,
  16. # DNS). This script only updates the CODE: storage/, .sessions/, .env, .scratch/, server.*,
  17. # testapp/ and logs are never sent, so live data on Byrodin is never touched.
  18. # No --delete: a file removed here stays on Byrodin (harmless — nothing imports it).
  19. set -euo pipefail
  20. # ---- the app ------------------------------------------------------------------------------
  21. APP=components.hybriel.worldapi.org
  22. CONTAINER=components.hybriel.worldapi.org
  23. [email protected]:/CONTAINERS/projects/components.hybriel.worldapi.org
  24. DEFAULT_URL=https://components.hybriel.worldapi.org/
  25. GATES=(
  26. "node tests/browser.mjs"
  27. "node tests/virtual-list.mjs"
  28. "node tests/virtual-list-reset.mjs"
  29. "env VL_OPTIONS=center VL_KEY=1 node tests/virtual-list.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.* /testapp/
  35. '*.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. URL_WAIT=${DEPLOY_URL_WAIT:-120}
  43. # Loreana's ssh config may not apply to Byrodin: -F /dev/null (ident STATUS)
  44. SSH=${DEPLOY_SSH:-ssh -F /dev/null -o BatchMode=yes -o ConnectTimeout=15}
  45. usage() { sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; }
  46. while [ $# -gt 0 ]; do
  47. case "$1" in
  48. --dry-run) DRY=1 ;;
  49. --skip-tests) SKIP=1 ;;
  50. --target) TARGET=${2:?--target needs a value}; shift ;;
  51. --target=*) TARGET=${1#--target=} ;;
  52. --url) URL=${2:?--url needs a value}; shift ;;
  53. --url=*) URL=${1#--url=} ;;
  54. -h|--help) usage; exit 0 ;;
  55. *) echo "deploy: unknown argument: $1" >&2; usage >&2; exit 2 ;;
  56. esac
  57. shift
  58. done
  59. HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
  60. cd "$HERE"
  61. step() { printf '\n==> %s\n' "$*"; }
  62. run() { printf ' $ %s\n' "$*" >&2; "$@"; }
  63. die() { printf '\ndeploy: REFUSED — %s\n' "$*" >&2; exit 1; }
  64. # a target `host:dir` is remote, a plain path is local
  65. if [[ "$TARGET" == *:* ]]; then
  66. REMOTE_HOST=${TARGET%%:*}
  67. REMOTE_DIR=${TARGET#*:}
  68. else
  69. REMOTE_HOST=
  70. REMOTE_DIR=$TARGET
  71. fi
  72. step "[0/5] $APP → $TARGET (dry run: $DRY, skip tests: $SKIP)"
  73. echo " from $HERE"
  74. echo " url $URL"
  75. [ -x bin/hybriel ] || die "bin/hybriel is missing here"
  76. [ -f docker-compose.yml ] || die "docker-compose.yml is missing here"
  77. [ -f project.hl ] || die "project.hl is missing here"
  78. command -v rsync >/dev/null || die "rsync is not installed"
  79. # ---- 1. the gates ---------------------------------------------------------------------------
  80. if [ "$SKIP" = 1 ]; then
  81. step "[1/5] GATES SKIPPED"
  82. printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  83. printf ' !! --skip-tests: NOTHING WAS TESTED. You deploy untested code. !!\n'
  84. printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  85. else
  86. step "[1/5] gates (${#GATES[@]})"
  87. # headless Chromes that exist BEFORE the gates are not ours (other sessions' test runs, e.g. Anton's)
  88. chromes() { ps -eo pid=,ppid=,args= | awk '/[h]l-browser-tier/ && /remote-debugging-port/ && !/--type=/ {print $1, $2}'; }
  89. before=" $(chromes | awk '{print $1}' | tr '\n' ' ') "
  90. for g in "${GATES[@]}"; do
  91. printf ' $ %s\n' "$g"
  92. out=$(mktemp)
  93. if ! $g > "$out" 2>&1; then
  94. grep -E '^FAIL|passed,' "$out" | sed 's/^/ /' || true
  95. echo " (full output: $out)"
  96. die "gate failed: $g"
  97. fi
  98. grep -E 'passed,' "$out" | tail -1 | sed 's/^/ /'
  99. rm -f "$out"
  100. done
  101. # a Chrome our gates LEFT: new since the gates began AND no longer owned by a running node test
  102. # (a Chrome whose parent is a live node process belongs to another session's test run right now)
  103. leaked=""
  104. while read -r pid ppid; do
  105. [ -z "$pid" ] && continue
  106. case "$before" in *" $pid "*) continue ;; esac
  107. ps -o args= -p "$ppid" 2>/dev/null | grep -q '^node\|/node ' && continue
  108. leaked="$leaked $pid"
  109. done < <(chromes)
  110. if [ -n "$leaked" ]; then
  111. die "a gate left a headless Chrome (pids:$leaked; ps -eo pid,args | grep hl-browser-tier)"
  112. fi
  113. fi
  114. # ---- 2. pre-deploy backup of the LIVE data (before anything is sent) ------------------------
  115. BACKUP_ROOT=${DEPLOY_BACKUP_ROOT:-/media/SLOW1TB2/deploy-backups}
  116. BACKUP_DIR="$BACKUP_ROOT/$APP"
  117. BACKUP_FILE="$BACKUP_DIR/$APP-$(date +%Y%m%d-%H%M).tgz"
  118. if [ "$DRY" = 1 ]; then
  119. step "[2/5] DRY RUN: backup skipped"
  120. else
  121. step "[2/5] backup live data ($APP) → $BACKUP_FILE"
  122. mkdir -p "$BACKUP_DIR"
  123. if [ -n "$REMOTE_HOST" ]; then
  124. present=$($SSH "$REMOTE_HOST" "cd '$REMOTE_DIR' 2>/dev/null && for p in storage .sessions .env; do [ -e \"\$p\" ] && echo \"\$p\"; done; true")
  125. else
  126. present=$(cd "$REMOTE_DIR" 2>/dev/null && for p in storage .sessions .env; do [ -e "$p" ] && echo "$p"; done; true)
  127. fi
  128. present=$(printf '%s' "$present" | tr '\n' ' ' | sed 's/ *$//')
  129. if [ -z "$present" ]; then
  130. echo " nothing to back up yet (no storage/.sessions/.env on the target)"
  131. else
  132. echo " taring: $present"
  133. if [ -n "$REMOTE_HOST" ]; then
  134. # Order (Anton #203): directories, then every file except *.mpack (indexes, idxstate, sessions, .env), then the *.mpack
  135. # data last — a hot copy then never holds index offsets past the data it copied. tar exit 1 = "file changed as we
  136. # read it" / a file gone between find and tar (--ignore-failed-read) — a warning; the archive is checked with gzip -t.
  137. 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" \
  138. || { rm -f "$BACKUP_FILE"; die "backup failed (tar/ssh error) — refusing to deploy"; }
  139. else
  140. run tar czf "$BACKUP_FILE" --hard-dereference -C "$REMOTE_DIR" $present \
  141. || { rm -f "$BACKUP_FILE"; die "backup failed (tar error) — refusing to deploy"; }
  142. fi
  143. [ -s "$BACKUP_FILE" ] || { rm -f "$BACKUP_FILE"; die "backup is empty — refusing to deploy"; }
  144. echo " $(du -h "$BACKUP_FILE" | cut -f1) $BACKUP_FILE"
  145. ls -1t "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | tail -n +6 | xargs -r rm -f --
  146. echo " keeping $(ls -1 "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | wc -l) archive(s) of $APP"
  147. fi
  148. fi
  149. # ---- 3. rsync the code ----------------------------------------------------------------------
  150. RSYNC=(rsync -az --no-owner --no-group --itemize-changes)
  151. for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); done
  152. if [ -n "$REMOTE_HOST" ]; then
  153. RSYNC+=(-e "$SSH")
  154. else
  155. mkdir -p "$REMOTE_DIR"
  156. fi
  157. # the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in it
  158. step "[3/5] rsync preview (what would be sent)"
  159. preview=$(mktemp)
  160. run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"
  161. sed 's/^/ /' "$preview"
  162. echo " ($(grep -c . "$preview" || true) lines)"
  163. if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.|testapp/)|\.log$|\.pid$' ; then
  164. die "the preview holds a path that must never be sent (see above)"
  165. fi
  166. rm -f "$preview"
  167. if [ "$DRY" = 1 ]; then
  168. step "[3/5] DRY RUN: nothing sent"
  169. else
  170. step "[3/5] rsync"
  171. run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'
  172. fi
  173. # ---- 4. restart the container, without a gap ------------------------------------------------
  174. # Apollo 2026-10-25: the main container is never restarted before the standby (45016, compose profile "standby") answers 200.
  175. # The shared helper (worldapi-conductor/standby-swap.sh) is piped to Byrodin: it starts the standby with the new code, waits for 200,
  176. # restarts the main container, waits for 200 on 45006 and stops the standby. nginx serves from the standby meanwhile. If the standby never
  177. # comes up, nothing live was touched and the deploy stops here.
  178. SWAP=${DEPLOY_STANDBY_SWAP:-/media/STORAGE/projects/WorldAPI/worldapi-conductor/standby-swap.sh}
  179. SWAP_ARGS="components components components-standby /month-view 45006"
  180. [ -f "$SWAP" ] || die "the hand-over helper is missing: $SWAP"
  181. if [ "$DRY" = 1 ]; then
  182. step "[4/5] DRY RUN: would hand over $CONTAINER through its standby (no gap)"
  183. echo " would run: $SWAP_ARGS with $SWAP on $TARGET"
  184. DRY_RUN=1 APP_DIR="$REMOTE_DIR" bash "$SWAP" $SWAP_ARGS 2>&1 | sed 's/^/ /' || true
  185. else
  186. step "[4/5] hand over $CONTAINER through its standby (no gap)"
  187. if [ -n "$REMOTE_HOST" ]; then
  188. printf ' $ %s %s "APP_DIR=%s bash -s -- %s" < %s\n' "$SSH" "$REMOTE_HOST" "$REMOTE_DIR" "$SWAP_ARGS" "$SWAP" >&2
  189. $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)"
  190. else
  191. APP_DIR="$REMOTE_DIR" bash "$SWAP" $SWAP_ARGS || die "the hand-over failed — see the log above"
  192. fi
  193. fi
  194. # ---- 5. the URL answers 200 -----------------------------------------------------------------
  195. if [ "$DRY" = 1 ]; then
  196. step "[5/5] DRY RUN: would check $URL answers 200"
  197. step "dry run done — nothing was sent, nothing restarted"
  198. exit 0
  199. fi
  200. step "[5/5] $URL must answer 200 (up to ${URL_WAIT}s: a new Hybriel compiles the app at its first start, 18–41 s, hybriel#148)"
  201. code=000
  202. start=$SECONDS
  203. i=0
  204. while :; do
  205. i=$((i + 1))
  206. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)
  207. echo " try $i ($((SECONDS - start)) s): $code"
  208. [ "$code" = 200 ] && break
  209. [ $((SECONDS - start)) -ge "$URL_WAIT" ] && break
  210. sleep 2
  211. done
  212. if [ "$code" != 200 ]; then
  213. if [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200 — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fi
  214. die "$URL answered $code, not 200 — look: docker logs --tail 50 $CONTAINER"
  215. fi
  216. step "deployed $APP → $TARGET, $URL answers 200"

Branches

Latest commits

  • b7e11e3bvirtual-list: the first resetKey is the baseline, so centerId and scrollTop keep their place at mount; gate for itAtlas
  • 7e428ba6Re-vendor Hybriel day72 (day73 withdrawn: minifier breaks write sets)Atlas
  • a06fc778Reset virtual-list window when the host changes resetKeyAtlas
  • 3aab598cRe-vendor complete Hybriel day73 set for virtual-list resetAtlas
  • 337ca075MD1 gate check measures frames in the page, not milliseconds from outside, and takes the middle load (components#30)mre
  • f5f131c5Record AP29 autoplay comparisons and passing gatesmre
  • 51c38187Gate media autoplay on first load and after client mountmre
  • a3f2223dRecord successful B44 deployment and live proofmre
  • 06c1e021Record passing B44 browser rerunmre
  • c9861533Record B44 component proof and browser gate blockermre
  • 1b7413beIgnore detached media events and space demo option outputsmre
  • ca3b4959Re-vendor complete Hybriel plugins and runtime to day44mre
  • df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
  • 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
  • 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
  • 9b872cedRecord IC28 deployment and live icon verificationmre
  • 46fefaa7Count the icons entry in the offline home-page checkmre
  • c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre
  • 5e090ffdRecord IC28 review evidence and gate resultsmre