# GPU destekli CUDA base image (Ubuntu 22.04 tabanlı)
FROM nvidia/cuda:12.2.0-base-ubuntu22.04

# Go 1.25 kur
RUN apt-get update && apt-get install -y wget git curl build-essential && \
    wget https://go.dev/dl/go1.25.0.linux-amd64.tar.gz && \
    tar -C /usr/local -xzf go1.25.0.linux-amd64.tar.gz && \
    rm go1.25.0.linux-amd64.tar.gz

ENV PATH=$PATH:/usr/local/go/bin

# ffmpeg ve ffprobe (NVENC destekli)
RUN apt-get update && apt-get install -y ffmpeg libavcodec-extra && \
    rm -rf /var/lib/apt/lists/*

# FreeCAD ve Python3 bağımlılıkları
RUN apt-get update && apt-get install -y \
    software-properties-common \
    python3 \
    python3-pip \
    python3-dev && \
    add-apt-repository ppa:freecad-maintainers/freecad-stable && \
    apt-get update && \
    apt-get install -y freecad-python3 && \
    rm -rf /var/lib/apt/lists/*

# Python Flask ve bağımlılıkları
RUN pip3 install --no-cache-dir flask werkzeug

# Hot reload için Air yükle
RUN go install github.com/air-verse/air@latest

# Çalışma dizini
WORKDIR /app

# Go modüllerini indir
COPY go.mod go.sum ./
RUN go mod download

# Startup script'i önce kopyala
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh

# Tüm proje dosyalarını kopyala
COPY . .

# Python scripts klasörü oluştur
RUN mkdir -p /app/python_scripts

# Environment variables
ENV FREECAD_API_URL=http://localhost:8090
ENV FREECAD_API_PORT=8090
ENV PYTHONPATH=/app/python_scripts:$PYTHONPATH

# Startup script ile başlat
CMD ["/app/start.sh"]
