gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit31e40b8b31e40b8bMerge dm3-media: range handling in the layouts media routemre31e40b8b/deploy.sh

9.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 - --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" -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 ---------------------------------------------------------------
  172. RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"
  173. if [ "$DRY" = 1 ]; then
  174. step "[4/5] DRY RUN: would restart $CONTAINER"
  175. if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fi
  176. else
  177. step "[4/5] restart $CONTAINER"
  178. if [ -n "$REMOTE_HOST" ]; then
  179. run $SSH "$REMOTE_HOST" "$RESTART"
  180. else
  181. run bash -c "$RESTART"
  182. fi
  183. fi
  184. # ---- 5. the URL answers 200 -----------------------------------------------------------------
  185. if [ "$DRY" = 1 ]; then
  186. step "[5/5] DRY RUN: would check $URL answers 200"
  187. step "dry run done — nothing was sent, nothing restarted"
  188. exit 0
  189. fi
  190. 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)"
  191. code=000
  192. start=$SECONDS
  193. i=0
  194. while :; do
  195. i=$((i + 1))
  196. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)
  197. echo " try $i ($((SECONDS - start)) s): $code"
  198. [ "$code" = 200 ] && break
  199. [ $((SECONDS - start)) -ge "$URL_WAIT" ] && break
  200. sleep 2
  201. done
  202. if [ "$code" != 200 ]; then
  203. if [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200 — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fi
  204. die "$URL answered $code, not 200 — look: docker logs --tail 50 $CONTAINER"
  205. fi
  206. step "deployed $APP → $TARGET, $URL answers 200"

Branches

Latest commits

  • 31e40b8bMerge dm3-media: range handling in the layouts media routemre
  • 856dcacbLayouts media route: read suffix ranges and ignore range lists and garbage, like the components route (the layouts copy still answered 416 for the last bytes)mre
  • ad5056eaMerge dm3-sync: components re-sync to c2834ddmre
  • 740e2abeRe-sync the components copy to c2834dd: media player fixes (state after a queue pick, cover-less audio, accessibility labels)mre
  • 7fe103bbMerge mp-player: the media player showcase pagemre
  • 7db43c4eMedia route: serve the showcase's media from committed files (storage/ is not in git)mre
  • f77b7d12Media player: re-sync components from 1c41293 (replay / forward 10 icons, play button surface on audio and video)mre
  • 40a9e69cMP: report, LOG linemre
  • 5b5dbf0fMedia player: the component from components.hybriel dd003e5 (sync-components), the showcase page /components/media-player with a queue, its media files served with ranges (lib/media.hl), theme rules (the seek bar, the queue's current item, the radii), the page in the overview listsmre
  • 9197159fTake components e54f83a: table lines and one-row desktop toolbar in the theme, Table button gates, a table in the md-editor demomre
  • e6322a44UX: report and LOG linemre
  • 58c2da6fUX: nav marker without bars; chat composer is one box (files-upload pick mode, showcase); comments state footer + closer reactions row; modal footer rule only for its own footer; gates for all of itmre
  • 956f107async components.hybriel 4922f9c: 44 px targets in month-view, date-picker, range-picker, pagination, modal, comments; names follow <html lang> (English default), UTC weekday fix; gate: 390 px target checks, 'edited' hit-area padding; comments showcase 'You are' is a labelled group (SY)mre
  • 49940371sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 6f7bd392gate: the phone toolbar is two even rows (E2)mre
  • 3049c082sync components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
  • b9a3f85fLOG: MLmre
  • 7979397creport ML-mobilemre
  • 85d2ed25gate: wordingmre
  • 98a311c0gate: 390 px checks for list rows, table word, edited tap target, code in titlesmre