27 lines
932 B
Bash
27 lines
932 B
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Container entrypoint: bring the accounts schema up to head, then serve.
|
||
|
|
#
|
||
|
|
# Alembic runs before uvicorn so a fresh Postgres volume gets its tables. It is
|
||
|
|
# retried because `db` can still be finishing startup even though compose waits on
|
||
|
|
# its healthcheck — a cold volume's first connection may race the server becoming
|
||
|
|
# ready to accept the migration.
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
cd /app/backend
|
||
|
|
|
||
|
|
max=10
|
||
|
|
tries=0
|
||
|
|
echo "==> Running database migrations (alembic upgrade head)"
|
||
|
|
until alembic upgrade head; do
|
||
|
|
tries=$((tries + 1))
|
||
|
|
if [ "$tries" -ge "$max" ]; then
|
||
|
|
echo "!! alembic upgrade head failed after ${max} attempts; giving up" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
echo " migration attempt ${tries}/${max} failed; retrying in 3s..." >&2
|
||
|
|
sleep 3
|
||
|
|
done
|
||
|
|
|
||
|
|
echo "==> Starting uvicorn on 0.0.0.0:${PORT:-8137} with ${WORKERS:-4} worker(s)"
|
||
|
|
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-8137}" --workers "${WORKERS:-4}"
|