#!/usr/bin/env bash # deploy.sh — Deploy Performance West via git pull # # Usage: # ./scripts/deploy.sh # deploy to prod # ./scripts/deploy.sh prod # deploy to prod # ./scripts/deploy.sh dev # deploy to dev # # Prerequisites: # - SSH key configured for deploy@207.174.124.71 port 22022 # - Server directories are git clones of the Forgejo repo # - .env configured on server set -euo pipefail SERVER="deploy@207.174.124.71" SSH_PORT=22022 ENV="${1:-prod}" if [ "$ENV" = "dev" ]; then REMOTE_DIR="/opt/performancewest-dev" SITE_URL="https://dev.performancewest.net" API_URL="https://api.dev.performancewest.net" API_PORT=3002 else REMOTE_DIR="/opt/performancewest" SITE_URL="https://performancewest.net" API_URL="https://api.performancewest.net" API_PORT=3001 fi # Colors RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m' log() { echo -e "${GREEN}[deploy:${ENV}]${NC} $*"; } warn() { echo -e "${YELLOW}[deploy:${ENV}]${NC} $*"; } die() { echo -e "${RED}[deploy:${ENV}] ERROR:${NC} $*" >&2; exit 1; } # ── 1. Ensure local changes are committed ──────────────────────────────────── if [ -n "$(git status --porcelain 2>/dev/null)" ]; then warn "You have uncommitted changes. Commit them first:" git status --short die "Commit your changes before deploying." fi # ── 2. Push to Forgejo ─────────────────────────────────────────────────────── log "Pushing to Forgejo..." git push origin main || die "Git push failed" # ── 3. Pull + build + restart on server ────────────────────────────────────── log "Deploying to ${ENV} (${REMOTE_DIR})..." ssh -p "${SSH_PORT}" "${SERVER}" bash < /dev/null 2>&1; then echo "[remote] API is healthy." break fi sleep 3 done echo "[remote] Container status:" docker compose ps --format "table {{.Name}}\t{{.Status}}" REMOTE log "Deploy complete." log "Site: ${SITE_URL} | API: ${API_URL}"