1- # Dockerfile
1+ # Base Image - slim Python
2+ FROM python:3.13-slim
23
3- # Base Image
4- FROM python:3. 8
4+ # Environment settings
5+ ENV PYTHONUNBUFFERED=1 LANG=C.UTF- 8
56
6- # set default environment variables
7- ENV PYTHONUNBUFFERED 1
8- ENV LANG C.UTF-8
9-
10- # to take runtime arguments and set env variables
7+ # Django superuser build args
118ARG DJANGO_SUPERUSER_USERNAME
12- ENV DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME}
13-
149ARG DJANGO_SUPERUSER_PASSWORD
15- ENV DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
16-
1710ARG DJANGO_SUPERUSER_EMAIL
11+ ENV DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME}
12+ ENV DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
1813ENV DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL}
1914
20- # create and set working directory
21- RUN mkdir /app
15+ # Set workdir
2216WORKDIR /app
2317
24- RUN chown -R www-data:www-data /app
25-
26- # Add current directory code to working directory
27- COPY . /app/
28-
29- # install environment dependencies
30- RUN pip install -r requirements.txt
31-
32- # install nginx
33- RUN apt-get update && apt-get install nginx vim -y --no-install-recommends
18+ # Install system dependencies and nginx, then install Python deps
19+ COPY requirements.txt .
20+ RUN apt-get update && \
21+ apt-get install -y --no-install-recommends nginx vim && \
22+ pip install --no-cache-dir -r requirements.txt && \
23+ rm -rf /var/lib/apt/lists/*
3424
35- # Refer https://github.com/devtron-labs/devtron/blob/main/sample-docker-templates/django/nginx.default for sample nginx.default file
36- COPY nginx.default /etc/nginx/sites-available/default
25+ # Copy app code, nginx.conf, and start script
26+ COPY app/ ./
27+ COPY nginx.conf /etc/nginx/nginx.conf
28+ RUN chmod +x start-server.sh
3729
38- RUN ln -sf /dev/stdout /var/log/nginx/access.log \
39- && ln -sf /dev/stderr /var/log/nginx/error.log
30+ # Create non-root user and set permissions
31+ RUN groupadd -g 2002 nonroot && \
32+ useradd -u 2002 -g nonroot -s /bin/bash -m nonroot && \
33+ mkdir -p /tmp/nginx-logs && \
34+ chown -R nonroot:nonroot /app /tmp/nginx-logs
4035
36+ # Expose port 8080
37+ EXPOSE 8080
4138
42- # start server
43- EXPOSE 8000
39+ # Switch to non-root
40+ USER nonroot
4441
42+ # Stop signal for graceful shutdown
43+ # https://docs.docker.com/reference/dockerfile/#stopsignal
4544STOPSIGNAL SIGTERM
4645
47- # Refer https://github.com/devtron-labs/devtron/blob/main/sample-docker-templates/django/start- server.sh for sample start-server.sh file
46+ # Start server (migrations, superuser, gunicorn, nginx)
4847CMD ["/app/start-server.sh" ]
0 commit comments