#!/usr/bin/env bash set -euo pipefail STATIC_SRC="/opt/cc-dashboard/src/static" STATIC_DST="/var/www/html/cc-dashboard" COMPOSE="docker compose -f /opt/cc-dashboard/docker-compose.yml" log() { echo "[$(date '+%H:%M:%S')] $*"; } die() { echo "[ERROR] $*" >&2; exit 1; } cd /opt/cc-dashboard || die "Cannot cd to /opt/cc-dashboard" # ── 1. Pull latest code ────────────────────────────────────────────────────── log "Pulling latest code..." git pull # ── 2. Sync static files to web root ──────────────────────────────────────── # Apache serves /cc-dashboard/* from /var/www/html/cc-dashboard/ # index.html must be at the root; CSS/JS go into static/ subdir to match # paths in index.html (/cc-dashboard/static/css/..., /cc-dashboard/static/js/...) log "Syncing static files to $STATIC_DST..." sudo mkdir -p "$STATIC_DST/static" sudo cp "$STATIC_SRC/index.html" "$STATIC_DST/index.html" sudo rsync -a --delete --exclude='index.html' "$STATIC_SRC/" "$STATIC_DST/static/" # ── 3. Rebuild app image ───────────────────────────────────────────────────── log "Building app image..." $COMPOSE build app # ── 4. Restart app (migrations run automatically on container start) ───────── log "Restarting app container..." $COMPOSE up -d --no-deps app # ── 5. Wait for healthy + show logs ───────────────────────────────────────── log "Waiting for container to start..." sleep 3 $COMPOSE ps app $COMPOSE logs --tail=30 app log "Deploy complete."