#!/usr/bin/env bash set -e echo "============================================" echo " MTG Online Backend - Starting" echo " $(date -u '+%Y-%m-%d %H:%M:%S UTC')" echo "============================================" # Wait for PostgreSQL to be ready echo "[entrypoint] Waiting for PostgreSQL databases..." for db in mtgo_platform mtgdata mtgo_mirror; do host="postgres_${db}" echo " Checking ${host}..." until python -c " import asyncio, asyncpg async def check(): try: conn = await asyncpg.connect(host='${host}', port=5432, user='postgres', password='postgres', database='${db}') await conn.close() return True except Exception: return False asyncio.run(check()) " 2>/dev/null; do echo " ${host} not ready, waiting 2s..." sleep 2 done echo " ${host} is ready!" done # Wait for Redis to be ready echo "[entrypoint] Waiting for Redis..." until python -c " import asyncio, redis.asyncio as aioredis async def check(): try: r = aioredis.from_url('redis://redis:6379/0') await r.ping() await r.close() return True except Exception: return False asyncio.run(check()) " 2>/dev/null; do echo " Redis not ready, waiting 2s..." sleep 2 done echo " Redis is ready!" # Run database migrations echo "[entrypoint] Running Alembic migrations..." python -m alembic upgrade head echo "[entrypoint] Migrations complete." # Start the application echo "[entrypoint] Starting uvicorn..." exec python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --forwarded-allow-ips '*' --log-level info