mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 11:12:54 +00:00
## Major Refactoring Based on Research: ### ❌ **Removed Over-Engineered Approach**: - Removed `gosu` dependency (unnecessary complexity) - Removed complex user switching in entrypoint - Removed root operations during runtime - Simplified permission management ### ✅ **Implemented 2025 Best Practices**: #### 1. **Simplified Dockerfile Pattern**: - Create directories with proper ownership in build stage - Set `USER django` once and keep it throughout - No complex user switching or runtime permission changes - Clean, standard Docker layering #### 2. **Industry-Standard Entrypoint**: - Simple script that runs as non-root user - Standard `exec "$@"` pattern - No permission operations during runtime - Follows container orchestration best practices #### 3. **Proper Architecture Documentation**: - Django/Gunicorn for dynamic content only - Nginx serves static files (6000+ req/sec vs Django's much lower) - Non-root user throughout for security - Clean service separation ## Benefits of This Approach: - ✅ **Security**: Non-root user throughout application lifecycle - ✅ **Simplicity**: Standard Docker patterns, no complex scripts - ✅ **Performance**: Nginx handles static files efficiently - ✅ **Maintainability**: Follows industry conventions - ✅ **Reliability**: Proven patterns used by major companies ## Research Sources: Based on 2025 best practices from: - TestDriven.io Django Docker patterns - Better Stack community guides - Official Django deployment documentation - Docker security best practices This follows the KISS principle while maintaining production-grade security and performance. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
50 lines
1.2 KiB
Docker
50 lines
1.2 KiB
Docker
FROM python:3.11-slim as base
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
postgresql-client \
|
|
build-essential \
|
|
libpq-dev \
|
|
gettext \
|
|
curl \
|
|
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
|
|
&& apt-get install -y nodejs \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
COPY requirements/base.txt /app/requirements/
|
|
RUN pip install --no-cache-dir -r requirements/base.txt
|
|
|
|
FROM base as development
|
|
|
|
COPY requirements/development.txt /app/requirements/
|
|
RUN pip install --no-cache-dir -r requirements/development.txt
|
|
|
|
COPY . /app/
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
|
|
|
|
FROM base as production
|
|
|
|
COPY requirements/production.txt /app/requirements/
|
|
RUN pip install --no-cache-dir -r requirements/production.txt
|
|
|
|
RUN groupadd -r django && useradd -r -g django django
|
|
|
|
COPY . /app/
|
|
|
|
# Create directories and set ownership - industry best practice
|
|
RUN mkdir -p /app/staticfiles /app/media && \
|
|
chown -R django:django /app
|
|
|
|
USER django
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "django_project.wsgi:application"] |