42 lines
910 B
Bash
42 lines
910 B
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
echo "Waiting for database..."
|
|
python - <<'PY'
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
from sqlalchemy import text
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
|
|
|
|
async def wait_db(retries: int = 40) -> None:
|
|
url = os.environ["DATABASE_URL"]
|
|
engine = create_async_engine(url)
|
|
for i in range(retries):
|
|
try:
|
|
async with engine.connect() as conn:
|
|
await conn.execute(text("SELECT 1"))
|
|
await engine.dispose()
|
|
print("Database is ready")
|
|
return
|
|
except Exception as exc: # noqa: BLE001
|
|
print(f"DB not ready ({i + 1}/{retries}): {exc}")
|
|
await asyncio.sleep(1)
|
|
await engine.dispose()
|
|
sys.exit(1)
|
|
|
|
|
|
asyncio.run(wait_db())
|
|
PY
|
|
|
|
echo "Running migrations..."
|
|
alembic upgrade head
|
|
|
|
echo "Bootstrapping admin..."
|
|
python -m app.bootstrap
|
|
|
|
echo "Starting application..."
|
|
exec "$@"
|