gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit97110ad997110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre97110ad9/deploy.sh

10.5 KB

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

Branches

Latest commits

  • 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
  • ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
  • 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
  • b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 8d9ed0b8Re-vendor complete Hybriel plugins and runtime to day39mre
  • ebd00b6cNest caller slot styles in three-panemre
  • 009991efNest caller slot styles in list-firstmre
  • 494d75d4Nest caller slot styles in app-sidebarmre
  • e5571680Align all plugin sources with Hybriel day38bmre
  • 5d204c46Re-vendor layouts to Hybriel set day38bmre
  • 17e0f03eNest html-prefixed theme component overridesmre
  • e54e735eFormat plain theme elements with nested rules and bare mediamre
  • 547f834eRecord LY7 deployment and live verificationmre
  • fa4600b1Link caller-slot style exceptions to hybriel#270mre
  • 413b11e1Record corrected LY7 nesting, exact CSS and Chrome proofmre
  • b810453etracker-demo: nest child and compound selectors in Stylemre
  • 0b5b1d61notes-demo: nest child and compound selectors in Stylemre
  • ab22bdc2mail-demo: nest child and compound selectors in Stylemre
  • fe2d8de9home: nest child and compound selectors in Stylemre
  • e631791buser-menu: nest child and compound selectors in Stylemre