From e6e0747285d0cf9a52f25c4eb1439c173a842126 Mon Sep 17 00:00:00 2001 From: Sasser7 Date: Mon, 21 Oct 2024 23:40:30 +0200 Subject: [PATCH 1/4] add Dockerfile, compose.yml and modify README.md and .gitignore --- .gitignore | 1 + Dockerfile | 11 +++++++++++ README.md | 20 +++++++++++++++++--- compose.yml | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/.gitignore b/.gitignore index 61881b8a4..b83f95f26 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ venv/ *.log web_custom_versions/ .DS_Store +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..34dd4e42a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.12-slim +EXPOSE 8188 + +# Copy the repo and install required dependencies +WORKDIR /ComfyUI +COPY . . +RUN pip install --no-cache-dir -r requirements.txt + +# ComfyUI entrypoint +WORKDIR /ComfyUI +CMD [ "python", "main.py" ] \ No newline at end of file diff --git a/README.md b/README.md index 8e5cef450..02bab6d0c 100644 --- a/README.md +++ b/README.md @@ -42,14 +42,14 @@ This ui will let you design and execute advanced stable diffusion pipelines usin - [Flux](https://comfyanonymous.github.io/ComfyUI_examples/flux/) - Asynchronous Queue system - Many optimizations: Only re-executes the parts of the workflow that changes between executions. -- Smart memory management: can automatically run models on GPUs with as low as 1GB vram. +- Smart memory management: can automatically run models on GPUs with as low as 1GB of VRAM. - Works even if you don't have a GPU with: ```--cpu``` (slow) - Can load ckpt, safetensors and diffusers models/checkpoints. Standalone VAEs and CLIP models. - Embeddings/Textual inversion - [Loras (regular, locon and loha)](https://comfyanonymous.github.io/ComfyUI_examples/lora/) - [Hypernetworks](https://comfyanonymous.github.io/ComfyUI_examples/hypernetworks/) - Loading full workflows (with seeds) from generated PNG, WebP and FLAC files. -- Saving/Loading workflows as Json files. +- Saving/Loading workflows as JSON files. - Nodes interface can be used to create complex workflows like one for [Hires fix](https://comfyanonymous.github.io/ComfyUI_examples/2_pass_txt2img/) or much more advanced ones. - [Area Composition](https://comfyanonymous.github.io/ComfyUI_examples/area_composition/) - [Inpainting](https://comfyanonymous.github.io/ComfyUI_examples/inpaint/) with both regular and inpainting models. @@ -66,6 +66,7 @@ This ui will let you design and execute advanced stable diffusion pipelines usin - Starts up very fast. - Works fully offline: will never download anything. - [Config file](extra_model_paths.yaml.example) to set the search paths for models. +- [Docker](#running-with-docker) support Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/) @@ -211,6 +212,20 @@ For 6700, 6600 and maybe other RDNA2 or older: ```HSA_OVERRIDE_GFX_VERSION=10.3. For AMD 7600 and maybe other RDNA3 cards: ```HSA_OVERRIDE_GFX_VERSION=11.0.0 python main.py``` +# Running with Docker +Just execute the command below: + +```docker compose --profile up --build -d``` +## Profiles +```cpu``` - For CPU-only machines + +```cuda``` - For NVIDIA CUDA Chips + +## Additional variables for Docker (.env support) +```PORT``` - Port for ComfyUI + +```LISTEN_IP``` - IP address for ComfyUI to listen + # Notes Only parts of the graph that have an output with all the correct inputs will be executed. @@ -296,4 +311,3 @@ This will use a snapshot of the legacy frontend preserved in the [ComfyUI Legacy ### Which GPU should I buy for this? [See this page for some recommendations](https://github.com/comfyanonymous/ComfyUI/wiki/Which-GPU-should-I-buy-for-ComfyUI) - diff --git a/compose.yml b/compose.yml new file mode 100644 index 000000000..8a4bfcaae --- /dev/null +++ b/compose.yml @@ -0,0 +1,33 @@ +# ComfyUI common x-variable +x-comfyui-common: &comfyui-common + build: + context: . + image: comfyui + ports: + - "${PORT:-8188}:8188" + volumes: + - "./custom_nodes:/ComfyUI/custom_nodes" + - "./models:/ComfyUI/models" + - "./output:/ComfyUI/output" + +# ComfyUI profiles +services: + comfyui-cpu: + <<: *comfyui-common + command: > + python main.py --listen=${LISTEN_IP:-0.0.0.0} --cpu + profiles: + - cpu + comfyui-cuda: + <<: *comfyui-common + command: > + python main.py --listen=${LISTEN_IP:-0.0.0.0} + profiles: + - cuda + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [ gpu ] \ No newline at end of file From 6d432c31e4935708273ccc344cd711472e2ff1f9 Mon Sep 17 00:00:00 2001 From: Sasser7 Date: Fri, 25 Oct 2024 22:25:46 +0200 Subject: [PATCH 2/4] Add .dockerignore --- .dockerignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ac2a3a9d5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +custom_nodes/* +models/* +output/* \ No newline at end of file From 8b8b34818d99b4a33f73699a98b5e1d4613f4956 Mon Sep 17 00:00:00 2001 From: Sasser7 Date: Sun, 10 Nov 2024 23:56:21 +0100 Subject: [PATCH 3/4] Add docker-run.bat --- docker-run.bat | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docker-run.bat diff --git a/docker-run.bat b/docker-run.bat new file mode 100644 index 000000000..7fb01e67e --- /dev/null +++ b/docker-run.bat @@ -0,0 +1,43 @@ +@echo off + +:: Set default port and read from .env if exists +set "port=8188" +for /f "tokens=2 delims==" %%i in ('findstr /r "^PORT=" .env') do set "port=%%i" + +:: Check if NVIDIA GPU is available and set profile accordingly +for /f "tokens=*" %%i in ('wmic path win32_videocontroller get name ^| find /i "NVIDIA"') do set "profile=cuda" && goto pull +set "profile=cpu" + +:: Pull updates and handle local changes +:pull +set "cmdOutput=cmd_output.txt" +git pull > "%cmdOutput%" 2>&1 + +:: Handle potential conflicts or changes +findstr /C:"error: Your local changes to the following files would be overwritten by merge:" "%cmdOutput%" > nul && ( + echo Pull conflicts detected. Stashing changes... + git stash + git pull + goto rebuild +) + +findstr /C:"Already up to date." "%cmdOutput%" > nul || goto rebuild + +echo No changes detected. Starting Docker container... +docker compose --profile %profile% up -d +goto open_browser + +:: Rebuild section +:rebuild +echo Changes detected. Rebuilding Docker image... +docker compose --profile %profile% up --build -d + +:: Open the browser to localhost:%port% +:open_browser +echo Opening localhost:%port% in your default browser... +start http://localhost:%port% + +:: Cleanup section +:cleanup +del "%cmdOutput%" +exit /f 0 From f139294aaf7aeabc003f34a112d63a168ecbbc60 Mon Sep 17 00:00:00 2001 From: Sasser7 Date: Thu, 28 Nov 2024 21:53:13 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=85=20Update=20code,=20add=20run.bat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + run.bat | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 run.bat diff --git a/Dockerfile b/Dockerfile index 34dd4e42a..30c1d2bb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ EXPOSE 8188 # Copy the repo and install required dependencies WORKDIR /ComfyUI COPY . . +RUN apt update && apt install git -y RUN pip install --no-cache-dir -r requirements.txt # ComfyUI entrypoint diff --git a/run.bat b/run.bat new file mode 100644 index 000000000..188c71d2c --- /dev/null +++ b/run.bat @@ -0,0 +1,41 @@ +@echo off + +:: Set default port and read from .env if exists +set "port=8188" +for /f "tokens=2 delims==" %%i in ('findstr /r "^PORT=" .env') do set "port=%%i" + +:: Set default venv path and read from .env if exists +set "venv_path=" +for /f "tokens=2 delims==" %%i in ('findstr /r "^VENV_PATH=" .env') do set "venv_path=%%i" + +:: Activate the virtual environment if specified +if not "%venv_path%"=="" ( + call "%venv_path%\Scripts\activate" + echo Activated virtual environment: %venv_path% +) else ( + echo No virtual environment specified. Using system Python. +) + +:: Pull updates and handle local changes +:pull +set "cmdOutput=cmd_output.txt" +git pull > "%cmdOutput%" 2>&1 + +:: Handle potential conflicts or changes +findstr /C:"error: Your local changes to the following files would be overwritten by merge:" "%cmdOutput%" > nul && ( + echo Pull conflicts detected. Stashing changes... + git stash + git pull +) + +findstr /C:"Already up to date." "%cmdOutput%" > nul || goto rebuild + +del "%cmdOutput%" + +echo No changes detected. Starting ComfyUI +pip install -r requirements.txt + +echo Opening localhost:%port% in your default browser... +start http://localhost:%port% + +python main.py