gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5d2c385a5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre5d2c385a/deploy.sh

11.2 KB

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

Branches

Latest commits

  • 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
  • 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
  • 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
  • a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
  • 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
  • 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
  • 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
  • a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
  • 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
  • c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre
  • e307d69agitoria: say what is per process during the hand-overmre
  • f0cbe6a6gitoria: standby service on port 45014 and a deploy that hands over through it without a gapmre
  • 727cd083gitoria#25: README: vendor notes for Hybriel c1b1010f and the page cachemre
  • 61b72dedgitoria#25: re-vendor Hybriel master c1b1010f (W149 page cache), key the repo Readme page by slug and main commit, extend the readme-cache gatemre
  • 5b0b4b9ereadme-cache gate: use the security gate's ports when no own ports are givenmre
  • bc8f20d9gitoria#25: re-vendor Hybriel c09538bb with the W141 render cache, cache the homepage per commit, add the readme-cache gatemre
  • 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
  • 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
  • 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
  • 2a2fdd77gs: C2 check before cookie experimentsmre