gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1c41293e1c41293eMediaPlayer: 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 letmre1c41293e/deploy.sh

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

Branches

Latest commits

  • 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
  • e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
  • 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
  • 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre
  • 5228126dUX: components synced from the tickets/layouts UX mission (comments: State select in the footer and button words; files-upload: one-box pick mode; modal: footer rule for its own footer). WIP: the gate's #18 pick-mode checks still expect the old drop zone (11 fail), see the UX2 reportmre
  • 0a9216fbMdEditor: a Table button in the toolbar, a typed pipe row fills the cells, tables take the page theme's look; gate checks updated for 12 toolbar buttonsmre
  • f9d405c8comments: reactions row half as far from its comment (creator 2026-10-24: 'half this distance please'); the 44 px tap targets staymre
  • 4922f9cfsessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 0355975areports/MC-mobile.md, LOG, STATUS (MC)mre
  • 3f0a7229Month view, date picker, range picker: names follow the page language (English by default, not the browser's), weekday/month names formatted in UTC (a UTC+12 zone showed Tue first), 44 px day cells and buttons, Send row air; gate checks at 390 px for every page, popup and dialog (MC)mre
  • 29eb07eaPhone: 44 px targets on the site (brand, home links, buttons), comments, modal and pagination; the header is the brand alone on a phone; comments demo: labelled 'You are' group with the chosen user pressed (MC)mre
  • d1cc83e2reports/E2-toolbar.mdmre
  • 214c3183MdEditor on a phone: toolbar as two even rows of 44 px targets (no clipped icon, no swipe), 'Markdown source' label 15 px, table head 16 px; gate checks (E2)mre
  • 9215bbaareports/F5-empty.mdmre
  • 134b4e3eMdEditor: an editor the framework puts into the page is built at once (page observer), a surface put in anew under a built editor is redrawn; gates for both (hybriel#211)mre
  • 0dce2899reports/K1-bubble.mdmre
  • 6b0936a0comments: 'edited' foldable also drops the theme's border, margin and radius (display: contents alone left them computed)mre
  • 8d79ff79comments bubble hugs its content: a readonly md-editor surface gets no inline min-height (it beat the stylesheet's min-height 0); 'edited' is a quiet label beside the time, versions unframed; gate checksmre