# Lightweight Dockerfile for changelog generation
FROM python:3.12.8-slim-bookworm

# Install system dependencies
RUN apt-get update && \
    apt-get install -y curl && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy files needed for changelog generation to the expected structure
COPY . /app/genai-engine/

# Install uv
RUN pip3 install uv==0.11.7

# Set environment variables
ENV PYTHONPATH="$PYTHONPATH:/app/genai-engine/src"

# Install only the minimal dependencies needed for changelog generation
# We need FastAPI and its dependencies, but not the heavy ML dependencies
WORKDIR /app/genai-engine
RUN UV_SYSTEM_PYTHON=1 uv sync --frozen --no-install-project

# Install oasdiff - detect architecture and install correct version
RUN ARCH=$(dpkg --print-architecture) && \
    if [ "$ARCH" = "amd64" ]; then \
        curl -L -o oasdiff.deb https://github.com/Tufin/oasdiff/releases/download/v1.11.7/oasdiff_1.11.7_linux_amd64.deb; \
    elif [ "$ARCH" = "arm64" ]; then \
        curl -L -o oasdiff.deb https://github.com/Tufin/oasdiff/releases/download/v1.11.7/oasdiff_1.11.7_linux_arm64.deb; \
    else \
        echo "Unsupported architecture: $ARCH" && exit 1; \
    fi && \
    dpkg -i oasdiff.deb && \
    rm oasdiff.deb

# Set the default command
WORKDIR /app
CMD ["bash", "-c", "cd genai-engine && uv run python changelog.py"]
