# Auto-generated by ninja-deploy for {{ app_name }}
# Multi-stage build for {{ project_name }}

FROM python:3.12-slim AS builder

WORKDIR /build

# Install uv for fast dependency resolution
RUN pip install --no-cache-dir uv

# Copy dependency files first for layer caching
COPY pyproject.toml uv.lock ./
COPY libs/ libs/
COPY apps/{{ app_name }}/ apps/{{ app_name }}/

# Install dependencies
RUN uv sync --frozen --no-dev

FROM python:3.12-slim AS runtime

WORKDIR /app

# Create non-root user
RUN groupadd --gid 1000 appuser && \
    useradd --uid 1000 --gid appuser --create-home appuser

# Copy installed packages and app code
COPY --from=builder /build/.venv /app/.venv
COPY --from=builder /build/libs /app/libs
COPY --from=builder /build/apps/{{ app_name }} /app/apps/{{ app_name }}

ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=1

USER appuser

EXPOSE {{ port }}

CMD ["uvicorn", "{{ module }}", "--host", "0.0.0.0", "--port", "{{ port }}"]
