diff --git a/.gitignore b/.gitignore index 4e8cea71e..3e9c4b638 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,7 @@ web_custom_versions/ openapi.yaml filtered-openapi.yaml uv.lock + +# Docker +.dockerignore +docker-compose.override.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..1efb9894d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Build argument for base image selection +ARG BASE_IMAGE=nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 + +# ---------------------- +# Stage: Base Runtime +# ---------------------- +FROM ${BASE_IMAGE} AS base + +ENV DEBIAN_FRONTEND=noninteractive +ENV PIP_PREFER_BINARY=1 +ENV PYTHONUNBUFFERED=1 + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + python3.12 python3.12-venv git git-lfs wget \ + libgl1 libglib2.0-0 libsm6 libxext6 libxrender1 \ + ffmpeg \ + espeak-ng libespeak-ng1 \ + build-essential \ + && git lfs install \ + && ln -sf /usr/bin/python3.12 /usr/bin/python \ + && 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 + +WORKDIR /app/ComfyUI + +# Copy entrypoint and helper scripts +COPY scripts/docker-entrypoint.sh /app/ComfyUI/scripts/docker-entrypoint.sh +COPY scripts/comfy-node-install.sh /usr/local/bin/comfy-node-install +RUN chmod +x /app/ComfyUI/scripts/docker-entrypoint.sh && \ + chmod +x /usr/local/bin/comfy-node-install + +# Set entrypoint +ENTRYPOINT ["/app/ComfyUI/scripts/docker-entrypoint.sh"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..3a61257bf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +services: + comfyui: + build: + context: . + dockerfile: Dockerfile + container_name: comfyui + ports: + - "8188:8188" + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [gpu] + ipc: host + volumes: + - .:/app/ComfyUI # Mount local repo (for git checkout updates) + - comfyui-models:/app/ComfyUI/models # Persist models + - comfyui-output:/app/ComfyUI/output # Persist outputs + - comfyui-input:/app/ComfyUI/input # Persist inputs + - comfyui-custom-nodes:/app/ComfyUI/custom_nodes # Persist custom nodes + - comfyui-user:/app/ComfyUI/user # Persist user settings/workflows + - comfyui-venv:/app/venv # Cache virtualenv + environment: + - TZ=America/Chicago + - PUID=1000 + - PGID=1000 + # OpenTelemetry environment variables (optional - set if you want OTEL) + # - OTEL_EXPORTER_OTLP_ENDPOINT=http://your-otel-collector:4317 + # - OTEL_SERVICE_NAME=comfyui + # - OTEL_RESOURCE_ATTRIBUTES=service.name=comfyui + restart: unless-stopped + +volumes: + comfyui-models: + comfyui-output: + comfyui-input: + comfyui-custom-nodes: + comfyui-user: + comfyui-venv: + diff --git a/scripts/comfy-node-install.sh b/scripts/comfy-node-install.sh new file mode 100644 index 000000000..4026888d6 --- /dev/null +++ b/scripts/comfy-node-install.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# comfy-node-install - Install ComfyUI custom nodes from GitHub repositories +# Usage: comfy-node-install [repo-url2 ...] + +set -e + +COMFYUI_DIR="${COMFYUI_DIR:-/app/ComfyUI}" +CUSTOM_NODES_DIR="${COMFYUI_DIR}/custom_nodes" + +# Ensure custom_nodes directory exists +mkdir -p "${CUSTOM_NODES_DIR}" + +install_node() { + local repo_url="$1" + if [ -z "$repo_url" ]; then + echo "Error: Repository URL is required" + return 1 + fi + + # Extract repository name from URL + local repo_name=$(basename "${repo_url}" .git) + + # Handle full GitHub URLs or just repo paths + if [[ "$repo_url" != http* ]]; then + repo_url="https://github.com/${repo_url}" + fi + + local target_dir="${CUSTOM_NODES_DIR}/${repo_name}" + + echo "Installing custom node: ${repo_name} from ${repo_url}" + + # Remove existing installation if it exists + if [ -d "${target_dir}" ]; then + echo " Removing existing installation..." + rm -rf "${target_dir}" + fi + + # Clone the repository + if [ -n "${GIT_LFS_SKIP_SMUDGE}" ]; then + GIT_LFS_SKIP_SMUDGE=1 git clone --depth 1 "${repo_url}" "${target_dir}" + else + git clone --depth 1 "${repo_url}" "${target_dir}" + fi + + echo " Successfully installed ${repo_name}" +} + +# Install all provided repositories +for repo_url in "$@"; do + install_node "${repo_url}" +done +