From 4af9049937c1d92f7ed2d14b11e1c897e6d5a3c8 Mon Sep 17 00:00:00 2001 From: bartool Date: Sat, 29 Nov 2025 19:30:39 +0100 Subject: [PATCH] add dockerfile for backend --- backand/Dockerfile | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 backand/Dockerfile diff --git a/backand/Dockerfile b/backand/Dockerfile new file mode 100644 index 0000000..39fc5b3 --- /dev/null +++ b/backand/Dockerfile @@ -0,0 +1,52 @@ +# ============================ +# Stage 1: Build dependencies +# ============================ +FROM python:3.13-slim AS builder + +# Optimize Python +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +# Install build tools (if needed for wheels) +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Create app working directory +WORKDIR /app + +# Install Python dependencies +COPY requirements.txt . +RUN pip install --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt + +# ============================ +# Stage 2: Production image +# ============================ +FROM python:3.13-slim + +# Optimize Python +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +# Create non-root user +RUN useradd -m -r appuser + +# Create working directory +WORKDIR /app + +# Copy installed dependencies from builder +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/ + +# Copy application code with ownership +COPY --chown=appuser:appuser . . + +# Switch to non-root user +USER appuser + +# Expose Django port +EXPOSE 8000 + +# Run Django with uvicorn +CMD ["uvicorn", "MPM:application", "--host", "0.0.0.0", "--port", "7080"]