-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.django
More file actions
42 lines (30 loc) · 1.08 KB
/
Dockerfile.django
File metadata and controls
42 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Stage 1: Build based requirements
FROM python:3.13-slim AS builder
RUN mkdir /app
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ARG REQ_ENV=prod
RUN pip install --upgrade pip
COPY requirements/${REQ_ENV}-requirements.txt /app/
RUN pip install pip-tools
RUN pip install --no-cache-dir -r ${REQ_ENV}-requirements.txt
# Stage 2: Production stage
FROM python:3.13-slim
RUN useradd -m -r appuser && \
mkdir /app && \
chown -R appuser /app
# Copy the Python dependencies from the builder stage
COPY --from=builder /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
WORKDIR /app
COPY --chown=appuser:appuser static_compiled ./static_compiled
COPY --chown=appuser:appuser media ./media
COPY --chown=appuser:appuser django_app .
# Set environment variables to optimize Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
USER appuser
EXPOSE 8000
# Start the application using Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "citycouncil.wsgi:application"]