# Python API Server for Vendor Report Generator
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies (cached unless this changes)
RUN apt-get update && apt-get install -y \
    curl \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Upgrade pip and install build tools first (cached)
RUN pip install --upgrade pip setuptools wheel

# Copy requirements first for better caching
COPY requirements.txt .

# Install Python dependencies
# Remove --no-cache-dir to use pip's cache (much faster rebuilds)
# This layer will be cached unless requirements.txt changes
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

# Copy application files
# Docker automatically detects file changes via content hash
# If any .py file changes, only this layer and after rebuild (apt-get & pip stay cached!)
COPY *.py ./
COPY *.yaml* ./
COPY *.md ./

# Create directories for reports and output
RUN mkdir -p /app/reports /app/output

# Expose port (internal only, not exposed in docker-compose)
EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
    CMD curl -f http://localhost:8080/health || exit 1

# Run API server (uses environment variables for configuration)
CMD ["python", "api_server.py"]

