# syntax=docker/dockerfile:1.7
# Lesson 02: multi-stage build with BuildKit cache mount.

# --- Stage 1: builder ---
FROM python:3.11-slim AS builder
WORKDIR /build
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install --no-cache-dir --prefix=/install -r requirements.txt

# --- Stage 2: runtime ---
FROM python:3.11-slim

# Bring just the installed packages forward.
COPY --from=builder /install /usr/local

# Non-root user (from L01 homework).
RUN useradd --create-home --uid 1000 app
WORKDIR /app
COPY --chown=app:app app.py .
USER app

EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
