FROM nvcr.io/nvidia/pytorch:26.01-py3
ENV DEBIAN_FRONTEND=noninteractive

# 1. Système
RUN apt-get update && apt-get install -y \
    openssh-server ffmpeg libsndfile1 sox git curl zstd \
    libgl1 libglib2.0-0 net-tools \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# 2. Python & Dépendances
RUN pip install --no-cache-dir numpy==1.26.4
RUN pip install --no-cache-dir \
    open-webui gradio scipy soundfile julius omegaconf hydra-core \
    flashy torchmetrics encodec xformers einops spacy==3.7.6
RUN pip install --no-cache-dir --no-deps git+https://github.com/facebookresearch/audiocraft.git

# 3. Ollama & Comfy
RUN curl -fsSL https://ollama.ai/install.sh | sh
WORKDIR /root
RUN git clone https://github.com/comfyanonymous/ComfyUI.git && \
    cd ComfyUI && pip install --no-cache-dir -r requirements.txt

# 4. Code applicatif
RUN mkdir -p /root/audiocraft-api
COPY server.py /root/audiocraft-api/server.py

# 5. Script de démarrage robuste (Heredoc sans erreur de syntaxe)
RUN cat <<'EOF' > /start.sh
#!/bin/bash
service ssh start
ollama serve > /root/ollama.log 2>&1 &
open-webui serve --port 3000 > /root/webui.log 2>&1 &
python3 /root/ComfyUI/main.py --listen 0.0.0.0 --port 8188 > /root/comfy.log 2>&1 &
python3 /root/audiocraft-api/server.py > /root/audio.log 2>&1 &
echo "Studio Ready"
sleep infinity
EOF
RUN chmod +x /start.sh

EXPOSE 22 3000 7860 8188 11434
ENTRYPOINT ["/bin/bash", "/start.sh"]