gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7f992d627f992d62gitoria#23: phone first on the shared theme — brand, branch and pull links 44 px, readme code 14 px; gate block "phone first" (15 pages at 390 + the three dropdowns, fails 20 on old), dropdown-aware login/logout clicks, check-theme in GATESmre7f992d62/deploy.sh

8.9 KB

  1. #!/usr/bin/env bash
  2. # deploy.sh — gitoria.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=gitoria.worldapi.org
  21. CONTAINER=gitoria.worldapi.org
  22. [email protected]:/CONTAINERS/projects/gitoria.worldapi.org
  23. DEFAULT_URL=https://gitoria.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,' "$out" | sed 's/^/ /' || true
  93. echo " (full output: $out)"
  94. die "gate failed: $g"
  95. fi
  96. grep -E 'passed,' "$out" | tail -1 | sed 's/^/ /'
  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. run $SSH "$REMOTE_HOST" "tar czf - -C '$REMOTE_DIR' $present" > "$BACKUP_FILE" \
  133. || { rm -f "$BACKUP_FILE"; die "backup failed (tar/ssh error) — refusing to deploy"; }
  134. else
  135. run tar czf "$BACKUP_FILE" -C "$REMOTE_DIR" $present \
  136. || { rm -f "$BACKUP_FILE"; die "backup failed (tar error) — refusing to deploy"; }
  137. fi
  138. [ -s "$BACKUP_FILE" ] || { rm -f "$BACKUP_FILE"; die "backup is empty — refusing to deploy"; }
  139. echo " $(du -h "$BACKUP_FILE" | cut -f1) $BACKUP_FILE"
  140. ls -1t "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | tail -n +6 | xargs -r rm -f --
  141. echo " keeping $(ls -1 "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | wc -l) archive(s) of $APP"
  142. fi
  143. fi
  144. # ---- 3. rsync the code ----------------------------------------------------------------------
  145. RSYNC=(rsync -az --no-owner --no-group --itemize-changes)
  146. for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); done
  147. if [ -n "$REMOTE_HOST" ]; then
  148. RSYNC+=(-e "$SSH")
  149. else
  150. mkdir -p "$REMOTE_DIR"
  151. fi
  152. # the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in it
  153. step "[3/5] rsync preview (what would be sent)"
  154. preview=$(mktemp)
  155. run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"
  156. sed 's/^/ /' "$preview"
  157. echo " ($(grep -c . "$preview" || true) lines)"
  158. if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.|testapp/)|\.log$|\.pid$' ; then
  159. die "the preview holds a path that must never be sent (see above)"
  160. fi
  161. rm -f "$preview"
  162. if [ "$DRY" = 1 ]; then
  163. step "[3/5] DRY RUN: nothing sent"
  164. else
  165. step "[3/5] rsync"
  166. run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'
  167. fi
  168. # ---- 4. restart the container ---------------------------------------------------------------
  169. RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"
  170. if [ "$DRY" = 1 ]; then
  171. step "[4/5] DRY RUN: would restart $CONTAINER"
  172. if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fi
  173. else
  174. step "[4/5] restart $CONTAINER"
  175. if [ -n "$REMOTE_HOST" ]; then
  176. run $SSH "$REMOTE_HOST" "$RESTART"
  177. else
  178. run bash -c "$RESTART"
  179. fi
  180. fi
  181. # ---- 5. the URL answers 200 -----------------------------------------------------------------
  182. if [ "$DRY" = 1 ]; then
  183. step "[5/5] DRY RUN: would check $URL answers 200"
  184. step "dry run done — nothing was sent, nothing restarted"
  185. exit 0
  186. fi
  187. 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)"
  188. code=000
  189. start=$SECONDS
  190. i=0
  191. while :; do
  192. i=$((i + 1))
  193. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)
  194. echo " try $i ($((SECONDS - start)) s): $code"
  195. [ "$code" = 200 ] && break
  196. [ $((SECONDS - start)) -ge "$URL_WAIT" ] && break
  197. sleep 2
  198. done
  199. if [ "$code" != 200 ]; then
  200. if [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200 — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fi
  201. die "$URL answered $code, not 200 — look: docker logs --tail 50 $CONTAINER"
  202. fi
  203. step "deployed $APP → $TARGET, $URL answers 200"

Branches

Latest commits

  • 7f992d62gitoria#23: phone first on the shared theme — brand, branch and pull links 44 px, readme code 14 px; gate block "phone first" (15 pages at 390 + the three dropdowns, fails 20 on old), dropdown-aware login/logout clicks, check-theme in GATESmre
  • a2a840a5gitoria#23 WIP (quota stop): theme from layouts, styles inherit it, shell on the theme's header/menus/sidebar, phone measurement script; gates not runmre
  • 12b665b0mission brief 005mre
  • b680c483Revert "gitoria#22: RepoTabs wrapping component for the repo tabs (active tab, no content for a missing repo)"mre
  • 4fda244fgitoria#22: RepoTabs wrapping component for the repo tabs (active tab, no content for a missing repo)mre
  • 0fd5e280mission brief 004mre
  • e1d425e7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • e59ff114deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • bcafcceb003: compose cache volume + tmpfs /tmp, gate start waits 120 s, report/LOG/STATUSmre
  • bed3f2d5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored)mre
  • 3207e128mission brief 003mre
  • 18ab71fbtests/ticketskit: wait up to 120 s for tickets (native Hybriel cold compile ~25 s, hybriel#148)mre
  • 4fffa966docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mre
  • 86605446mission 002 (code order) 4/4: README file map + import order + 'Same output' test + gate run with a tickets HEAD copy, STATUS (entry, lessons), LOG, report; tests/realdata-baseline.mjs + realdata-compare.py (a cleanup answers the same on live data: pages, modules, API, git over HTTPS and SSH, faces), tests/letcount.pymre
  • cc7bf7bamission 002 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (289 lets → plain declarations; 213 left: 125 reassigned, 88 loop-bound; no member/import/param clash). gates 200/0, 46/0, 44/0; real-data reads + writes identical (browser modules: var → const only)mre
  • 090a20c6mission 002 (code order) 2/4: one lib/ file per topic — git.hl split into git (calls, branches, init, temp folder) / homepage / code / pulls / releases (+ git-helpers: paths, ids, |||PR/|||RL markers); repos-helpers, tickets-helpers, transport-helpers; util.hl = localtime + env, storage dir, addresses, lists, text checks, one newest-first sort (was 3 copies); the function routes out of project.hl into lib/api.hl (thin; plumbing in api-helpers.hl), sshgate.hl folded into api.hl + sshkeys.hl keyLine + repos.hl mayPush; 'Make main' and the merge answer out of the faces (code.hl makeMain, pulls.hl pullsView), one login helper (users.hl userOfLoginCode); project.hl is the map. Session-writing routes get &req + &server.sessions. gates 200/0, 46/0, 44/0; real-data identical except /login/failed now shows the parked reason for a browser that already had a session (the old copy-of-req lost it)mre
  • 110c2799mission 002 (code order) 1/4: .hl files out of the root — lib/ (api, git, localtime, markdown, repos, sshgate, sshkeys, tickets, tokens, transport, users), components/styles.hl; jsoncheck.hl removed (imported nowhere); import paths only. gates 200/0, 46/0, 44/0; real-data reads + writes identicalmre
  • fdfb4b1bgitoria: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 200/0, 46/0, 44/0mre
  • 5b46ac84antcolony#40: LOG.md — missions 069/072 are antcolony missions (report paths on Byrodin)mre