gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3e5cfd593e5cfd59Merge branch 'calendar28-fix' into mainAtlas3e5cfd59/deploy.sh

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

Branches

Latest commits

  • 3e5cfd59Merge branch 'calendar28-fix' into mainAtlas
  • 692346ed|||PR calendar28: handle an already-subscribed notification device in push checksAtlas
  • bc2d7776|||PR WIP calendar28: preserve toggle focus and chip specificityAtlas
  • 189c4c8c|||PR WIP calendar28: replace visual class state with View conditionsAtlas
  • fff2f537Merge branch 'calendar31-lib' into mainAtlas
  • 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
  • a753b0ab|||PR move shared calendar logic to libAtlas
  • b32a921dMerge branch 'vendor-day72' into mainAtlas
  • 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
  • 53f5464dMerge branch 'calendar26-day73' into mainAtlas
  • 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
  • ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
  • cab224a1Re-vendor calendar to verified Hybriel day73Atlas
  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas