# syntax=docker/dockerfile:1
FROM python:3.13-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    && rm -rf /var/lib/apt/lists/*

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

# Set up working directory
WORKDIR /app

# Copy dependency files
COPY pyproject.toml uv.lock ./

# Install dependencies
RUN uv pip install --system --no-cache-dir --compile-bytecode -e .

# Copy source code
COPY src/ ./src/

# Build wheel
RUN uv pip install --system build && \
    python -m build --wheel --outdir /dist

# Runtime stage
FROM python:3.13-slim

# Create non-root user
RUN useradd -m -u 1000 appuser

# Install runtime dependencies
COPY --from=builder /dist/*.whl /tmp/
RUN pip install --no-cache-dir /tmp/*.whl && \
    rm -rf /tmp/*

# Switch to non-root user
USER appuser

# Set entrypoint
ENTRYPOINT ["python", "-m", "boilerplate"]
CMD ["--help"]