39 lines
1.5 KiB
Bash
39 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ────────────────────────────────────────────────
|
|
# Entrypoint: Run migrations, then start the app.
|
|
# ────────────────────────────────────────────────
|
|
|
|
echo "[entrypoint] Waiting for database to be ready..."
|
|
|
|
# Wait for PostgreSQL to accept connections (max 30s retries)
|
|
for i in $(seq 1 30); do
|
|
if python -c "import asyncpg,os,asyncio; asyncio.run(asyncpg.connect(
|
|
host=os.getenv('POSTGRES_HOST','192.168.178.3'),
|
|
port=int(os.getenv('POSTGRES_PORT','5432')),
|
|
user=os.getenv('POSTGRES_USER','postgres'),
|
|
password=os.getenv('POSTGRES_PASSWORD'),
|
|
database=os.getenv('POSTGRES_DB','postgres'),
|
|
))" 2>/dev/null; then
|
|
echo "[entrypoint] Database is ready."
|
|
break
|
|
fi
|
|
if [ "$i" -eq 30 ]; then
|
|
echo "[entrypoint] ERROR: Could not connect to database after 30 attempts." >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# ── Run migrations ──────────────────────────────
|
|
echo "[entrypoint] Running database migrations..."
|
|
python /app/migrate.py || {
|
|
echo "[entrypoint] ERROR: Migration failed — aborting startup." >&2
|
|
exit 1
|
|
}
|
|
echo "[entrypoint] Migrations complete."
|
|
|
|
# ── Start the application ───────────────────────
|
|
exec "$@"
|