# NVIDIA CUDA + Python base (GPU desteği)
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04

# Sistem bağımlılıkları
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 python3-pip python3-dev \
    build-essential gcc g++ \
    libgl1-mesa-glx libglib2.0-0 \
    curl wget \
    && pip3 install --no-cache-dir cython \
    && rm -rf /var/lib/apt/lists/*

# Timezone
ENV TZ=Europe/Istanbul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Çalışma dizini
WORKDIR /app

# Python bağımlılıkları
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

# Model indirme scripti
COPY download_models.py .
RUN python3 download_models.py

# Uygulama kodu
COPY app.py .

# Port
EXPOSE 8100

# GPU memory ayarları
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
ENV ORT_CUDA_ARENA_EXTEND_STRATEGY=kNextPowerOfTwo

# Başlat
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8100", "--workers", "1", "--log-level", "info"]
