gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5c481bfd5c481bfdident#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)mre5c481bfd/deploy.sh

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

  • 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
  • 6d4f996esessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 029eb5e5deploy: security gate (tests/security.mjs)mre
  • d3c065a8security audit (SI): uploadMax 0, Secure __Host- cookie behind https, headers on function routes/files, page CSP+referrer meta, app/identity caps, tests/security.mjs, reportmre
  • 5561a0cbreport I4-mobilemre
  • 4ca2ed20404 page in the shell (viewport, status 404, way home); phone: account actions live in the user menu so the open menu covers nothing; mobile gate; signoutall waits for a cold startmre
  • 9baad745tests: browser gate waits for the reloaded document (offline reload race under CPU throttle); HL_CPU_THROTTLE knobmre
  • b96796bdtests: wait for hydration before real clicks after a navigation (H2)mre
  • 9722964fre-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
  • c9b196c9tests/iplimit: wait for the welcome form itself after B's first login (identities list renders before it); mission 017 reportmre
  • 72e0f587ident#26: identity page with "Used in" (app, since, last use, Notif. chip, empty state); lastLogin recorded at exchange; gates + lisbeth E2E; mission 016 reportmre
  • 94576fbcident#26 WIP: identity page /identity/:iid with "Used in" (app, since, last use, Notif. chip), lastLogin recorded at exchange, "Used in…" link on the identities list; apps gate 4b, e2e-usedin.mjsmre
  • 349cb502tests/invites: wait for hydration on the code page before entering the code (native GET submit raced the welcome form); mission 015 reportmre
  • d1bf4720tests: no hard-coded ports — every gate's ports and fixture origins come from <GATE>_PORT / _CHROME env (defaults unchanged; Bob/fixture origins follow, selector cookie name too)mre
  • 6280c92fre-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
  • 147744bftests/migration: the fixture app origin follows MIGRATION_GATE_TESTAPP_PORT (oldstore-009 OLD_TESTAPP)mre