# Use the official ROCm base image
FROM ubuntu:26.04

# Set environment variables for 7900 XTX (gfx1100)
ENV PIP_BREAK_SYSTEM_PACKAGES=1
ENV PYTHONUNBUFFERED=1

RUN apt update -y && apt install -y --no-install-recommends \
    rocm-dev \
    rocm-libs \
    rocminfo \
    python3-pip \
    python3-dev \
    python3-torch-rocm \
    python3-torchaudio \
    git \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Clone ComfyUI
RUN git clone https://github.com/comfyanonymous/ComfyUI.git .

# Install ComfyUI dependencies
RUN grep -vE 'torch|torchaudio|torchvision' requirements.txt > req_no_torch.txt \
    && pip3 install --no-cache-dir -r req_no_torch.txt

# Set custom Nodes
WORKDIR /app/custom_nodes

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

# Go back to root
WORKDIR /app

# Expose the default ComfyUI port
EXPOSE 8188

# Launch ComfyUI
CMD ["python3", "main.py", "--listen", "0.0.0.0"]
