Skip to content

Commit b8a7a73

Browse files
committed
Apply migrations and superuser in Dockerfile entrypoint
1 parent 3d4e1df commit b8a7a73

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ RUN pip install --upgrade pip && \
2929
# Copy project files
3030
COPY . .
3131

32+
# Make entrypoint script executable
33+
RUN chmod +x /app/entrypoint.sh
34+
3235
# Create a non-root user
3336
RUN useradd -m appuser && chown -R appuser:appuser /app
3437
USER appuser
@@ -40,5 +43,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
4043
# Expose port
4144
EXPOSE 8000
4245

43-
# Run gunicorn
44-
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120", "--keep-alive", "5", "--max-requests", "1000", "--chdir", "src", "temple_web.wsgi:application"]
46+
# Set entrypoint
47+
ENTRYPOINT ["/app/entrypoint.sh"]

entrypoint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# you may be required to use python3 instead of python in some systems
4+
5+
# Apply database migrations
6+
python src/manage.py migrate
7+
8+
# Create superuser if needed
9+
python src/manage.py ensure_superuser
10+
11+
# Start Gunicorn
12+
exec gunicorn --bind 0.0.0.0:8000 --workers 3 --timeout 120 --keep-alive 5 --max-requests 1000 --chdir src temple_web.wsgi:application

0 commit comments

Comments
 (0)