#!/bin/bash
set -e

echo "=== Banatie Landing Deployment ==="

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"

# Pull latest code
echo "→ Pulling latest changes..."
cd "$PROJECT_DIR"
git pull

# Build
echo "→ Building landing..."
cd /opt/banatie

BUILD_ARGS=""
if [[ "$1" == "--no-cache" ]]; then
    echo "  (using --no-cache)"
    BUILD_ARGS="--no-cache"
fi

docker compose --env-file .env --env-file secrets.env build $BUILD_ARGS banatie-landing

# Deploy
echo "→ Deploying..."
docker compose --env-file .env --env-file secrets.env up -d banatie-landing

# Check
sleep 3
echo "→ Status:"
docker logs banatie-landing --tail 5

echo "=== Done ==="
