gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite999b0d3e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mree999b0d3/deploy.sh

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

Branches

Latest commits

  • e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
  • 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
  • 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