#!/usr/bin/env bash # deploy-hetzner.sh — ship the production build to the bitbaum Hetzner box. # # The box serves FleetCrown at https://fleetcrown.orangecat.ch (Caddy → # 127.0.0.1:4002, systemd unit fleetcrown-app). Box-side .env, launch.sh and # backups/ are owned by the box and never touched by a deploy. # # Usage: # bash scripts/deploy-hetzner.sh # build + rsync + restart # bash scripts/deploy-hetzner.sh --no-build # rsync an existing build set -euo pipefail HOST="root@${HETZNER_IP:-167.233.22.31}" APP_DIR="/opt/fleetcrown/app" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" STANDALONE="$PROJECT_DIR/.next/standalone" if [ "${1:-}" != "--no-build" ]; then (cd "$PROJECT_DIR" && npm run build) fi if [ ! -d "$STANDALONE/.next/static" ]; then echo "✗ $STANDALONE missing static assets — run npm run build first" >&2 exit 1 fi echo "→ rsync standalone → $HOST:$APP_DIR" rsync -az --delete \ --exclude '.env' \ --exclude 'launch.sh' \ --exclude 'backups' \ "$STANDALONE/" "$HOST:$APP_DIR/" echo "→ restart fleetcrown-app on box" ssh "$HOST" "chown -R ubuntu:ubuntu $APP_DIR \ && systemctl restart fleetcrown-app \ && sleep 3 \ && systemctl is-active fleetcrown-app \ && curl -s -o /dev/null -w 'box app HTTP %{http_code}\n' http://127.0.0.1:4002/sign-in" echo "✓ deployed $(cd "$PROJECT_DIR" && git rev-parse --short HEAD) to Hetzner"