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

APP_NAME="cve-2026-33937"
REPO_URL="https://github.com/dinhvaren/cve-2026-33937.git"
APP_DIR="/opt/${APP_NAME}"

echo "[*] Deploying ${APP_NAME}..."

if [ ! -d "$APP_DIR/.git" ]; then
  echo "[*] Cloning repository..."
  git clone "$REPO_URL" "$APP_DIR"
fi

cd "$APP_DIR"

echo "[*] Pulling latest code..."
git pull

echo "[*] Rebuilding containers..."
docker compose down
docker compose up -d --build

echo "[*] Cleaning unused Docker images..."
docker image prune -f

echo "[+] Deploy completed"
docker compose ps