From 1d5b9bc4fac967d72537dbea8df05e763adadb38 Mon Sep 17 00:00:00 2001 From: User Name Date: Fri, 12 Dec 2025 20:21:57 -0600 Subject: [PATCH] Add Docker setup for ComfyUI with GitHub release tracking - Add Dockerfile with CUDA 12.6 and Python 3.12 base - Add docker-compose.yml with GPU support and volume mounts - Add docker-entrypoint.sh script with venv management and OTEL support - Add comfy-node-install.sh helper for custom node installation - Update .gitignore to exclude Docker-related artifacts - Entrypoint ensures frontend package matches requirements.txt version - Optional OTEL instrumentation when OTEL_EXPORTER_OTLP_ENDPOINT is set - Volume-mounted repo allows git checkout of release tags without rebuilds --- Dockerfile | 5 +- docker-compose.override.yml.example | 12 +++++ scripts/docker-entrypoint.sh | 72 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 docker-compose.override.yml.example create mode 100644 scripts/docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 1efb9894d..bc13b3628 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV PYTHONUNBUFFERED=1 # Install system dependencies RUN apt-get update && apt-get install -y \ - python3.12 python3.12-venv git git-lfs wget \ + python3.12 python3.12-venv python3-pip git git-lfs wget \ libgl1 libglib2.0-0 libsm6 libxext6 libxrender1 \ ffmpeg \ espeak-ng libespeak-ng1 \ @@ -22,8 +22,7 @@ RUN apt-get update && apt-get install -y \ && ln -sf /usr/bin/pip3 /usr/bin/pip \ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* -# Install OpenTelemetry packages for optional instrumentation -RUN pip install --no-cache-dir opentelemetry-distro opentelemetry-exporter-otlp +# OpenTelemetry packages will be installed in the venv by entrypoint script if needed WORKDIR /app/ComfyUI diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example new file mode 100644 index 000000000..98e78bf8d --- /dev/null +++ b/docker-compose.override.yml.example @@ -0,0 +1,12 @@ +# Example override file to disable GPU for testing +# Copy this to docker-compose.override.yml to use CPU-only mode +services: + comfyui: + deploy: + resources: + reservations: + devices: [] + # Remove ipc: host if not using GPU + # ipc: host + + diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh new file mode 100644 index 000000000..dbe810365 --- /dev/null +++ b/scripts/docker-entrypoint.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# Docker entrypoint script for ComfyUI +# Handles virtual environment setup, dependency installation, custom nodes, and optional OTEL instrumentation + +set -e + +COMFYUI_DIR="/app/ComfyUI" +VENV_DIR="/app/venv" +WORKDIR="${COMFYUI_DIR}" + +cd "${WORKDIR}" + +# Create virtual environment if it doesn't exist +if [ ! -d "${VENV_DIR}" ]; then + echo "Creating virtual environment..." + python -m venv "${VENV_DIR}" +fi + +# Activate virtual environment +source "${VENV_DIR}/bin/activate" + +# Upgrade pip +pip install --upgrade pip setuptools wheel + +# Install PyTorch with CUDA 12.6 support +echo "Installing PyTorch with CUDA 12.6..." +pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 + +# Install ComfyUI requirements (upgrade ensures packages match requirements.txt) +echo "Installing ComfyUI requirements..." +pip install --upgrade --no-cache-dir -r requirements.txt + +# Install OpenTelemetry packages if OTEL endpoint is configured +if [ -n "${OTEL_EXPORTER_OTLP_ENDPOINT}" ]; then + echo "Installing OpenTelemetry packages..." + pip install --no-cache-dir opentelemetry-distro opentelemetry-exporter-otlp +fi + +# Explicitly ensure frontend package matches requirements.txt version +echo "Verifying frontend package version..." +REQUIRED_FRONTEND_VERSION=$(grep "^comfyui-frontend-package==" requirements.txt | cut -d'=' -f3) +if [ -n "$REQUIRED_FRONTEND_VERSION" ]; then + echo "Installing frontend package version: $REQUIRED_FRONTEND_VERSION" + pip install --upgrade --force-reinstall --no-cache-dir "comfyui-frontend-package==${REQUIRED_FRONTEND_VERSION}" +else + echo "Warning: Could not determine required frontend version from requirements.txt" +fi + +# Optional: Install curated custom nodes (can be enabled via environment variable) +if [ "${INSTALL_CURATED_NODES:-false}" = "true" ]; then + echo "Installing curated custom nodes..." + export COMFYUI_DIR="${COMFYUI_DIR}" + comfy-node-install \ + https://github.com/city96/ComfyUI-GGUF \ + https://github.com/rgthree/rgthree-comfy \ + https://github.com/ClownsharkBatwing/RES4LYF \ + https://github.com/giriss/comfy-image-saver || echo "Warning: Some custom nodes failed to install" +fi + +# Check if OpenTelemetry endpoint is configured +if [ -n "${OTEL_EXPORTER_OTLP_ENDPOINT}" ]; then + echo "OpenTelemetry endpoint detected, enabling instrumentation..." + exec opentelemetry-instrument \ + --traces_exporter otlp \ + --metrics_exporter otlp \ + --logs_exporter otlp \ + python main.py --listen 0.0.0.0 --port 8188 "$@" +else + echo "Starting ComfyUI without OpenTelemetry instrumentation..." + exec python main.py --listen 0.0.0.0 --port 8188 "$@" +fi +