FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04

# Prevent interactive prompts during install
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

# System dependencies
RUN apt-get update && apt-get install -y \
    python3.11 \
    python3.11-venv \
    python3-pip \
    git \
    wget \
    curl \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libexif12 \
    exiftool \
    ffmpeg \
    imagemagick \
    && rm -rf /var/lib/apt/lists/*

# Install Ollama
RUN curl -fsSL https://ollama.com/install.sh | sh

# Working directory
WORKDIR /app

# Python dependencies first (cache layer)
COPY requirements.txt .
RUN python3.11 -m pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create data directories
RUN mkdir -p /app/data/reference_photos \
    /app/data/prnu_samples \
    /app/data/backgrounds \
    /app/data/output

# Startup script
COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Expose Ollama port (internal only)
EXPOSE 11434

ENTRYPOINT ["/entrypoint.sh"]
CMD ["python3.11", "src/main.py"]