gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchhl-standard-36d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlashl-standard-3/deploy.sh

11.3 KB

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

Branches

Latest commits

  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
  • 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
  • cc759328Merge sb3-standby: calendar deploys through its standbymre
  • f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre
  • 229643f7Merge branch 'cal-14'mre
  • 1110b26fcalendar#14: the month name no longer breaks into two lines on a phone (Reminder settings drops to its own row when the header is too narrow), gate checks for one-line title and all header controls on screenmre
  • 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre