#!/usr/bin/env bash # Deploy the WattHound demo. NO GitHub involved. # # Source of truth : ./index.html (committed to Gitea, built by Coolify) # Git host : gitea.sculpt.co.nz/macjones/watthound-demo (public, Mac's own server) # Runtime : Coolify app "watthound-demo-gitea" -> nginx:alpine, FQDN # https://watthound-demo.sculpt7.com # # Flow: commit index.html -> push to Gitea -> trigger Coolify deploy -> verify. # # Usage: ./deploy.sh # commits & pushes ./index.html, then deploys # ./deploy.sh /path/to/new/index.html # copies that file in first # # Requires: COOLIFY_API_TOKEN + COOLIFY_URL in the myPKA .env (never printed). # git push access to the gitea remote (already configured / keychain). set -euo pipefail SITE_DIR="$(cd "$(dirname "$0")" && pwd)" ENV_FILE="/Users/macjones/Projects/watthound/mypka/.env" APP_UUID="${APP_UUID:-hd9qde2w6xrmnippah409jgt}" # Coolify app watthound-demo-gitea FQDN="https://watthound-demo.sculpt7.com" # Optional: pull in a new build from an arbitrary path if [ "${1:-}" != "" ]; then cp "$1" "$SITE_DIR/index.html" echo "Copied $1 -> index.html ($(wc -c < "$SITE_DIR/index.html") bytes)" fi TOKEN="$(grep '^COOLIFY_API_TOKEN=' "$ENV_FILE" | head -1 | cut -d= -f2-)" URL="$(grep '^COOLIFY_URL=' "$ENV_FILE" | head -1 | cut -d= -f2-)" case "$URL" in */api/v1) BASE="$URL";; *) BASE="${URL%/}/api/v1";; esac cd "$SITE_DIR" if ! git diff --quiet -- index.html || ! git diff --cached --quiet -- index.html; then git add index.html git commit -m "Update demo ($(wc -c < index.html) bytes) $(date +%Y-%m-%d)" >/dev/null echo "Committed index.html" else echo "index.html unchanged since last commit (will still redeploy current HEAD)" fi echo "Pushing to Gitea..." git push gitea main echo "Triggering Coolify deploy (app $APP_UUID)..." curl -sS -X POST -H "Authorization: Bearer $TOKEN" "$BASE/deploy?uuid=$APP_UUID&force=true" \ | python3 -c 'import sys,json;d=json.load(sys.stdin);print(json.dumps(d))' echo "Verifying $FQDN (may take ~30-60s to rebuild)..." for i in $(seq 1 20); do read -r CODE SIZE < <(curl -sS --max-time 15 -o /tmp/wh_deploy_check.html \ -w "%{http_code} %{size_download}" -L "$FQDN/" 2>/dev/null || echo "000 0") WANT="$(wc -c < index.html | tr -d ' ')" echo " check $i: http=$CODE size=$SIZE (want $WANT)" if [ "$CODE" = "200" ] && [ "$SIZE" = "$WANT" ]; then echo "LIVE and verified."; exit 0 fi sleep 10 done echo "WARNING: not verified within timeout; check Coolify deployment logs." exit 1