# 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.59

RUN pip install imageio controlnet_aux

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 | xargs pip install && \
    pip install torchsde

WORKDIR /app/comfyui/custom_nodes

RUN git clone https://github.com/Comfy-Org/ComfyUI-Manager.git

WORKDIR /app/comfyui

EXPOSE 8188

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