gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3e07b1cf3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre3e07b1cf/deploy.sh

10.8 KB

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

Branches

Latest commits

  • 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
  • d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
  • 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
  • d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
  • 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
  • 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre
  • e4e7402fnotes#11: plain declarations instead of let for variables never reassigned (components/notes.hl 3, lib/jsoncheck.hl 5, lib/util.hl 2, tools/migrate-short-ids.hl 8)mre
  • 27b6a09enotes#8: Style blocks in the nested form (note-list, note-editor, .ask with their children nested, :empty as a nested pseudo-class); the same CSS rules, the pages look the samemre
  • 71a9538bnotes: B27W report, log linemre
  • 78ba0073notes: an ident access key (Authorization: Bearer idt_…) reads and writes its identity's notes through /api/me and /api/notes; gate tests/ident-access-notes.mjs (ident#27)mre
  • 3de46dacnotes: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 73+5 failing → 78 passedmre
  • 5909d458notes: MdEditor from components 59704ce (text on the clipboard always pastes, a file manager copy still attaches; pipe rows without a delimiter row; tickets#49, notes#5)mre
  • 98bd6a98N5b: pipe rows without a delimiter row are a table (MdEditor ad4e929, plain copy); gate tests/dashboard-table.mjs; reportmre
  • dbf93319N5 report: components gate rerun 613 passed, 0 failedmre
  • 3a8bc0d2N5: empty Table-button table is written as a real pipe table (MdEditor 4bd1112, plain copy); gate tests/table-button.mjs; reportmre
  • c16bd443N5: step 1 report (tables pass locally; his DASHBOARD note has no delimiter row)mre
  • 6091320anotes: MdEditor 7437e32 (surface drawn at once when the page is claimed); gate measures claim-to-text on 5 note loads at 1280 and 390mre
  • 0aa9277enotes: move each component's styles into its own Style block (shell and header selector in main.hl, list, editor frame and delete question in notes.hl); styles.hl keeps the theme inherit, the accent and the message colour; .gitignore ignores a bin symlink too; tests/shots.mjs for the pixel comparemre
  • 9ba01de3notes: write the standby service out in full so the boot gate can read the main servicemre
  • 98cab40anotes: standby service on its port plus 10 and a deploy that hands over through it without a gapmre