# Get cuda version from https://hub.docker.com/r/nvidia/cuda
FROM nvcr.io/nvidia/pytorch:25.05-py3 AS build-deps

WORKDIR /app

# Get release version from https://github.com/comfyanonymous/ComfyUI/releases
ARG ComfyUI_Release=0.3.43

RUN wget https://github.com/comfyanonymous/ComfyUI/archive/refs/tags/v${ComfyUI_Release}.tar.gz && \
    tar xzf v${ComfyUI_Release}.tar.gz && \
    rm v${ComfyUI_Release}.tar.gz && \
    mv /app/ComfyUI-${ComfyUI_Release} /app/comfyui/

WORKDIR /app/comfyui

RUN ln -sf /usr/bin/python3 /usr/bin/python && \
    ln -sf /usr/bin/pip3 /usr/bin/pip

#RUN grep -vE "^(torch|#)" requirements.txt | sed 's/==.*//' | sed 's/>=.*//' | sed 's/~=.*//' | xargs pip install
RUN grep -vE "^(torch|#)" requirements.txt | xargs pip install && \
    pip install torchsde

EXPOSE 8188

CMD ["python", "main.py", "--listen", "0.0.0.0"]
