From 98ed2b08da6dad61feb22559b75292c1b42f5e37 Mon Sep 17 00:00:00 2001 From: Madiator2011 Date: Mon, 1 Jul 2024 15:57:52 +0200 Subject: [PATCH] Added Better ComfyUI Teamplate --- official-templates/better-comfyui/Dockerfile | 59 +++++++++++++++++++ official-templates/better-comfyui/README.md | 7 +++ .../better-comfyui/docker-bake.hcl | 18 ++++++ .../better-comfyui/pre_start.sh | 39 ++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 official-templates/better-comfyui/Dockerfile create mode 100644 official-templates/better-comfyui/README.md create mode 100644 official-templates/better-comfyui/docker-bake.hcl create mode 100644 official-templates/better-comfyui/pre_start.sh diff --git a/official-templates/better-comfyui/Dockerfile b/official-templates/better-comfyui/Dockerfile new file mode 100644 index 0000000..0bb1ca1 --- /dev/null +++ b/official-templates/better-comfyui/Dockerfile @@ -0,0 +1,59 @@ +# Stage 1: Base Image +FROM madiator2011/better-pytorch:cuda12.1 as base + +ARG PYTHON_VERSION1 +ARG TORCH + +# Install PyTorch if specified +RUN if [ -n "${TORCH}" ]; then \ + pip install --upgrade --no-cache-dir ${TORCH}; \ + fi + +# Stage 2: ComfyUI Installation +FROM base as comfyui-install + +# Create and activate virtual environment for ComfyUI installation +RUN python -m venv /venv +ENV PATH="/venv/bin:$PATH" + +RUN git clone https://github.com/comfyanonymous/ComfyUI.git && \ + cd /ComfyUI && \ + pip install -r requirements.txt && \ + git clone https://github.com/ltdrdata/ComfyUI-Manager.git custom_nodes/ComfyUI-Manager && \ + cd custom_nodes/ComfyUI-Manager && \ + pip install -r requirements.txt + +# Stage 3: Model Setup and Final Image +FROM comfyui-install as final + +# Create model and cache directories +RUN mkdir -p /root/.cache/huggingface && mkdir -p /comfy-models + +# Download models directly +RUN wget -q --show-progress https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors -O /comfy-models/v1-5-pruned-emaonly.safetensors && \ + wget -q --show-progress https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors -O /comfy-models/v2-1_768-ema-pruned.safetensors && \ + wget -q --show-progress https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -O /comfy-models/sd_xl_base_1.0.safetensors && \ + wget -q --show-progress https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -O /comfy-models/sd_xl_refiner_1.0.safetensors + +# Verify models were downloaded +RUN ls -lh /comfy-models + +# NGINX Proxy +COPY --from=proxy nginx.conf /etc/nginx/nginx.conf +COPY --from=proxy readme.html /usr/share/nginx/html/readme.html + +# Copy the README.md +COPY README.md /usr/share/nginx/html/README.md + +# Set environment variables for runtime +ENV PATH="/workspace/venv/bin:$PATH" +ENV VIRTUAL_ENV="/workspace/venv" + +# Start Scripts +COPY pre_start.sh /pre_start.sh + +# Start Scripts +COPY --from=scripts start.sh / +RUN chmod +x /start.sh + +CMD [ "/start.sh" ] \ No newline at end of file diff --git a/official-templates/better-comfyui/README.md b/official-templates/better-comfyui/README.md new file mode 100644 index 0000000..3fb5ea4 --- /dev/null +++ b/official-templates/better-comfyui/README.md @@ -0,0 +1,7 @@ +## Build Options + +To build with default options, run `docker buildx bake`, to build a specific target, run `docker buildx bake `. + +## Ports + +- 22/tcp (SSH) diff --git a/official-templates/better-comfyui/docker-bake.hcl b/official-templates/better-comfyui/docker-bake.hcl new file mode 100644 index 0000000..1666161 --- /dev/null +++ b/official-templates/better-comfyui/docker-bake.hcl @@ -0,0 +1,18 @@ +group "default" { + targets = ["py310-cuda121"] +} + +target "py310-cuda121" { + contexts = { + scripts = "../../container-template" + proxy = "../../container-template/proxy" + logo = "../../container-template" + } + dockerfile = "Dockerfile" + args = { + BASE_IMAGE = "nvidia/cuda:12.1.0-cudnn8-devel-ubuntu22.04", + TORCH = "torch==2.3.1+cu121 -f https://download.pytorch.org/whl/torch_stable.html", + PYTHON_VERSION = "3.10" + } + tags = ["madiator2011/better-comfyui:cuda12.1"] +} \ No newline at end of file diff --git a/official-templates/better-comfyui/pre_start.sh b/official-templates/better-comfyui/pre_start.sh new file mode 100644 index 0000000..a56a5ac --- /dev/null +++ b/official-templates/better-comfyui/pre_start.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status +set -e + +# Function to print colorized feedback +print_feedback() { + GREEN='\033[0;32m' + NC='\033[0m' # No Color + echo -e "${GREEN}[ComfyUI Startup]:${NC} $1" +} + +# Function to run rsync with progress bar +rsync_with_progress() { + stdbuf -i0 -o0 -e0 rsync -au --info=progress2 "$@" | stdbuf -i0 -o0 -e0 tr '\r' '\n' | stdbuf -i0 -o0 -e0 grep -oP '\d+%|\d+.\d+[mMgG]' | tqdm --bar-format='{l_bar}{bar}' --total=100 --unit='%' > /dev/null +} + +print_feedback "Starting ComfyUI setup..." + +print_feedback "Syncing virtual environment..." +rsync_with_progress /venv/ /workspace/venv/ + +print_feedback "Activating virtual environment..." +source /workspace/venv/bin/activate + +export PYTHONUNBUFFERED=1 + +print_feedback "Syncing ComfyUI files..." +rsync_with_progress --remove-source-files /ComfyUI/ /workspace/ComfyUI/ + +print_feedback "Creating symbolic links for model checkpoints..." +ln -sf /comfy-models/* /workspace/ComfyUI/models/checkpoints/ + +print_feedback "Changing to ComfyUI directory..." +cd /workspace/ComfyUI + +print_feedback "Starting ComfyUI server..." +print_feedback "ComfyUI will be available at http://0.0.0.0:3000" +exec /workspace/venv/bin/python main.py --listen --port 3000 \ No newline at end of file