gitoria

ident

All repositories: gitoria

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

Branches

Latest commits

  • 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
  • 48cd36bctests/migration: ports from env (MIGRATION_GATE_PORT, MIGRATION_GATE_TESTAPP_PORT); 8395/8396 were taken by a foreign servermre
  • 3d9b2fd8docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 19b7e3c3deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre