gitoriaLog in with ident

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcc063ea2cc063ea2deploy.sh: never send .git or .gitignore to Byrodinmrecc063ea2/deploy.sh

6.9 KB

  1. #!/usr/bin/env bash
  2. # deploy.sh — ident.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, .env with SMTP, nginx vhost,
  13. # cert, DNS). This script only updates the CODE: storage/, .sessions/, .env, .scratch/,
  14. # server.*, 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=ident.worldapi.org
  19. CONTAINER=ident.worldapi.org
  20. [email protected]:/CONTAINERS/projects/ident.worldapi.org
  21. DEFAULT_URL=https://ident.worldapi.org/
  22. GATES=(
  23. "node tests/browser.mjs"
  24. "node tests/apps.mjs"
  25. "node tests/selector.mjs"
  26. "node tests/migration.mjs"
  27. "node tests/iplimit.mjs"
  28. "node tests/notify.mjs"
  29. )
  30. # NEVER SENT (rsync patterns; a leading / anchors at the app folder)
  31. EXCLUDES=(
  32. /.git/ /.gitignore
  33. /storage/ /.sessions/ /.env /.env.* /.scratch/ /server.* /testapp/
  34. '*.log' '*.pid' node_modules/
  35. )
  36. # ---------------------------------------------------------------------------------------------
  37. DRY=0
  38. SKIP=0
  39. TARGET=${DEPLOY_TARGET:-$DEFAULT_TARGET}
  40. URL=${DEPLOY_URL:-$DEFAULT_URL}
  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,13p' "$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/4] $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/4] 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/4] 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. rsync the code ----------------------------------------------------------------------
  113. RSYNC=(rsync -az --no-owner --no-group --itemize-changes)
  114. for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); done
  115. if [ -n "$REMOTE_HOST" ]; then
  116. RSYNC+=(-e "$SSH")
  117. else
  118. mkdir -p "$REMOTE_DIR"
  119. fi
  120. # the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in it
  121. step "[2/4] rsync preview (what would be sent)"
  122. preview=$(mktemp)
  123. run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"
  124. sed 's/^/ /' "$preview"
  125. echo " ($(grep -c . "$preview" || true) lines)"
  126. if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.|testapp/)|\.log$|\.pid$' ; then
  127. die "the preview holds a path that must never be sent (see above)"
  128. fi
  129. rm -f "$preview"
  130. if [ "$DRY" = 1 ]; then
  131. step "[2/4] DRY RUN: nothing sent"
  132. else
  133. step "[2/4] rsync"
  134. run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'
  135. fi
  136. # ---- 3. restart the container ---------------------------------------------------------------
  137. RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"
  138. if [ "$DRY" = 1 ]; then
  139. step "[3/4] DRY RUN: would restart $CONTAINER"
  140. if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fi
  141. else
  142. step "[3/4] restart $CONTAINER"
  143. if [ -n "$REMOTE_HOST" ]; then
  144. run $SSH "$REMOTE_HOST" "$RESTART"
  145. else
  146. run bash -c "$RESTART"
  147. fi
  148. fi
  149. # ---- 4. the URL answers 200 -----------------------------------------------------------------
  150. if [ "$DRY" = 1 ]; then
  151. step "[4/4] DRY RUN: would check $URL answers 200"
  152. step "dry run done — nothing was sent, nothing restarted"
  153. exit 0
  154. fi
  155. step "[4/4] $URL must answer 200"
  156. code=000
  157. for i in $(seq 1 20); do
  158. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)
  159. echo " try $i: $code"
  160. [ "$code" = 200 ] && break
  161. sleep 1
  162. done
  163. if [ "$code" != 200 ]; then
  164. if [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200 — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fi
  165. die "$URL answered $code, not 200 — look: docker logs --tail 50 $CONTAINER"
  166. fi
  167. step "deployed $APP → $TARGET, $URL answers 200"

Branches

Latest commits

  • cc063ea2deploy.sh: never send .git or .gitignore to Byrodinmre
  • 81b15b7bState of 2026-09-27, before the move to gitoriamre