gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita4887ea3a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mrea4887ea3/deploy.sh

11.0 KB

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

Branches

Latest commits

  • a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
  • d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
  • ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
  • 80965c08ident#28: README says the deploy goes through the standbymre
  • 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
  • a544b261ident#28: README names the new vendored Hybrielmre
  • 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
  • 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
  • f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre
  • d8be66ebident: report and log line for the widget cache and frame height changemre
  • 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre
  • a22d2daaident#31: the sign-in frame is no taller than the tallest step needs (plain CSS height per width), gate check for itmre
  • a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemre
  • 5c481bfdident#31: sign in to ident inside the selector's panel (email, code, identity in an iframe; a new address goes to ident in the same tab and comes back)mre
  • 061abfe2ident: the apps gate waits until the test app's login button stops moving before it clicks (the page grows after load and the click missed about every second run)mre
  • 45f7e4daident: the user menu's Sign out waits for the server before it reloads (the apps gate failed because the session could still be signed in)mre
  • f07658c7ident: home page shows the account once (account bar removed, the user menu carries email, Sign out, Sign out everywhere); wildcard origins https://*.domain for apps on many subdomains; gates follow (WIP: gates not re-run after the last edits)mre
  • f2c43bbbtheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre