Merge pull request #9 from whtvrboo/fix/docker-migrations

Fix(docker): Run Alembic migrations on container startup
This commit is contained in:
whtvrboo 2025-06-01 19:10:53 +02:00 committed by GitHub
commit c50395ae86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View File

@ -49,6 +49,8 @@ COPY --chown=appuser:appuser alembic/ ./alembic/
COPY --chown=appuser:appuser alembic.ini ./ COPY --chown=appuser:appuser alembic.ini ./
COPY --chown=appuser:appuser *.py ./ COPY --chown=appuser:appuser *.py ./
COPY --chown=appuser:appuser requirements.txt ./ COPY --chown=appuser:appuser requirements.txt ./
COPY --chown=appuser:appuser entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
# Create logs directory # Create logs directory
RUN mkdir -p /app/logs && chown -R appuser:appuser /app RUN mkdir -p /app/logs && chown -R appuser:appuser /app
@ -64,6 +66,7 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
EXPOSE 8000 EXPOSE 8000
# Production command # Production command
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["uvicorn", "app.main:app", \ CMD ["uvicorn", "app.main:app", \
"--host", "0.0.0.0", \ "--host", "0.0.0.0", \
"--port", "8000", \ "--port", "8000", \

10
be/entrypoint.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
set -e
# Run database migrations
echo "Running database migrations..."
alembic upgrade head
# Execute the command passed as arguments to this script
echo "Starting application..."
exec "$@"

View File

@ -33,7 +33,7 @@ services:
# Pass the database URL to the backend container # Pass the database URL to the backend container
# Uses the service name 'db' as the host, and credentials defined above # Uses the service name 'db' as the host, and credentials defined above
# IMPORTANT: Use the correct async driver prefix if your app needs it! # IMPORTANT: Use the correct async driver prefix if your app needs it!
- DATABASE_URL=xxx - DATABASE_URL=postgresql+asyncpg://mitlist_owner:npg_p0SkmyJ6BPWO@ep-small-sound-a9ketcef-pooler.gwc.azure.neon.tech/testnewmig
- GEMINI_API_KEY=xxx - GEMINI_API_KEY=xxx
- SECRET_KEY=xxx - SECRET_KEY=xxx
# Add other environment variables needed by the backend here # Add other environment variables needed by the backend here