From 4340541358053878f787344c3e65f99ad11b278b Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 15 May 2024 11:00:13 -0400 Subject: [PATCH 1/7] add docker compose --profile syntax to startup --- README.md | 47 +++++---------- docker-compose.yml | 140 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 136 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index a145ec2..a5a663f 100644 --- a/README.md +++ b/README.md @@ -28,43 +28,26 @@ Unraid template available on [superboki's Repository](https://github.com/superbo ## Choosing a Project -Use the environmental variable `WEBUI_VERSION` to choose which [project](#projects) to install and use based on the number in the **WEBUI** column. [easy diffusion](https://github.com/easydiffusion/easydiffusion) (`01`) is installed if none is specified. - -Example: To use SD.Next => `WEBUI_VERSION=04` - ``` -docker run ... -e WEBUI_VERSION=04 ... holaflenain/stable-diffusion -``` - -or modify `WEBUI_VERSION` in [docker-compose.yml](/docker-compose.yml) - -## Docker Notes - -### Using PUID and PGID - -If you are - -* running on a **linux host** (ie unraid) and -* **not** using [rootless containers with Podman](https://developers.redhat.com/blog/2020/09/25/rootless-containers-with-podman-the-basics#why_podman_) +docker compose --profile easy-diffusion up # http://:9001 +docker compose --profile automatic1111 up # http://:9002 +docker compose --profile forge up # http://:9022 +docker compose --profile invoke-ai up # http://:9003 +docker compose --profile sd-next up # http://:9004 +docker compose --profile comfy-ui up # http://:9005 +docker compose --profile fooocus up # http://:9006 +docker compose --profile stable-swarm up # http://:9007 +docker compose --profile lama-cleaner up # http://:9050 +docker compose --profile face-fusion up # http://:9051 +docker compose --profile kohya up # http://:9070 -then you must set the [environmental variables **PUID** and **PGID**.](https://docs.linuxserver.io/general/understanding-puid-and-pgid) in the container in order for it to generate files/folders your normal user can interact it. - -Run these commands from your terminal - -* `id -u` -- prints UID for **PUID** -* `id -g` -- prints GID for **PGID** - -Then add to your docker command like so: - -```shell -docker run -d ... -e "PUID=1000" -e "PGID=1000" ... holaflenain/stable-diffusion ``` -or substitute them in [docker-compose.yml](/docker-compose.yml) +or -### Docker Compose - -Reference [docker-compose.yml](/docker-compose.yml) which uses Easy-Diffusion as an example. +``` +docker compose up # to run all the services at once +``` ## Directory Structure diff --git a/docker-compose.yml b/docker-compose.yml index 339531b..7aadb30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,122 @@ -version: '3.1' +x-service: &default-service + image: holaflenain/stable-diffusion:latest + runtime: nvidia + volumes: + - '/data/stable-diffusion:/config:rw' + +x-environment: &default-environment + NVIDIA_VISIBLE_DEVICES: all + TZ: ${TZ:-America/New_York} + PUID: ${PUID:-1000} + PGID: ${PGID:-1000} + services: - stable-diffusion-test: - image: holaflenain/stable-diffusion:latest - container_name: stable-diffusion - environment: - - WEBUI_VERSION=01 - - NVIDIA_VISIBLE_DEVICES=all - - TZ=Europe/Paris - - PUID=1000 - - PGID=1000 - ports: - - '9000:9000/tcp' - volumes: - - '/my/own/datadir:/config:rw' - # or specify individual dirs - #- '/my/own/datadir:/config:rw' # config/program dir - #- '/my/own/datadir/outputs:/config/outputs:rw' - #- '/my/own/datadir/cache:/config/cache:rw' - runtime: nvidia \ No newline at end of file + stable-diffusion-easy-diffusion: + <<: *default-service + profiles: [easy-diffusion] + container_name: stable-diffusion-easy-diffusion + environment: + <<: *default-environment + WEBUI_VERSION: '00' + ports: + - 9001:9000/tcp + + stable-diffusion-automatic1111: + <<: *default-service + profiles: [automatic1111] + container_name: stable-diffusion-automatic1111 + environment: + <<: *default-environment + WEBUI_VERSION: '02' + ports: + - 9002:9000/tcp + + stable-diffusion-forge: + <<: *default-service + profiles: [forge] + container_name: stable-diffusion-forge + environment: + <<: *default-environment + WEBUI_VERSION: '02.forge' + ports: + - 9022:9000/tcp + + stable-diffusion-invoke-ai: + <<: *default-service + profiles: [invoke-ai] + container_name: stable-diffusion-invoke-ai + environment: + <<: *default-environment + WEBUI_VERSION: '03' + ports: + - 9003:9000/tcp + + stable-diffusion-sd-next: + <<: *default-service + profiles: [sd-next] + container_name: stable-diffusion-sd-next + environment: + <<: *default-environment + WEBUI_VERSION: '04' + ports: + - 9004:9000/tcp + + stable-diffusion-comfy-ui: + <<: *default-service + profiles: [comfy-ui] + container_name: stable-diffusion-comfy-ui + environment: + <<: *default-environment + WEBUI_VERSION: '05' + ports: + - 9005:9000/tcp + + stable-diffusion-fooocus: + <<: *default-service + profiles: [fooocus] + container_name: stable-diffusion-fooocus + environment: + <<: *default-environment + WEBUI_VERSION: '06' + ports: + - 9006:9000/tcp + + stable-diffusion-stable-swarm: + <<: *default-service + profiles: [stable-swarm] + container_name: stable-diffusion-stable-swarm + environment: + <<: *default-environment + WEBUI_VERSION: '07' + ports: + - 9007:9000/tcp + + stable-diffusion-lama-cleaner: + <<: *default-service + profiles: [lama-cleaner] + container_name: stable-diffusion-lama-cleaner + environment: + <<: *default-environment + WEBUI_VERSION: '50' + ports: + - 9050:9000/tcp + + stable-diffusion-face-fusion: + <<: *default-service + profiles: [face-fusion] + container_name: stable-diffusion-face-fusion + environment: + <<: *default-environment + WEBUI_VERSION: '51' + ports: + - 9051:9000/tcp + + stable-diffusion-kohya: + <<: *default-service + profiles: [kohya] + container_name: stable-diffusion-kohya + environment: + <<: *default-environment + WEBUI_VERSION: '51' + ports: + - 9070:9000/tcp \ No newline at end of file From ba25cad315725d5781f642109c708a5f53836ac5 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 15 May 2024 15:34:31 -0400 Subject: [PATCH 2/7] fix mapping issues in docker-compose.yml --- README.md | 2 +- docker-compose.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a5a663f..6722b11 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Unraid template available on [superboki's Repository](https://github.com/superbo ``` docker compose --profile easy-diffusion up # http://:9001 -docker compose --profile automatic1111 up # http://:9002 +docker compose --profile automatic up # http://:9002 docker compose --profile forge up # http://:9022 docker compose --profile invoke-ai up # http://:9003 docker compose --profile sd-next up # http://:9004 diff --git a/docker-compose.yml b/docker-compose.yml index 7aadb30..12a83d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,14 +17,14 @@ services: container_name: stable-diffusion-easy-diffusion environment: <<: *default-environment - WEBUI_VERSION: '00' + WEBUI_VERSION: '01' ports: - 9001:9000/tcp - stable-diffusion-automatic1111: + stable-diffusion-automatic: <<: *default-service - profiles: [automatic1111] - container_name: stable-diffusion-automatic1111 + profiles: [automatic] + container_name: stable-diffusion-automatic environment: <<: *default-environment WEBUI_VERSION: '02' @@ -117,6 +117,6 @@ services: container_name: stable-diffusion-kohya environment: <<: *default-environment - WEBUI_VERSION: '51' + WEBUI_VERSION: '70' ports: - 9070:9000/tcp \ No newline at end of file From e22db71a197f12a61f0359139a16ff061f783b15 Mon Sep 17 00:00:00 2001 From: Mike Glenn <219478+ilude@users.noreply.github.com> Date: Thu, 16 May 2024 10:35:32 -0400 Subject: [PATCH 3/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6722b11..439212d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,8 @@ docker compose --profile kohya up # http://:9070 ``` -or +or +( Although not recommended as it will requires significant system resources, 64GB+ system memory and at bare minimum 16GB VRAM card, you have been warned! ) ``` docker compose up # to run all the services at once From dc35e4d4715ebd33135d2b786bc0555d43b1cd3e Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 16 May 2024 11:41:12 -0400 Subject: [PATCH 4/7] add makefile and update README.md --- .gitignore | 2 ++ Makefile | 44 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 26 +++++++++++++------------- 4 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad60b67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +data/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ea07d2 --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +# get the current machines +export HOSTIP := $(shell ip route get 1.1.1.1 | grep -oP 'src \K\S+') +export PUID := $(shell id -u) +export PGID := $(shell id -g) + +# Parse the available profiles from the docker-compose.yml +AVAILABLE_PROFILES := $(shell grep -oP 'profiles:\s*\[\K[^\]]+' docker-compose.yml | sed 's/\s*//g' | tr '\n' ' ') + +# Include .env variable in the current environment +ifneq (,$(wildcard ./.env)) + include .env + export +endif + +# Default target +.DEFAULT_GOAL := help +.PHONY: help up down start stop logs + +# Help target +help: + @echo "Available targets:" + @echo " up [profile] Start the specified profile (e.g., make up fooocus)" + @echo " down [profile] Stop the specified profile (e.g., make down fooocus)" + @echo " help Show this help message" + +# up target +up: + docker compose --profile $(filter-out $@,$(MAKECMDGOALS)) up + +# down/stop target +down: stop +stop: + docker compose --profile $(filter-out $@,$(MAKECMDGOALS)) down + +# start target +start: + docker compose --profile $(filter-out $@,$(MAKECMDGOALS)) up -d + +logs: + docker compose --profile $(filter-out $@,$(MAKECMDGOALS)) logs -f + +# Allow extra arguments for the up and down targets +%: + @: diff --git a/README.md b/README.md index 439212d..f3a7bca 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,35 @@ or docker compose up # to run all the services at once ``` +## Make + +alternatively you can use make to start and stop the services + +there are two variations + +``` +# will start the service detached from the terminal (running in the background) +make start + +# will start the service and leave its output attached to the terminal +make up +``` +Here is a complete list for starting services +``` +make start easy-diffusion # http://:9001 +make start automatic # http://:9002 +make start forge # http://:9022 +make start invoke-ai # http://:9003 +make start sd-next # http://:9004 +make start comfy-ui # http://:9005 +make start fooocus # http://:9006 +make start stable-swarm # http://:9007 +make start lama-cleaner # http://:9050 +make start face-fusion # http://:9051 +make start kohya # http://:9070 +``` + + ## Directory Structure Each interface has its own folder : diff --git a/docker-compose.yml b/docker-compose.yml index 12a83d7..2a2680d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,10 +2,10 @@ x-service: &default-service image: holaflenain/stable-diffusion:latest runtime: nvidia volumes: - - '/data/stable-diffusion:/config:rw' + - "${STABLE_DIFFUSION_DATA_DIRECTORY:-./data/stable-diffusion}:/config:rw" x-environment: &default-environment - NVIDIA_VISIBLE_DEVICES: all + NVIDIA_VISIBLE_DEVICES: ${NVIDIA_VISIBLE_DEVICES:-all} TZ: ${TZ:-America/New_York} PUID: ${PUID:-1000} PGID: ${PGID:-1000} @@ -19,7 +19,7 @@ services: <<: *default-environment WEBUI_VERSION: '01' ports: - - 9001:9000/tcp + - ${EASY_DIFFUSION_PORT:-9001}:9000/tcp stable-diffusion-automatic: <<: *default-service @@ -29,7 +29,7 @@ services: <<: *default-environment WEBUI_VERSION: '02' ports: - - 9002:9000/tcp + - ${AUTOMATIC_PORT:-9002}:9000/tcp stable-diffusion-forge: <<: *default-service @@ -39,7 +39,7 @@ services: <<: *default-environment WEBUI_VERSION: '02.forge' ports: - - 9022:9000/tcp + - ${FORGE_PORT:-9022}:9000/tcp stable-diffusion-invoke-ai: <<: *default-service @@ -49,7 +49,7 @@ services: <<: *default-environment WEBUI_VERSION: '03' ports: - - 9003:9000/tcp + - ${INVOKE_AI_PORT:-9003}:9000/tcp stable-diffusion-sd-next: <<: *default-service @@ -59,7 +59,7 @@ services: <<: *default-environment WEBUI_VERSION: '04' ports: - - 9004:9000/tcp + - ${SD_NEXT_PORT:-9004}:9000/tcp stable-diffusion-comfy-ui: <<: *default-service @@ -69,7 +69,7 @@ services: <<: *default-environment WEBUI_VERSION: '05' ports: - - 9005:9000/tcp + - ${COMFY_UI_PORT:-}9005:9000/tcp stable-diffusion-fooocus: <<: *default-service @@ -79,7 +79,7 @@ services: <<: *default-environment WEBUI_VERSION: '06' ports: - - 9006:9000/tcp + - ${FOOOCUS_PORT:-9006}:9000/tcp stable-diffusion-stable-swarm: <<: *default-service @@ -89,7 +89,7 @@ services: <<: *default-environment WEBUI_VERSION: '07' ports: - - 9007:9000/tcp + - ${STABLE_SWARM_PORT:-9007}:9000/tcp stable-diffusion-lama-cleaner: <<: *default-service @@ -99,7 +99,7 @@ services: <<: *default-environment WEBUI_VERSION: '50' ports: - - 9050:9000/tcp + - ${LAMA_CLEANER_PORT:-9050}:9000/tcp stable-diffusion-face-fusion: <<: *default-service @@ -109,7 +109,7 @@ services: <<: *default-environment WEBUI_VERSION: '51' ports: - - 9051:9000/tcp + - ${FACE_FUSION_PORT:-9051}:9000/tcp stable-diffusion-kohya: <<: *default-service @@ -119,4 +119,4 @@ services: <<: *default-environment WEBUI_VERSION: '70' ports: - - 9070:9000/tcp \ No newline at end of file + - ${KOHYA_PORT:-9070}:9000/tcp From 19e607dfdc11446461cab5b1d7ed99a75704a6ea Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 9 Jun 2024 09:50:04 +0200 Subject: [PATCH 5/7] check dependencies --- 05.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05.sh b/05.sh index 1cc7cc0..3cfb4b3 100755 --- a/05.sh +++ b/05.sh @@ -44,7 +44,7 @@ conda install -n base conda-libmamba-solver -y conda install -c conda-forge git python=3.11 pip gxx libcurand --solver=libmamba -y conda install -c nvidia cuda-cudart --solver=libmamba -y pip install onnxruntime-gpu -pip install insightface torch torchvision +pip install insightface torch>=2.2.2 torchvision opencv-python-headless>=4.9.0.80 huggingface-hub>=0.20.2 numpy>=1.24.4 install_requirements ${SD05_DIR}/ComfyUI/custom_nodes From 396c96f370817e522bb98165c703a22a50a8d729 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 9 Jun 2024 10:04:50 +0200 Subject: [PATCH 6/7] remove custom nodes requirements installation --- 05.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05.sh b/05.sh index 3cfb4b3..0c66ae9 100755 --- a/05.sh +++ b/05.sh @@ -46,7 +46,7 @@ conda install -c nvidia cuda-cudart --solver=libmamba -y pip install onnxruntime-gpu pip install insightface torch>=2.2.2 torchvision opencv-python-headless>=4.9.0.80 huggingface-hub>=0.20.2 numpy>=1.24.4 -install_requirements ${SD05_DIR}/ComfyUI/custom_nodes +#install_requirements ${SD05_DIR}/ComfyUI/custom_nodes #clean old venv if it still exists if [ -d ${SD05_DIR}/venv ]; then From 4e635e1f96c38c591ca638f1ccc988918a70f5ae Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 9 Jun 2024 10:17:02 +0200 Subject: [PATCH 7/7] install Custom Nodes dependencies only after a clean, and only fisrt level of dependencies --- 05.sh | 9 ++++++++- functions.sh | 28 +++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/05.sh b/05.sh index 0c66ae9..58fe7ea 100755 --- a/05.sh +++ b/05.sh @@ -46,7 +46,14 @@ conda install -c nvidia cuda-cudart --solver=libmamba -y pip install onnxruntime-gpu pip install insightface torch>=2.2.2 torchvision opencv-python-headless>=4.9.0.80 huggingface-hub>=0.20.2 numpy>=1.24.4 -#install_requirements ${SD05_DIR}/ComfyUI/custom_nodes +#Install custom nodes dependencies if a clean Venv has been done +if [ "$active_clean" = "1" ]; then + echo "-------------------------------------" + echo "Install Custom Nodes Dependencies" + install_requirements ${SD05_DIR}/ComfyUI/custom_nodes + echo "Done!" + echo -e "-------------------------------------\n" +fi #clean old venv if it still exists if [ -d ${SD05_DIR}/venv ]; then diff --git a/functions.sh b/functions.sh index 2fa2362..3e6aef5 100644 --- a/functions.sh +++ b/functions.sh @@ -55,6 +55,23 @@ fi } # Fonction récursive pour installer les requirements.txt +#install_requirements() { +# local directory="$1" +# local requirements_file="$directory/requirements.txt" + +# if [ -f "$requirements_file" ]; then +# echo "Installation des dépendances dans $directory ..." +# pip install -r "$requirements_file" +# echo "Dépendances installées avec succès dans $directory." +# fi + +# # Parcours récursif des sous-dossiers +# for subdir in "$directory"/*; do +# if [ -d "$subdir" ]; then +# install_requirements "$subdir" +# fi +# done +#} install_requirements() { local directory="$1" local requirements_file="$directory/requirements.txt" @@ -65,10 +82,15 @@ install_requirements() { echo "Dépendances installées avec succès dans $directory." fi - # Parcours récursif des sous-dossiers + # Parcours des sous-dossiers du premier niveau uniquement for subdir in "$directory"/*; do if [ -d "$subdir" ]; then - install_requirements "$subdir" + local subdir_requirements_file="$subdir/requirements.txt" + if [ -f "$subdir_requirements_file" ]; then + echo "Installation des dépendances dans $subdir ..." + pip install -r "$subdir_requirements_file" + echo "Dépendances installées avec succès dans $subdir." + fi fi done -} \ No newline at end of file +}