gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchb27b3d43c187ident-access: server-side check of an ident access key (Bearer or Basic password), asks ident on every call, README, gate tests/ident-access.mjs (ident#27 app side)mreb27b/deploy.sh

10.5 KB

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

Branches

Latest commits

  • 3d43c187ident-access: server-side check of an ident access key (Bearer or Basic password), asks ident on every call, README, gate tests/ident-access.mjs (ident#27 app side)mre
  • 59704ce1Merge branch 'n5b-pipes'mre
  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • ad4e929bMdEditor: pipe rows without a delimiter row are a table (first row = header, short rows padded, written back without an invented | --- | line) (notes#5)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre
  • c5442043components: no jobs switch needed in the standbymre
  • 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
  • c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
  • 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
  • ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
  • 9a4f9b31Merge mp-player: media served from the committed filesmre
  • ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
  • b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
  • 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
  • 9e1ab228MP: report, LOG line, STATUS entrymre
  • dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre