calendar
All repositories: gitoria
10.2 KB
#!/usr/bin/env bash# deploy.sh — calendar.worldapi.org: Loreana (this folder) → Byrodin. Run ON LOREANA.## ./deploy.sh gates → backup → rsync → restart the container → public URL 200# ./deploy.sh --dry-run gates → rsync -n (shows what WOULD be sent), no backup, no restart, no URL check# ./deploy.sh --skip-tests skips the gates (LOUD warning) — only when you know why# ./deploy.sh --target DIR|HOST:DIR another destination (default below); a local DIR is# how the script is tested without touching Byrodin# ./deploy.sh --url URL the URL that must answer 200 after the restart# (env: DEPLOY_TARGET, DEPLOY_URL, DEPLOY_SSH override the same defaults)# (backup: tars storage/.sessions/.env that exist on the target to Loreana's# /media/SLOW1TB2/deploy-backups/<app>/, keeps newest 5; --target DIR backs up DIR instead)## THE FIRST DEPLOY is done by the architect on Byrodin (folder, data, nginx vhost, cert,# DNS). This script only updates the CODE: storage/, .sessions/, .env, .scratch/, server.*,# testapp/ and logs are never sent, so live data on Byrodin is never touched.# No --delete: a file removed here stays on Byrodin (harmless — nothing imports it).set -euo pipefail# ---- the app ------------------------------------------------------------------------------APP=calendar.worldapi.orgCONTAINER=calendar.worldapi.org[email protected]:/CONTAINERS/projects/calendar.worldapi.orgDEFAULT_URL=https://calendar.worldapi.org/GATES=("node tests/browser.mjs""node theme/check-theme.mjs ." # the theme gate: no hard-coded colours, decorative borders or odd radii (docs/design-rules.md)"node tests/notify-paths.mjs" # ports: NOTIFY_GATE_PORT (default 8700, +1 ident, +2…+9 Chrome), NOTIFY_GATE_SCRATCH"node tests/push.mjs" # Web Push gate; ports: PUSH_GATE_PORT (app, +1 ident, +2 fake push service, +4 Chrome)"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)"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))# NEVER SENT (rsync patterns; a leading / anchors at the app folder)EXCLUDES=(/.git/ /.gitignore/storage/ /.sessions/ /.env /.env.* /.scratch/ /server.* /testapp/'*.log' '*.pid' node_modules/)# ---------------------------------------------------------------------------------------------DRY=0SKIP=0TARGET=${DEPLOY_TARGET:-$DEFAULT_TARGET}URL=${DEPLOY_URL:-$DEFAULT_URL}# how long the URL may take after the restart (seconds); a cold start compiles first (hybriel#148)URL_WAIT=${DEPLOY_URL_WAIT:-120}# Loreana's ssh config may not apply to Byrodin: -F /dev/null (ident STATUS)SSH=${DEPLOY_SSH:-ssh -F /dev/null -o BatchMode=yes -o ConnectTimeout=15}usage() { sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; }while [ $# -gt 0 ]; docase "$1" in--dry-run) DRY=1 ;;--skip-tests) SKIP=1 ;;--target) TARGET=${2:?--target needs a value}; shift ;;--target=*) TARGET=${1#--target=} ;;--url) URL=${2:?--url needs a value}; shift ;;--url=*) URL=${1#--url=} ;;-h|--help) usage; exit 0 ;;*) echo "deploy: unknown argument: $1" >&2; usage >&2; exit 2 ;;esacshiftdoneHERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)cd "$HERE"step() { printf '\n==> %s\n' "$*"; }run() { printf ' $ %s\n' "$*" >&2; "$@"; }die() { printf '\ndeploy: REFUSED — %s\n' "$*" >&2; exit 1; }# a target `host:dir` is remote, a plain path is localif [[ "$TARGET" == *:* ]]; thenREMOTE_HOST=${TARGET%%:*}REMOTE_DIR=${TARGET#*:}elseREMOTE_HOST=REMOTE_DIR=$TARGETfistep "[0/5] $APP → $TARGET (dry run: $DRY, skip tests: $SKIP)"echo " from $HERE"echo " url $URL"[ -x bin/hybriel ] || die "bin/hybriel is missing here"[ -f docker-compose.yml ] || die "docker-compose.yml is missing here"[ -f project.hl ] || die "project.hl is missing here"command -v rsync >/dev/null || die "rsync is not installed"# ---- 1. the gates ---------------------------------------------------------------------------if [ "$SKIP" = 1 ]; thenstep "[1/5] GATES SKIPPED"printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'printf ' !! --skip-tests: NOTHING WAS TESTED. You deploy untested code. !!\n'printf ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'elsestep "[1/5] gates (${#GATES[@]})"# headless Chromes that exist BEFORE the gates are not ours (other sessions' test runs, e.g. Anton's)chromes() { ps -eo pid=,ppid=,args= | awk '/[h]l-browser-tier/ && /remote-debugging-port/ && !/--type=/ {print $1, $2}'; }before=" $(chromes | awk '{print $1}' | tr '\n' ' ') "for g in "${GATES[@]}"; doprintf ' $ %s\n' "$g"out=$(mktemp)if ! $g > "$out" 2>&1; thengrep -E '^FAIL|passed,|^check-theme:' "$out" | sed 's/^/ /' || trueecho " (full output: $out)"die "gate failed: $g"figrep -E 'passed,|^check-theme:' "$out" | tail -1 | sed 's/^/ /' || truerm -f "$out"done# a Chrome our gates LEFT: new since the gates began AND no longer owned by a running node test# (a Chrome whose parent is a live node process belongs to another session's test run right now)leaked=""while read -r pid ppid; do[ -z "$pid" ] && continuecase "$before" in *" $pid "*) continue ;; esacps -o args= -p "$ppid" 2>/dev/null | grep -q '^node\|/node ' && continueleaked="$leaked $pid"done < <(chromes)if [ -n "$leaked" ]; thendie "a gate left a headless Chrome (pids:$leaked; ps -eo pid,args | grep hl-browser-tier)"fifi# ---- 2. pre-deploy backup of the LIVE data (before anything is sent) ------------------------BACKUP_ROOT=${DEPLOY_BACKUP_ROOT:-/media/SLOW1TB2/deploy-backups}BACKUP_DIR="$BACKUP_ROOT/$APP"BACKUP_FILE="$BACKUP_DIR/$APP-$(date +%Y%m%d-%H%M).tgz"if [ "$DRY" = 1 ]; thenstep "[2/5] DRY RUN: backup skipped"elsestep "[2/5] backup live data ($APP) → $BACKUP_FILE"mkdir -p "$BACKUP_DIR"if [ -n "$REMOTE_HOST" ]; thenpresent=$($SSH "$REMOTE_HOST" "cd '$REMOTE_DIR' 2>/dev/null && for p in storage .sessions .env; do [ -e \"\$p\" ] && echo \"\$p\"; done; true")elsepresent=$(cd "$REMOTE_DIR" 2>/dev/null && for p in storage .sessions .env; do [ -e "$p" ] && echo "$p"; done; true)fipresent=$(printf '%s' "$present" | tr '\n' ' ' | sed 's/ *$//')if [ -z "$present" ]; thenecho " nothing to back up yet (no storage/.sessions/.env on the target)"elseecho " taring: $present"if [ -n "$REMOTE_HOST" ]; then# Order (Anton #203): directories, then every file except *.mpack (indexes, idxstate, sessions, .env), then the *.mpack# data last — a hot copy then never holds index offsets past the data it copied. tar exit 1 = "file changed as we# read it" / a file gone between find and tar (--ignore-failed-read) — a warning; the archive is checked with gzip -t.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" \|| { rm -f "$BACKUP_FILE"; die "backup failed (tar/ssh error) — refusing to deploy"; }elserun tar czf "$BACKUP_FILE" -C "$REMOTE_DIR" $present \|| { rm -f "$BACKUP_FILE"; die "backup failed (tar error) — refusing to deploy"; }fi[ -s "$BACKUP_FILE" ] || { rm -f "$BACKUP_FILE"; die "backup is empty — refusing to deploy"; }echo " $(du -h "$BACKUP_FILE" | cut -f1) $BACKUP_FILE"ls -1t "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | tail -n +6 | xargs -r rm -f --echo " keeping $(ls -1 "$BACKUP_DIR/$APP"-*.tgz 2>/dev/null | wc -l) archive(s) of $APP"fifi# ---- 3. rsync the code ----------------------------------------------------------------------RSYNC=(rsync -az --no-owner --no-group --itemize-changes)for e in "${EXCLUDES[@]}"; do RSYNC+=("--exclude=$e"); doneif [ -n "$REMOTE_HOST" ]; thenRSYNC+=(-e "$SSH")elsemkdir -p "$REMOTE_DIR"fi# the preview is ALWAYS made first (rsync -n): nothing that must stay on Byrodin may be in itstep "[3/5] rsync preview (what would be sent)"preview=$(mktemp)run "${RSYNC[@]}" -n ./ "$TARGET/" > "$preview"sed 's/^/ /' "$preview"echo " ($(grep -c . "$preview" || true) lines)"if awk '{print $2}' "$preview" | grep -E '^(storage/|\.sessions/|\.env|\.scratch/|server\.|testapp/)|\.log$|\.pid$' ; thendie "the preview holds a path that must never be sent (see above)"firm -f "$preview"if [ "$DRY" = 1 ]; thenstep "[3/5] DRY RUN: nothing sent"elsestep "[3/5] rsync"run "${RSYNC[@]}" ./ "$TARGET/" | sed 's/^/ /'fi# ---- 4. restart the container ---------------------------------------------------------------RESTART="cd '$REMOTE_DIR' && docker compose up -d --build && docker compose restart && docker compose ps"if [ "$DRY" = 1 ]; thenstep "[4/5] DRY RUN: would restart $CONTAINER"if [ -n "$REMOTE_HOST" ]; then echo " would run: $SSH $REMOTE_HOST \"$RESTART\""; else echo " would run: bash -c \"$RESTART\""; fielsestep "[4/5] restart $CONTAINER"if [ -n "$REMOTE_HOST" ]; thenrun $SSH "$REMOTE_HOST" "$RESTART"elserun bash -c "$RESTART"fifi# ---- 5. the URL answers 200 -----------------------------------------------------------------if [ "$DRY" = 1 ]; thenstep "[5/5] DRY RUN: would check $URL answers 200"step "dry run done — nothing was sent, nothing restarted"exit 0fistep "[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)"code=000start=$SECONDSi=0while :; doi=$((i + 1))code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$URL" || true)echo " try $i ($((SECONDS - start)) s): $code"[ "$code" = 200 ] && break[ $((SECONDS - start)) -ge "$URL_WAIT" ] && breaksleep 2doneif [ "$code" != 200 ]; thenif [ -n "$REMOTE_HOST" ]; then die "$URL answered $code, not 200 — look: $SSH $REMOTE_HOST docker logs --tail 50 $CONTAINER"; fidie "$URL answered $code, not 200 — look: docker logs --tail 50 $CONTAINER"fistep "deployed $APP → $TARGET, $URL answers 200"
Branches
Latest commits
- 2dd53dccP1: one reminder shows once: arm() one at a time, the page skips reminders the server already pushed; push-twice gatemre
- 3a29760aC13 report (handoff)mre
- 33ab66ffCalendar: notification controls move from the month view into Reminder settings (user menu), one consistent state, state read when the dialog opensmre
- 682a5b43reports: calendar gate countsmre
- 876d22b2reports/H1-hydrate.mdmre
- ef0cae45tests/dst.mjs: wait for hydration instead of a fixed 2.5 s sleep before clicking #gomre
- d9cadecatests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- efa61227re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- 7808adbecalendar#12: report 011, LOG, STATUS, push-shots-testmre
- df2e4fa0calendar#12: test push rate limit (1 per 30 s per device), owner-only gate checksmre
- acb957cfcalendar#12: Send a test notification on a subscribed device (one push in ~10 s, owner's own device), push gate part 4mre
- 0b222eb8tests: e2e-theme CDP port default from E2E_THEME_CDP_PORT (8756 unchanged)mre
- 8b8a5abare-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- a69b27f9docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 1a97edfdcalendar mission 010: reminder rows at 390 px (the 7-column month grid no longer catches the reminder lists), gate checks, settings-shots, reportmre
- 61b21404calendar mission 009: reminder times on hl:time in the browser (lib/push-plan.hl and the Intl code removed), DST gate tests/dst.mjs, E2E script, reportmre
- 875353c1calendar mission 009: re-vendor Hybriel master 022a3ac1 (int 6 6b396322 hl:time browser side, int 7 65e8ec21; bin sha256 6e0f77d7, plugins whole)mre
- ce16a4efdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- f490bc8cdeploy: Web Push gate tests/push.mjs (PUSH_GATE_PORT)mre
- 3af29fc8calendar mission 008 (A8): report, README, LOG, push-shots.mjsmre