#!/bin/bash

echo "=== Ranking CAPES - Iniciando sistema ==="

cd /home/fred/projetos/ranking

echo "[1/4] Parando containers antigos..."
docker compose down 2>/dev/null

echo "[2/4] Limpando portas ocupadas..."
sudo fuser -k 8010/tcp 2>/dev/null
sudo fuser -k 5173/tcp 2>/dev/null

echo "[3/4] Criando rede Docker..."
docker network create shared_network 2>/dev/null

echo "[4/4] Subindo containers..."
docker compose up -d backend frontend

sleep 2

echo ""
docker ps --filter "name=ranking" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
echo ""
echo "URLs Locais:"
echo "  - Frontend: http://localhost:5173"
echo "  - Backend:  http://localhost:8010"
