Ajusta bootstrap e portas para subida sem conflitos
This commit is contained in:
@@ -150,7 +150,7 @@ ORACLE_DSN=host:1521/service_name
|
|||||||
poetry run python src/main.py
|
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
|
### Frontend
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ cp .env.example .env
|
|||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
- Backend: `http://localhost:8000`
|
- Backend: `http://localhost:8010`
|
||||||
- Frontend: `http://localhost`
|
- Frontend: `http://localhost`
|
||||||
|
|
||||||
## Endpoints da API
|
## Endpoints da API
|
||||||
@@ -231,8 +231,8 @@ Health check da API.
|
|||||||
## Documentação da API
|
## Documentação da API
|
||||||
|
|
||||||
Após iniciar o backend, acesse:
|
Após iniciar o backend, acesse:
|
||||||
- Swagger UI: `http://localhost:8000/docs`
|
- Swagger UI: `http://localhost:8010/docs`
|
||||||
- ReDoc: `http://localhost:8000/redoc`
|
- ReDoc: `http://localhost:8010/redoc`
|
||||||
|
|
||||||
## Desenvolvimento
|
## Desenvolvimento
|
||||||
|
|
||||||
|
|||||||
32
backend/scripts/bootstrap_ranking.sh
Normal file → Executable file
32
backend/scripts/bootstrap_ranking.sh
Normal file → Executable file
@@ -1,6 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
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
|
# Configs
|
||||||
DSN_CANDIDATES=()
|
DSN_CANDIDATES=()
|
||||||
if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
|
if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
|
||||||
@@ -8,7 +17,6 @@ if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
|
|||||||
fi
|
fi
|
||||||
DSN_CANDIDATES+=("127.0.0.1:1521/XEPDB1" "oracle18c:1521/XEPDB1" "mqapilc_oracle18c:1521/XEPDB1")
|
DSN_CANDIDATES+=("127.0.0.1:1521/XEPDB1" "oracle18c:1521/XEPDB1" "mqapilc_oracle18c:1521/XEPDB1")
|
||||||
API_URL=${API_URL:-"http://localhost:8000"}
|
API_URL=${API_URL:-"http://localhost:8000"}
|
||||||
VENV_PY="./venv/bin/python"
|
|
||||||
|
|
||||||
echo "[1/5] Aguardando Oracle..."
|
echo "[1/5] Aguardando Oracle..."
|
||||||
DSN_HOST=""
|
DSN_HOST=""
|
||||||
@@ -44,6 +52,14 @@ cur.close();conn.close()
|
|||||||
PY
|
PY
|
||||||
)
|
)
|
||||||
echo " Registros na TB_RANKING_CONSULTOR: ${COUNT}"
|
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
|
if [ "${COUNT}" -eq 0 ]; then
|
||||||
echo "[3/5] Rodando job de ranking (A/C/D)..."
|
echo "[3/5] Rodando job de ranking (A/C/D)..."
|
||||||
@@ -51,7 +67,7 @@ if [ "${COUNT}" -eq 0 ]; then
|
|||||||
# Espera concluir
|
# Espera concluir
|
||||||
while true; do
|
while true; do
|
||||||
STATUS=$(curl -s "${API_URL}/api/v1/ranking/status")
|
STATUS=$(curl -s "${API_URL}/api/v1/ranking/status")
|
||||||
running=$(python - <<'PY'
|
running=$($VENV_PY - <<'PY'
|
||||||
import os, json
|
import os, json
|
||||||
data=json.loads(os.environ["STATUS"])
|
data=json.loads(os.environ["STATUS"])
|
||||||
print(data.get("running", False))
|
print(data.get("running", False))
|
||||||
@@ -63,10 +79,21 @@ STATUS="$STATUS")
|
|||||||
fi
|
fi
|
||||||
sleep 20
|
sleep 20
|
||||||
done
|
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
|
fi
|
||||||
|
|
||||||
|
if [ "${NEED_B}" = "yes" ]; then
|
||||||
echo "[4/5] Rodando Componente B (PPG)..."
|
echo "[4/5] Rodando Componente B (PPG)..."
|
||||||
ORACLE_LOCAL_DSN=${DSN_HOST} PYTHONUNBUFFERED=1 $VENV_PY scripts/popular_componente_b.py
|
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:"
|
echo "[5/5] Contagens finais:"
|
||||||
$VENV_PY - <<PY
|
$VENV_PY - <<PY
|
||||||
@@ -75,6 +102,7 @@ conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
|
|||||||
cur=conn.cursor()
|
cur=conn.cursor()
|
||||||
cur.execute("select count(*) from tb_ranking_consultor"); print("total",cur.fetchone()[0])
|
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 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.execute("select max(pontuacao_total) from tb_ranking_consultor"); print("max total",cur.fetchone()[0])
|
||||||
cur.close();conn.close()
|
cur.close();conn.close()
|
||||||
PY
|
PY
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ services:
|
|||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8010:8000"
|
||||||
env_file:
|
env_file:
|
||||||
- ./backend/.env
|
- ./backend/.env
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ echo "[1/5] Parando containers antigos..."
|
|||||||
docker compose down 2>/dev/null
|
docker compose down 2>/dev/null
|
||||||
|
|
||||||
echo "[2/5] Limpando portas ocupadas..."
|
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
|
sudo fuser -k 5173/tcp 2>/dev/null
|
||||||
|
|
||||||
echo "[3/5] Matando ngrok antigo..."
|
echo "[3/5] Matando ngrok antigo..."
|
||||||
@@ -57,7 +57,7 @@ echo " URL Publica (ngrok): $NGROK_URL"
|
|||||||
echo ""
|
echo ""
|
||||||
echo " URLs Locais:"
|
echo " URLs Locais:"
|
||||||
echo " - Frontend: http://localhost:5173"
|
echo " - Frontend: http://localhost:5173"
|
||||||
echo " - Backend: http://localhost:8000"
|
echo " - Backend: http://localhost:8010"
|
||||||
echo " - Ngrok UI: http://localhost:4040"
|
echo " - Ngrok UI: http://localhost:4040"
|
||||||
echo ""
|
echo ""
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
|
|||||||
27
start.sh
Executable file
27
start.sh
Executable 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"
|
||||||
Reference in New Issue
Block a user