# Use NVIDIA's PyTorch image with CUDA support
FROM docker.io/pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Install system dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get install -y tzdata git ffmpeg libgl1 libglib2.0-0 && \
    rm -rf /var/lib/apt/lists/*

ARG UID=1000
ARG GID=1000
RUN groupadd --system --gid ${GID} worker && \
    adduser --system --gid ${GID} --uid ${UID} --home /home/worker worker

WORKDIR /home/worker
USER worker

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

# Install Python dependencies
RUN pip install --upgrade pip && \
    pip install -r requirements.txt && \
    rm -rf /home/worker/.cache/pip

# Expose port
EXPOSE 8188

# Run ComfyUI
CMD ["python", "main.py", "--listen", "0.0.0.0", "--port", "8188"]

