#!/usr/bin/env bash
set -Eeuo pipefail

# Always run from the directory where this script lives (your repo root).
cd "$(dirname "$0")"

echo "==> Pulling latest from origin/main (SSL verify disabled for this pull)…"
GIT_SSL_NO_VERIFY=1 git pull origin main

# Pick the right Docker Compose command (v2 `docker compose` or legacy `docker-compose`)
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
  DC="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
  DC="docker-compose"
else
  echo "Error: Docker Compose not found." >&2
  exit 1
fi

echo "==> Starting/refreshing containers…"
$DC up -d

echo "==> Collecting static files…"
$DC exec -T web python manage.py collectstatic --noinput

echo "✅ Done."
