From 621129092311732e2ffa721bad15d45e5f4111ad Mon Sep 17 00:00:00 2001 From: Ami Date: Tue, 21 Apr 2026 17:36:47 +0700 Subject: [PATCH] fix: add alembic dir to image + run migrations in entrypoint --- Dockerfile | 1 + entrypoint.sh | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3137fd..819d70c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,7 @@ COPY --from=builder /install /usr/local # Copy application code COPY apps/api/src ./src +COPY apps/api/alembic ./alembic COPY apps/scanner/src ./src_scanner RUN if [ -d src_scanner ]; then \ diff --git a/entrypoint.sh b/entrypoint.sh index 7b131c2..1c62463 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,6 @@ set -e # Extract host and port from DATABASE_URL -# Format: postgresql+asyncpg://user:pass@host:port/dbname DB_HOST=$(echo "$DATABASE_URL" | sed -E 's|.*@([^/:]+).*|\1|') DB_PORT=$(echo "$DATABASE_URL" | sed -E 's|.*@[^/:]+:([0-9]+)/.*|\1|') @@ -14,7 +13,11 @@ echo "Waiting for postgres at $DB_HOST:$DB_PORT ..." max_retries=30 counter=0 -until pg_isready -h "$DB_HOST" -p "$DB_PORT" -q 2>/dev/null; do +until ( + pg_isready -h "$DB_HOST" -p "$DB_PORT" -q 2>/dev/null +) || ( + (echo > /dev/tcp/"$DB_HOST"/"$DB_PORT") 2>/dev/null +); do counter=$((counter + 1)) if [ $counter -ge $max_retries ]; then echo "ERROR: postgres at $DB_HOST:$DB_PORT not ready after ${max_retries}s" @@ -26,4 +29,11 @@ done echo "postgres is ready!" +# Run alembic migrations +if [ -f /app/alembic/env.py ]; then + echo "Running database migrations ..." + python -m alembic upgrade head + echo "Migrations complete!" +fi + exec "$@"