Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Dockerfile.byow
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
FROM nvcr.io/nvidia/pytorch:25.03-py3

# Environment setup
ENV TZ="Etc/UTC"
ENV PYTORCH_CUDA_ALLOC_CONF="backend:cudaMallocAsync,expandable_segments:True"
ENV UV_COMPILE_BYTECODE=1
ENV UV_NO_CACHE=1
ENV UV_SYSTEM_PYTHON=1
# ENV UV_OVERRIDE=/workspace/constraints.txt
# COPY src/comfystream/scripts/constraints.txt /workspace/constraints.txt
ENV UV_BREAK_SYSTEM_PACKAGES=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

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

RUN pip install uv && uv --version && \
apt-get update && apt-get install --no-install-recommends ffmpeg libsm6 libxext6 -y && \
uv pip uninstall --system $(pip list --format=freeze | grep opencv) && \
rm -rf /usr/local/lib/python3.12/dist-packages/cv2/ && \
uv pip install wheel && \
uv pip install --no-build-isolation "opencv-contrib-python-headless!=4.11.0.86" && \
rm -rf /var/lib/apt/lists/*

# Install torchaudio with the correct version
COPY docker/install-torchaudio.sh /usr/local/bin/install-torchaudio.sh
RUN chmod +x /usr/local/bin/install-torchaudio.sh && \
/usr/local/bin/install-torchaudio.sh

# Create mount point for user's ComfyUI workspace
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
RUN git clone https://github.com/Comfy-Org/ComfyUI-Manager.git /workspace/ComfyUI/custom_nodes/ComfyUI-Manager

COPY src/comfystream/scripts /workspace/tmp/scripts
COPY configs /workspace/tmp/configs

COPY docker/entrypoint-byow.sh /usr/local/bin/comfyui-entrypoint.sh
RUN chmod +x /usr/local/bin/comfyui-entrypoint.sh

# Create venv in ComfyUI workspace and set uv enc default to it
WORKDIR /workspace/ComfyUI
RUN uv venv .venv
ENV VIRTUAL_ENV=/workspace/ComfyUI/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install comfy-cli
RUN uv pip install comfy-cli

#RUN comfy --here --skip-prompt install --skip-torch-or-directml
#RUN uv pip install --torch-backend=auto "comfyui@git+https://github.com/hiddenswitch/ComfyUI.git@e62df3a8811d8c652a195d4669f4fb27f6c9a9ba"
RUN uv pip install -r /workspace/ComfyUI/custom_nodes/ComfyUI-Manager/requirements.txt
RUN comfy --skip-prompt set-default /workspace/ComfyUI
# RUN comfy node install comfystream --fast-deps
RUN comfy node install comfystream --mode local comfystream --fast-deps

# WORKDIR /workspace/tmp
COPY scripts /workspace/ComfyUI/custom_nodes/src/comfystream/scripts
COPY configs /workspace/ComfyUI/custom_nodes/comfystream/configs

RUN mkdir -p /tmp

# Set working directory to the mount point
WORKDIR /workspace/ComfyUI
COPY docker/entrypoint-byow.sh /tmp/entrypoint.sh
RUN chmod +x /tmp/entrypoint.sh

# Set the entrypoint
# ENTRYPOINT ["/etc/local/bin/comfyui-entrypoint.sh"]

#Testing only
#ENTRYPOINT ["/tmp/entrypoint.sh"]

# Default command (can be overridden)
CMD []

# Expose ComfyUI port
EXPOSE 8188

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8188/system_stats || exit 1
158 changes: 158 additions & 0 deletions Dockerfile.uv
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
ARG BASE_IMAGE=nvidia/cuda:12.8.0-cudnn-devel-ubuntu24.04 \
PYTHON_VERSION=3.12 \
INSTALL_EXTRA_PACKAGES=false \
INSTALL_NODES=false

FROM "${BASE_IMAGE}"

ARG PYTHON_VERSION \
INSTALL_EXTRA_PACKAGES \
INSTALL_NODES

ENV DEBIAN_FRONTEND=noninteractive \
TensorRT_ROOT=/opt/TensorRT-10.12.0.36 \
PYTHON_VERSION="${PYTHON_VERSION}" \
UV_COMPILE_BYTECODE=1 \
UV_NO_CACHE=0 \
UV_SYSTEM_PYTHON=0 \
UV_BREAK_SYSTEM_PACKAGES=0 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8

# System dependencies
RUN apt update && apt install -yqq --no-install-recommends \
git wget curl nano socat \
libsndfile1 build-essential llvm tk-dev \
libglvnd-dev cmake swig libprotobuf-dev \
protobuf-compiler libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev \
libffi-dev libgirepository1.0-dev pkg-config libgflags-dev \
libgoogle-glog-dev libjpeg-dev libavcodec-dev libavformat-dev \
libavutil-dev libswscale-dev \
python3.12 python3.12-dev python3.12-venv python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Enable opengl support with nvidia gpu
RUN printf '%s\n' \
'{' \
' "file_format_version" : "1.0.0",' \
' "ICD" : {' \
' "library_path" : "libEGL_nvidia.so.0"' \
' }' \
'}' > /usr/share/glvnd/egl_vendor.d/10_nvidia.json

# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
. $HOME/.local/bin/env && \
uv --version
ENV PATH="/root/.local/bin:$PATH"

# Clone ComfyUI and Manager
RUN git clone --branch v0.3.60 --depth 1 https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
RUN git clone https://github.com/Comfy-Org/ComfyUI-Manager.git /workspace/ComfyUI/custom_nodes/ComfyUI-Manager

# Create venv in ComfyUI workspace
WORKDIR /workspace/ComfyUI
RUN uv venv .venv --python /usr/bin/python${PYTHON_VERSION}
ENV VIRTUAL_ENV=/workspace/ComfyUI/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Conditional TensorRT SDK installation
RUN if [ "$INSTALL_EXTRA_PACKAGES" = "true" ]; then \
cd /opt && \
wget --progress=dot:giga \
https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.12.0/tars/TensorRT-10.12.0.36.Linux.x86_64-gnu.cuda-12.9.tar.gz && \
tar -xzf TensorRT-10.12.0.36.Linux.x86_64-gnu.cuda-12.9.tar.gz && \
rm TensorRT-10.12.0.36.Linux.x86_64-gnu.cuda-12.9.tar.gz && \
echo "${TensorRT_ROOT}/lib" > /etc/ld.so.conf.d/tensorrt.conf && \
ldconfig && \
uv pip install --no-cache-dir \
${TensorRT_ROOT}/python/tensorrt-10.12.0.36-cp312-none-linux_x86_64.whl; \
fi

# Create comfystream directory for constraints and lock file
RUN mkdir -p /tmp/comfystream

# Copy constraints file and comfy lock file for dependency installation
COPY ./src/comfystream/scripts/constraints.txt /tmp/comfystream/constraints.txt
COPY ./configs/comfy-lock.yaml /tmp/comfystream/comfy-lock.yaml

# Install constraints (cached unless constraints.txt changes)
RUN uv pip install -r /tmp/comfystream/constraints.txt

# Copy workflows and test files early (less frequently changed)
COPY ./workflows/comfyui/* /workspace/ComfyUI/user/default/workflows/
COPY ./test/example-512x512.png /workspace/ComfyUI/input

# Conditional OpenCV CUDA installation
RUN if [ "$INSTALL_EXTRA_PACKAGES" = "true" ]; then \
cd /tmp && \
DOWNLOAD_NAME="opencv-cuda-release.tar.gz" && \
wget -q -O "$DOWNLOAD_NAME" https://github.com/JJassonn69/ComfyUI-Stream-Pack/releases/download/v2.1/opencv-cuda-release.tar.gz && \
tar -xzf "$DOWNLOAD_NAME" -C /tmp/ && \
rm "$DOWNLOAD_NAME" && \
SITE_PACKAGES_DIR="${VIRTUAL_ENV}/lib/python${PYTHON_VERSION}/site-packages" && \
rm -rf "${SITE_PACKAGES_DIR}/cv2"* && \
cp -r /tmp/cv2 "${SITE_PACKAGES_DIR}/" && \
VENV_LIB="${VIRTUAL_ENV}/lib" && \
rm -f "${VENV_LIB}/libstdc++.so"* && \
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${VENV_LIB}/" && \
cp /tmp/opencv/build/lib/libopencv_* /usr/lib/x86_64-linux-gnu/ && \
rm -rf /tmp/opencv_contrib /tmp/opencv /tmp/cv2 && \
echo "OpenCV CUDA installation completed"; \
fi

# Install ComfyUI requirements (cached unless ComfyUI version changes)
# RUN uv pip install -r /workspace/ComfyUI/requirements.txt
RUN uv pip install -r /workspace/ComfyUI/custom_nodes/ComfyUI-Manager/requirements.txt

# Copy full comfystream source directly into custom_nodes (done late to maximize cache hits)
COPY . /workspace/ComfyUI/custom_nodes/comfystream

# Install ComfyStream
RUN cd /workspace/ComfyUI/custom_nodes/comfystream && uv pip install -e .

# Run install.py (will use uv pip automatically when available)
RUN cd /workspace/ComfyUI/custom_nodes/comfystream && python install.py --workspace /workspace/ComfyUI

# Accept a build-arg that lets CI force-invalidate cache
ARG CACHEBUST=static
ENV CACHEBUST=${CACHEBUST}

# Note: setup_nodes.py is intentionally skipped

# Install comfy-cli for workspace management
RUN uv pip install comfy-cli
RUN comfy --skip-prompt set-default "/workspace/ComfyUI"
RUN comfy tracking disable

# Conditionally install custom nodes from snapshot
RUN if [ "$INSTALL_NODES" = "true" ]; then \
cd /workspace/ComfyUI && \
comfy node restore-snapshot /workspace/ComfyUI/custom_nodes/comfystream/configs/comfy-lock.yaml; \
fi

# Install numpy and xformers
#RUN uv pip install "numpy<2.0.0"
RUN uv pip install --no-cache-dir xformers==0.0.32.post2 --no-deps

# Create marker file to identify this as a built-in workspace
RUN touch /workspace/ComfyUI/.comfystream_builtin_workspace

WORKDIR /workspace/ComfyUI/custom_nodes/comfystream

# Expose ComfyUI port
EXPOSE 8188

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8188/system_stats || exit 1

# Copy and set up entrypoint script (last for optimal caching)
COPY ./docker/entrypoint-byow.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD []

16 changes: 16 additions & 0 deletions Dockerfile.uv.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Development Dockerfile for comfystream:uv
# This extends the production image and only overrides development-specific changes
# Build: docker build -f Dockerfile.uv.dev -t comfystream:uv-dev .

FROM comfystream:uv

# Override entrypoint script for development
# This is the only layer that rebuilds when you modify the entrypoint
COPY ./docker/entrypoint-byow.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Development-friendly settings
ENV COMFYUI_DEV_MODE=1

WORKDIR /workspace/ComfyUI/custom_nodes/comfystream

49 changes: 49 additions & 0 deletions Makefile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.PHONY: help build build-dev build-install-nodes build-no-extras run run-dev run-dev-live clean

COMFYUI_PATH ?= ~/ComfyUI
PORT ?= 8188

help: ## Show this help message
@echo "ComfyStream Docker Development Commands"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

build: ## Build production image with TensorRT and OpenCV CUDA
docker build -f Dockerfile.uv -t comfystream:uv .

build-install-nodes: ## Build production image with nodes installed
docker build -f Dockerfile.uv --build-arg INSTALL_NODES=true -t comfystream:uv-nodes .

build-no-extras: ## Build production image without TensorRT and OpenCV CUDA (faster)
docker build -f Dockerfile.uv --build-arg INSTALL_EXTRA_PACKAGES=false -t comfystream:uv-lite .

build-dev: ## Build development image (extends production, only rebuilds entrypoint layer)
docker build -f Dockerfile.uv.dev -t comfystream:uv-dev .

build-dev-nodes: ## Build development image (extends production, only rebuilds entrypoint layer)
docker build -f Dockerfile.uv-nodes -t comfystream:uv-dev .

run: ## Run built-in workspace (no mount)
docker run --gpus all -p $(PORT):8188 comfystream:uv

run-dev: ## Run with mounted workspace using docker-compose
docker compose -f docker-compose.dev.yml up

run-dev-live: ## Run with live entrypoint mounting (instant updates, no rebuild!)
docker run --gpus all -p $(PORT):8188 \
-v $(COMFYUI_PATH):/workspace/ComfyUI \
-v $$(pwd)/docker/entrypoint-byow.sh:/usr/local/bin/entrypoint.sh:ro \
comfystream:uv

run-dev-shell: ## Run with mounted workspace and drop into bash shell
docker run -it --gpus all \
-v $(COMFYUI_PATH):/workspace/ComfyUI \
-v $$(pwd)/docker/entrypoint-byow.sh:/usr/local/bin/entrypoint.sh:ro \
comfystream:uv bash

clean: ## Remove all comfystream images
docker rmi comfystream:uv comfystream:uv-dev comfystream:uv-lite || true

# Override ComfyUI path: make run-dev-live COMFYUI_PATH=/path/to/ComfyUI
# Override port: make run PORT=8189

Loading
Loading