predictor / services /api /render_start.sh
pengpeng9099's picture
Deploy World Cup 2026 Predictor (docker space)
1790bde verified
Raw History Blame Contribute Delete
951 Bytes
#!/bin/bash
# Render startup: ensure API data exists, then start API.
set -e
export PYTHONUTF8=1 PYTHONIOENCODING=utf-8
cd "$(dirname "$0")/../.."
echo "-- Checking API data --"
DB_READY="$(python - <<'PY'
import sqlite3
from pathlib import Path
db = Path("data/worldcup.db")
if not db.exists():
print("0")
else:
try:
with sqlite3.connect(db) as conn:
n = conn.execute("SELECT COUNT(*) FROM model_runs").fetchone()[0]
print("1" if n else "0")
except Exception:
print("0")
PY
)"
if [ "$DB_READY" != "1" ]; then
echo "-- Building database and model outputs --"
cd services/model
python ingest.py
if [ ! -f artifacts/dixon_coles.pkl ]; then
python backtest.py
fi
python pipeline.py "${N_SIMS:-5000}"
cd ../..
else
echo "-- Using prebuilt database --"
fi
echo "-- Starting API --"
cd services/api
python -m uvicorn main:app --host 0.0.0.0 --port "${PORT:-8000}"