Ajusta bootstrap e portas para subida sem conflitos

This commit is contained in:
Frederico Castro
2025-12-12 22:44:12 -03:00
parent a768fadbe2
commit 3edd81dbcb
5 changed files with 66 additions and 11 deletions

View File

@@ -150,7 +150,7 @@ ORACLE_DSN=host:1521/service_name
poetry run python src/main.py
```
A API estará disponível em `http://localhost:8000`
A API estará disponível em `http://localhost:8010`
### Frontend
@@ -185,7 +185,7 @@ cp .env.example .env
docker-compose up -d
```
- Backend: `http://localhost:8000`
- Backend: `http://localhost:8010`
- Frontend: `http://localhost`
## Endpoints da API
@@ -231,8 +231,8 @@ Health check da API.
## Documentação da API
Após iniciar o backend, acesse:
- Swagger UI: `http://localhost:8000/docs`
- ReDoc: `http://localhost:8000/redoc`
- Swagger UI: `http://localhost:8010/docs`
- ReDoc: `http://localhost:8010/redoc`
## Desenvolvimento

36
backend/scripts/bootstrap_ranking.sh Normal file → Executable file
View File

@@ -1,6 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
# Escolhe binário do Python (funciona no host ou dentro do container)
if [ -x "./venv/bin/python" ]; then
VENV_PY="./venv/bin/python"
elif command -v python3 >/dev/null 2>&1; then
VENV_PY="python3"
else
VENV_PY="python"
fi
# Configs
DSN_CANDIDATES=()
if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
@@ -8,7 +17,6 @@ if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
fi
DSN_CANDIDATES+=("127.0.0.1:1521/XEPDB1" "oracle18c:1521/XEPDB1" "mqapilc_oracle18c:1521/XEPDB1")
API_URL=${API_URL:-"http://localhost:8000"}
VENV_PY="./venv/bin/python"
echo "[1/5] Aguardando Oracle..."
DSN_HOST=""
@@ -44,6 +52,14 @@ cur.close();conn.close()
PY
)
echo " Registros na TB_RANKING_CONSULTOR: ${COUNT}"
MAX_B=$($VENV_PY - <<PY
import cx_Oracle
conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
cur=conn.cursor();cur.execute("select nvl(max(componente_b),0) from tb_ranking_consultor")
print(cur.fetchone()[0])
cur.close();conn.close()
PY
)
if [ "${COUNT}" -eq 0 ]; then
echo "[3/5] Rodando job de ranking (A/C/D)..."
@@ -51,7 +67,7 @@ if [ "${COUNT}" -eq 0 ]; then
# Espera concluir
while true; do
STATUS=$(curl -s "${API_URL}/api/v1/ranking/status")
running=$(python - <<'PY'
running=$($VENV_PY - <<'PY'
import os, json
data=json.loads(os.environ["STATUS"])
print(data.get("running", False))
@@ -63,10 +79,21 @@ STATUS="$STATUS")
fi
sleep 20
done
NEED_B="yes"
elif [ "${MAX_B}" -eq 0 ]; then
echo "[3/5] Tabela já tem dados, mas componente B nunca foi preenchido (max=0)."
NEED_B="yes"
else
echo "[3/5] Tabela já possui dados e componente B preenchido (max=${MAX_B}). Pulando cálculo pesado."
NEED_B="no"
fi
echo "[4/5] Rodando Componente B (PPG)..."
ORACLE_LOCAL_DSN=${DSN_HOST} PYTHONUNBUFFERED=1 $VENV_PY scripts/popular_componente_b.py
if [ "${NEED_B}" = "yes" ]; then
echo "[4/5] Rodando Componente B (PPG)..."
ORACLE_LOCAL_DSN=${DSN_HOST} PYTHONUNBUFFERED=1 $VENV_PY scripts/popular_componente_b.py
else
echo "[4/5] Componente B já presente, sem necessidade de recálculo."
fi
echo "[5/5] Contagens finais:"
$VENV_PY - <<PY
@@ -75,6 +102,7 @@ conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
cur=conn.cursor()
cur.execute("select count(*) from tb_ranking_consultor"); print("total",cur.fetchone()[0])
cur.execute("select count(*) from tb_ranking_consultor where componente_b>0"); print("B>0",cur.fetchone()[0])
cur.execute("select max(componente_b) from tb_ranking_consultor"); print("max B",cur.fetchone()[0])
cur.execute("select max(pontuacao_total) from tb_ranking_consultor"); print("max total",cur.fetchone()[0])
cur.close();conn.close()
PY

View File

@@ -5,7 +5,7 @@ services:
context: ./backend
dockerfile: Dockerfile
ports:
- "8000:8000"
- "8010:8000"
env_file:
- ./backend/.env
environment:

View File

@@ -8,7 +8,7 @@ echo "[1/5] Parando containers antigos..."
docker compose down 2>/dev/null
echo "[2/5] Limpando portas ocupadas..."
sudo fuser -k 8000/tcp 2>/dev/null
sudo fuser -k 8010/tcp 2>/dev/null
sudo fuser -k 5173/tcp 2>/dev/null
echo "[3/5] Matando ngrok antigo..."
@@ -57,7 +57,7 @@ echo " URL Publica (ngrok): $NGROK_URL"
echo ""
echo " URLs Locais:"
echo " - Frontend: http://localhost:5173"
echo " - Backend: http://localhost:8000"
echo " - Backend: http://localhost:8010"
echo " - Ngrok UI: http://localhost:4040"
echo ""
echo "=========================================="

27
start.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/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"