gitoriaLog in with ident

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbecbd59bbecbd59bcomponents#13: modal dialog (<dialog> based, focus wrap, backdrop/Esc/x close with reason, scroll lock, footer buttons)mrebecbd59b/deploy.sh

6.8 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 → rsync → restart the container → public URL 200
  5. # ./deploy.sh --dry-run gates → rsync -n (shows what WOULD be sent), 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. #
  12. # THE FIRST DEPLOY is done by the architect on Byrodin (folder, data, nginx vhost, cert,
  13. # DNS). This script only updates the CODE: storage/, .sessions/, .env, .scratch/, server.*,
  14. # testapp/ and logs are never sent, so live data on Byrodin is never touched.
  15. # No --delete: a file removed here stays on Byrodin (harmless — nothing imports it).
  16. set -euo pipefail
  17. # ---- the app ------------------------------------------------------------------------------
  18. APP=components.hybriel.worldapi.org
  19. CONTAINER=components.hybriel.worldapi.org
  20. [email protected]:/CONTAINERS/projects/components.hybriel.worldapi.org
  21. DEFAULT_URL=https://components.hybriel.worldapi.org/
  22. GATES=(
  23. "node tests/browser.mjs"
  24. )
  25. # NEVER SENT (rsync patterns; a leading / anchors at the app folder)
  26. EXCLUDES=(
  27. /.git/ /.gitignore
  28. /storage/ /.sessions/ /.env /.env.* /.scratch/ /server.* /testapp/
  29. '*.log' '*.pid' node_modules/
  30. )
  31. # ---------------------------------------------------------------------------------------------
  32. DRY=0
  33. SKIP=0
  34. TARGET=${DEPLOY_TARGET:-$DEFAULT_TARGET}
  35. URL=${DEPLOY_URL:-$DEFAULT_URL}
  36. # Loreana's ssh config may not apply to Byrodin: -F /dev/null (ident STATUS)
  37. SSH=${DEPLOY_SSH:-ssh -F /dev/null -o BatchMode=yes -o ConnectTimeout=15}
  38. usage() { sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//'; }
  39. while [ $# -gt 0 ]; do
  40. case "$1" in
  41. --dry-run) DRY=1 ;;
  42. --skip-tests) SKIP=1 ;;
  43. --target) TARGET=${2:?--target needs a value}; shift ;;
  44. --target=*) TARGET=${1#--target=} ;;
  45. --url) URL=${2:?--url needs a value}; shift ;;
  46. --url=*) URL=${1#--url=} ;;
  47. -h|--help) usage; exit 0 ;;
  48. *) echo "deploy: unknown argument: $1" >&2; usage >&2; exit 2 ;;
  49. esac
  50. shift
  51. done
  52. HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
  53. cd "$HERE"
  54. step() { printf '\n==> %s\n' "$*"; }
  55. run() { printf ' $ %s\n' "$*" >&2; "$@"; }
  56. die() { printf '\ndeploy: REFUSED — %s\n' "$*" >&2; exit 1; }
  57. # a target `host:dir` is remote, a plain path is local
  58. if [[ "$TARGET" == *:* ]]; then
  59. REMOTE_HOST=${TARGET%%:*}
  60. REMOTE_DIR=${TARGET#*:}
  61. else
  62. REMOTE_HOST=
  63. REMOTE_DIR=$TARGET
  64. fi
  65. step "[0/4] $APP → $TARGET (dry run: $DRY, skip tests: $SKIP)"
  66. echo " from $HERE"
  67. echo " url $URL"
  68. [ -x bin/hybriel ] || die "bin/hybriel is missing here"
  69. [ -f docker-compose.yml ] || die "docker-compose.yml is missing here"
  70. [ -f project.hl ] || die "project.hl is missing here"
  71. command -v rsync >/dev/null || die "rsync is not installed"
  72. # ---- 1. the gates ---------------------------------------------------------------------------
  73. if [ "$SKIP" = 1 ]; then
  74. step "[1/4] GATES SKIPPED"
  75. printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  76. printf ' !! --skip-tests: NOTHING WAS TESTED. You deploy untested code. !!\n'
  77. printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  78. else
  79. step "[1/4] gates (${#GATES[@]})"
  80. # headless Chromes that exist BEFORE the gates are not ours (other sessions' test runs, e.g. Anton's)
  81. chromes() { ps -eo pid=,ppid=,args= | awk '/[h]l-browser-tier/ && /remote-debugging-port/ && !/--type=/ {print $1, $2}'; }
  82. before=" $(chromes | awk '{print $1}' | tr '\n' ' ') "
  83. for g in "${GATES[@]}"; do
  84. printf ' $ %s\n' "$g"
  85. out=$(mktemp)
  86. if ! $g > "$out" 2>&1; then
  87. grep -E '^FAIL|passed,' "$out" | sed 's/^/ /' || true
  88. echo " (full output: $out)"
  89. die "gate failed: $g"
  90. fi
  91. grep -E 'passed,' "$out" | tail -1 | sed 's/^/ /'
  92. rm -f "$out"
  93. done
  94. # a Chrome our gates LEFT: new since the gates began AND no longer owned by a running node test
  95. # (a Chrome whose parent is a live node process belongs to another session's test run right now)
  96. leaked=""
  97. while read -r pid ppid; do
  98. [ -z "$pid" ] && continue
  99. case "$before" in *" $pid "*) continue ;; esac
  100. ps -o args= -p "$ppid" 2>/dev/null | grep -q '^node\|/node ' && continue
  101. leaked="$leaked $pid"
  102. done < <(chromes)
  103. if [ -n "$leaked" ]; then
  104. die "a gate left a headless Chrome (pids:$leaked; ps -eo pid,args | grep hl-browser-tier)"
  105. fi
  106. fi
  107. # ---- 2. rsync the code ----------------------------------------------------------------------
  108. RSYNC=(rsync -az --no-owner --no-group --itemize-changes)
  109. for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); done
  110. if [ -n "$REMOTE_HOST" ]; then
  111. RSYNC+=(-e "$SSH")
  112. else
  113. mkdir -p "$REMOTE_DIR"
  114. fi
  115. # the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in it
  116. step "[2/4] rsync preview (what would be sent)"
  117. preview=$(mktemp)
  118. run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"
  119. sed 's/^/ /' "$preview"
  120. echo " ($(grep -c . "$preview" || true) lines)"
  121. if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.|testapp/)|\.log$|\.pid$' ; then
  122. die "the preview holds a path that must never be sent (see above)"
  123. fi
  124. rm -f "$preview"
  125. if [ "$DRY" = 1 ]; then
  126. step "[2/4] DRY RUN: nothing sent"
  127. else
  128. step "[2/4] rsync"
  129. run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'
  130. fi
  131. # ---- 3. restart the container ---------------------------------------------------------------
  132. RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"
  133. if [ "$DRY" = 1 ]; then
  134. step "[3/4] DRY RUN: would restart $CONTAINER"
  135. if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fi
  136. else
  137. step "[3/4] restart $CONTAINER"
  138. if [ -n "$REMOTE_HOST" ]; then
  139. run $SSH "$REMOTE_HOST" "$RESTART"
  140. else
  141. run bash -c "$RESTART"
  142. fi
  143. fi
  144. # ---- 4. the URL answers 200 -----------------------------------------------------------------
  145. if [ "$DRY" = 1 ]; then
  146. step "[4/4] DRY RUN: would check $URL answers 200"
  147. step "dry run done — nothing was sent, nothing restarted"
  148. exit 0
  149. fi
  150. step "[4/4] $URL must answer 200"
  151. code=000
  152. for i in $(seq 1 20); do
  153. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)
  154. echo " try $i: $code"
  155. [ "$code" = 200 ] && break
  156. sleep 1
  157. done
  158. if [ "$code" != 200 ]; then
  159. if [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200 — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fi
  160. die "$URL answered $code, not 200 — look: docker logs --tail 50 $CONTAINER"
  161. fi
  162. step "deployed $APP → $TARGET, $URL answers 200"

Branches

Latest commits

  • becbd59bcomponents#13: modal dialog (<dialog> based, focus wrap, backdrop/Esc/x close with reason, scroll lock, footer buttons)mre
  • 367dd19adeploy.sh: never send .git or .gitignore to Byrodinmre
  • 4b4dabe5State of 2026-09-27, before the move to gitoriamre