Skip to content

Commit 9326c70

Browse files
committed
add docker entrypoint script for database migrations and server startup
1 parent d27f19b commit 9326c70

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

backend/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,12 @@ COPY ./app /app/app
4040
RUN --mount=type=cache,target=/root/.cache/uv \
4141
uv sync
4242

43-
# Use Uvicorn directly for better compatibility with Render's $PORT
44-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "${PORT:-8000}", "--workers", "4"]
43+
# Copy the entrypoint script
44+
COPY ./docker-entrypoint.sh /app/docker-entrypoint.sh
45+
RUN chmod +x /app/docker-entrypoint.sh
46+
47+
# Remove the old CMD
48+
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "${PORT:-8000}", "--workers", "4"]
49+
50+
# Set the entrypoint
51+
ENTRYPOINT ["/app/docker-entrypoint.sh"]

backend/docker-entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
set -e
5+
6+
# Run database migrations
7+
echo "Running database migrations..."
8+
alembic upgrade head
9+
10+
echo "Migrations finished. Starting server..."
11+
# Execute the command passed as arguments to this script (which will be the Docker CMD)
12+
# Or, directly execute the intended Uvicorn command if CMD is removed/changed
13+
exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000} --workers 4

0 commit comments

Comments
 (0)