-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathentrypoint.sh
More file actions
29 lines (25 loc) · 837 Bytes
/
entrypoint.sh
File metadata and controls
29 lines (25 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
set -eu
DB_HOST="${POSTGRES_HOST:-db}"
DB_PORT="${POSTGRES_PORT:-5432}"
DB_NAME="${POSTGRES_DB:-postgres}"
APP_MODULE="${APP_MODULE:-main:app}"
APP_PORT="${APP_PORT:-8000}"
RUN_MIGRATIONS="${RUN_MIGRATIONS:-true}"
UVICORN_RELOAD="${UVICORN_RELOAD:-false}"
# Wait for PostgreSQL to be ready
until PGPASSWORD="$POSTGRES_PASSWORD" pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$POSTGRES_USER" -d "$DB_NAME"; do
echo "Waiting for postgres at ${DB_HOST}:${DB_PORT}/${DB_NAME}..."
sleep 2
done
echo "PostgreSQL is ready!"
if [ "$RUN_MIGRATIONS" = "true" ]; then
echo "Applying migrations..."
alembic upgrade head
fi
echo "Starting the application..."
if [ "$UVICORN_RELOAD" = "true" ]; then
uvicorn "$APP_MODULE" --host 0.0.0.0 --port "$APP_PORT" --reload
else
uvicorn "$APP_MODULE" --host 0.0.0.0 --port "$APP_PORT"
fi