#!/usr/bin/env bash # Deploy InternetPressure to BHS64b: rsync → build images on the server → compose up → migrate/seed → health. # # deploy/bin/deploy.sh full deploy (build + up + migrate + seed + health) # deploy/bin/deploy.sh up compose up only (no rebuild) # deploy/bin/deploy.sh build rsync + build images only # deploy/bin/deploy.sh status docker compose ps + health # deploy/bin/deploy.sh logs [svc] follow logs # deploy/bin/deploy.sh route (re)create the public route on the BHS64 gateway # # Prerequisites (one-off): deploy/bin/prep-server.sh (Docker, WireGuard wg1 peer to BHS64, ufw), deploy/.env on the server. source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" cmd="${1:-full}"; shift || true health() { log "health via edge (through WireGuard from the gateway)" ssh -o BatchMode=yes "$IP_GATEWAY" "curl -s -m 10 -o /dev/null -w 'edge %{http_code} %{time_total}s\n' http://$IP_WG_IP:8350/api/v1/status; \ curl -s -m 10 http://$IP_WG_IP:8350/api/v1/status | head -c 300; echo" log "public" curl -s -m 15 -o /dev/null -w "https://$IP_DOMAIN %{http_code} %{time_total}s\n" "https://$IP_DOMAIN/api/v1/status" || warn "public check failed (DNS/route?)" } route() { log "route https://$IP_DOMAIN → $IP_WG_IP:8350 on $IP_GATEWAY" ssh -o BatchMode=yes "$IP_GATEWAY" "sudo tunnelctl add $IP_DOMAIN $IP_SERVER:8350 && sudo tunnelctl redirect internetpressure.io $IP_DOMAIN || true; sudo tunnelctl ls | grep -i internetpressure" } case "$cmd" in full) sync_repo compose "build --pull api web" compose "up -d --remove-orphans" compose "run --rm migrate" compose "ps" sleep 5 health ;; build) sync_repo; compose "build --pull api web" ;; up) sync_repo; compose "up -d --remove-orphans"; compose "ps" ;; migrate) compose "run --rm migrate" ;; status) compose "ps"; health ;; logs) compose "logs -f --tail=200 ${1:-}" ;; route) route ;; restart) compose "restart ${1:-}" ;; *) die "unknown command $cmd" ;; esac ok "done"