53 lines
1.2 KiB
Docker
53 lines
1.2 KiB
Docker
# ============================
|
|
# 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 7080
|
|
|
|
# Run Django with uvicorn
|
|
CMD ["uvicorn", "MPM:application", "--host", "0.0.0.0", "--port", "7080"]
|