#!/usr/bin/env bash # Deploy (or redeploy) the web app to the h4a workload. # # Prereqs: # - Workload provisioned via h4a (`thuisbatterij`). # - SSH alias `thuisbatterij` in ~/.ssh/config pointing at it. # If h4a rotates the VM, update the HostName in your SSH config and re-run. # # Usage: scripts/deploy.sh set -euo pipefail ALIAS="thuisbatterij" APP_DIR="/opt/thuisbatterij" echo "→ checking SSH" ssh -o BatchMode=yes -o ConnectTimeout=8 ${ALIAS} 'true' echo "→ rsyncing source to ${ALIAS}:${APP_DIR}" ssh ${ALIAS} "mkdir -p ${APP_DIR}" rsync -az --delete \ --exclude='.venv' --exclude='__pycache__' --exclude='*.pyc' \ --exclude='.pytest_cache' --exclude='.ruff_cache' --exclude='.mypy_cache' \ --exclude='data/processed' --exclude='.DS_Store' --exclude='.env' \ --exclude='.git' \ ./ ${ALIAS}:${APP_DIR}/ echo "→ installing python deps" ssh ${ALIAS} "cd ${APP_DIR} && \ apt-get install -y python3-venv python3.12-venv >/dev/null 2>&1 && \ ([ -d .venv ] || python3 -m venv .venv) && \ .venv/bin/pip install -q --upgrade pip && \ .venv/bin/pip install -q -e ." echo "→ installing/updating systemd unit" ssh ${ALIAS} "cat >/etc/systemd/system/thuisbatterij.service </dev/null || true systemctl disable h4a-app.service 2>/dev/null || true systemctl daemon-reload systemctl enable --now thuisbatterij.service systemctl restart thuisbatterij.service" sleep 3 echo "→ smoke test" ssh ${ALIAS} "curl -sf http://127.0.0.1:8080/healthz && echo" echo "→ done. If first deploy or DNS just changed, expose + bounce caddy:" echo " ssh ${ALIAS} 'systemctl restart caddy'"