From 18fb90ea22aed7dc4b37465527d5ce37871a7bee Mon Sep 17 00:00:00 2001 From: Paul Lamb Date: Sat, 30 Dec 2023 20:34:47 -0800 Subject: [PATCH 001/101] First pass at getting Fooocus working --- docker-compose.yml | 8 ++++++ services/fooocus/Dockerfile | 48 ++++++++++++++++++++++++++++++++++ services/fooocus/config.txt | 12 +++++++++ services/fooocus/entrypoint.sh | 38 +++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 services/fooocus/Dockerfile create mode 100644 services/fooocus/config.txt create mode 100644 services/fooocus/entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml index 93fba1d..a9a4147 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,3 +71,11 @@ services: deploy: {} environment: - CLI_ARGS=--cpu + + fooocus: &fooocus + <<: *base_service + profiles: ["fooocus"] + build: ./services/fooocus/ + image: sd-fooocus:3 + environment: + - CLI_ARGS= \ No newline at end of file diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile new file mode 100644 index 0000000..5f6e120 --- /dev/null +++ b/services/fooocus/Dockerfile @@ -0,0 +1,48 @@ +FROM alpine:3.17 as xformers +RUN apk add --no-cache aria2 +RUN aria2c -x 5 --dir / --out wheel.whl 'https://github.com/AbdBarho/stable-diffusion-webui-docker/releases/download/6.0.0/xformers-0.0.21.dev544-cp310-cp310-manylinux2014_x86_64-pytorch201.whl' + +FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 + +RUN apt-get update && apt-get install -y git && apt-get clean + +# add some packages for some custom nodes in comfyui +RUN apt-get install 'libglib2.0-0' -y +RUN apt-get update +RUN apt-get install 'libgl1-mesa-glx' -y +RUN apt-get install 'python-dev' -y + +ARG BRANCH=main SHA=8e62a72a63b30a3067d1a1bc3f8d226824bd9283 + +ENV ROOT=/stable-diffusion +RUN --mount=type=cache,target=/root/.cache/pip \ + git clone https://github.com/lllyasviel/Fooocus.git ${ROOT} && \ + cd ${ROOT} && \ + git checkout ${BRANCH} && \ + git reset --hard ${SHA} && \ + pip install -r requirements_versions.txt + + +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=bind,from=xformers,source=/wheel.whl,target=/xformers-0.0.21-cp310-cp310-linux_x86_64.whl \ + pip install /xformers-0.0.21-cp310-cp310-linux_x86_64.whl + +WORKDIR ${ROOT} + +RUN --mount=type=cache,target=/root/.cache/pip \ + git fetch && \ + git checkout ${BRANCH} && \ + git reset --hard ${SHA} && \ + pip install -r requirements_versions.txt + +# add info +COPY . /docker/ +RUN chmod u+x /docker/entrypoint.sh + +#ENV NVIDIA_VISIBLE_DEVICES=all +#ENV PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" +EXPOSE 7860 +ENTRYPOINT ["/docker/entrypoint.sh"] +CMD python -u entry_with_update.py --listen --port 7860 ${CLI_ARGS} diff --git a/services/fooocus/config.txt b/services/fooocus/config.txt new file mode 100644 index 0000000..ddced71 --- /dev/null +++ b/services/fooocus/config.txt @@ -0,0 +1,12 @@ +{ + "path_checkpoints": "/stable-diffusion/models/checkpoints", + "path_loras": "/stable-diffusion/models/loras", + "path_embeddings": "/stable-diffusion/models/embeddings", + "path_vae_approx": "/stable-diffusion/models/vae_approx", + "path_upscale_models": "/stable-diffusion/models/upscale_models", + "path_inpaint": "/stable-diffusion/models/inpaint", + "path_controlnet": "/stable-diffusion/models/controlnet", + "path_clip_vision": "/stable-diffusion/models/clip_vision", + "path_fooocus_expansion": "/stable-diffusion/models/prompt_expansion/fooocus_expansion", + "path_outputs": "/stable-diffusion/outputs" +} \ No newline at end of file diff --git a/services/fooocus/entrypoint.sh b/services/fooocus/entrypoint.sh new file mode 100644 index 0000000..3cdc921 --- /dev/null +++ b/services/fooocus/entrypoint.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +set -Eeuo pipefail + +declare -A MOUNTS + +#mkdir -p ${CONFIG_DIR} ${ROOT}/configs/stable-diffusion/ + +# cache +#MOUNTS["/root/.cache"]=/data/.cache/ + +# this is really just a hack to avoid migrations +#rm -rf ${HF_HOME}/diffusers + +# ui specific +#MOUNTS["${ROOT}/models/codeformer"]=/data/models/Codeformer/ +#MOUNTS["${ROOT}/models/gfpgan/GFPGANv1.4.pth"]=/data/models/GFPGAN/GFPGANv1.4.pth +#MOUNTS["${ROOT}/models/gfpgan/weights"]=/data/models/GFPGAN/ +#MOUNTS["${ROOT}/models/realesrgan"]=/data/models/RealESRGAN/ +#MOUNTS["${ROOT}/models/ldm"]=/data/.cache/invoke/ldm/ + +# hacks + +for to_path in "${!MOUNTS[@]}"; do + set -Eeuo pipefail + from_path="${MOUNTS[${to_path}]}" + rm -rf "${to_path}" + mkdir -p "$(dirname "${to_path}")" + # ends with slash, make it! + if [[ "$from_path" == */ ]]; then + mkdir -vp "$from_path" + fi + + ln -sT "${from_path}" "${to_path}" + echo Mounted $(basename "${from_path}") +done + +exec "$@" From 77cfe4965ee3ccf40634f1be3486da640497c2ca Mon Sep 17 00:00:00 2001 From: Paul Lamb Date: Sat, 30 Dec 2023 22:20:58 -0800 Subject: [PATCH 002/101] Adding mount points to shared models --- services/fooocus/Dockerfile | 7 +++---- services/fooocus/entrypoint.sh | 22 +++++++--------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile index 5f6e120..7a1ff77 100644 --- a/services/fooocus/Dockerfile +++ b/services/fooocus/Dockerfile @@ -8,12 +8,12 @@ ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 RUN apt-get update && apt-get install -y git && apt-get clean -# add some packages for some custom nodes in comfyui +# add in required packages RUN apt-get install 'libglib2.0-0' -y -RUN apt-get update RUN apt-get install 'libgl1-mesa-glx' -y RUN apt-get install 'python-dev' -y +# set this to your target branch commit ARG BRANCH=main SHA=8e62a72a63b30a3067d1a1bc3f8d226824bd9283 ENV ROOT=/stable-diffusion @@ -39,10 +39,9 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # add info COPY . /docker/ +RUN cp /docker/config.txt ${ROOT} RUN chmod u+x /docker/entrypoint.sh -#ENV NVIDIA_VISIBLE_DEVICES=all -#ENV PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" EXPOSE 7860 ENTRYPOINT ["/docker/entrypoint.sh"] CMD python -u entry_with_update.py --listen --port 7860 ${CLI_ARGS} diff --git a/services/fooocus/entrypoint.sh b/services/fooocus/entrypoint.sh index 3cdc921..ee1416e 100644 --- a/services/fooocus/entrypoint.sh +++ b/services/fooocus/entrypoint.sh @@ -4,22 +4,14 @@ set -Eeuo pipefail declare -A MOUNTS -#mkdir -p ${CONFIG_DIR} ${ROOT}/configs/stable-diffusion/ +MOUNTS["${ROOT}/outputs"]="/output/fooocus" -# cache -#MOUNTS["/root/.cache"]=/data/.cache/ - -# this is really just a hack to avoid migrations -#rm -rf ${HF_HOME}/diffusers - -# ui specific -#MOUNTS["${ROOT}/models/codeformer"]=/data/models/Codeformer/ -#MOUNTS["${ROOT}/models/gfpgan/GFPGANv1.4.pth"]=/data/models/GFPGAN/GFPGANv1.4.pth -#MOUNTS["${ROOT}/models/gfpgan/weights"]=/data/models/GFPGAN/ -#MOUNTS["${ROOT}/models/realesrgan"]=/data/models/RealESRGAN/ -#MOUNTS["${ROOT}/models/ldm"]=/data/.cache/invoke/ldm/ - -# hacks +# ui specific mounts +MOUNTS["${ROOT}/models/checkpoints"]=/data/models/Stable-diffusion/ +MOUNTS["${ROOT}/models/loras"]=/data/models/Lora/ +MOUNTS["${ROOT}/models/embeddings"]=/data/models/embeddings/ +MOUNTS["${ROOT}/models/vae_approx"]=/data/models/VAE/ +MOUNTS["${ROOT}/models/upscale_models"]=/data/models/upscale_models/ for to_path in "${!MOUNTS[@]}"; do set -Eeuo pipefail From 74813d56e7c3a1c517c9f21061de29668ce93bd4 Mon Sep 17 00:00:00 2001 From: Paul Lamb Date: Sun, 31 Dec 2023 14:32:26 -0800 Subject: [PATCH 003/101] Updated readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 95e10c3..a67bd9f 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,14 @@ This repository provides multiple UIs for you to play around with stable diffusi | -------------------------------------------------------------------------------- | | ![](https://github.com/comfyanonymous/ComfyUI/raw/master/comfyui_screenshot.png) | +### [Fooocus](https://github.com/comfyanonymous/ComfyUI) + +[Full feature list here](https://github.com/lllyasviel/Fooocus#fooocus), Screenshot: + +| Simplified UI | +| -------------------------------------------------------------------------------- | +| ![](https://github.com/lllyasviel/Fooocus/assets/19834515/483fb86d-c9a2-4c20-997c-46dafc124f25) | + ## Contributing Contributions are welcome! **Create a discussion first of what the problem is and what you want to contribute (before you implement anything)** From ff6e3d6fa87caa5cebaea89cefb3e8938c4cdaf8 Mon Sep 17 00:00:00 2001 From: Paul Lamb Date: Tue, 2 Jan 2024 00:17:55 -0800 Subject: [PATCH 004/101] Adding mount for wildcard functionality --- services/fooocus/entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/fooocus/entrypoint.sh b/services/fooocus/entrypoint.sh index ee1416e..cc0fa75 100644 --- a/services/fooocus/entrypoint.sh +++ b/services/fooocus/entrypoint.sh @@ -2,6 +2,8 @@ set -Eeuo pipefail +mkdir -vp /data/config/fooocus/wildcards + declare -A MOUNTS MOUNTS["${ROOT}/outputs"]="/output/fooocus" @@ -12,6 +14,7 @@ MOUNTS["${ROOT}/models/loras"]=/data/models/Lora/ MOUNTS["${ROOT}/models/embeddings"]=/data/models/embeddings/ MOUNTS["${ROOT}/models/vae_approx"]=/data/models/VAE/ MOUNTS["${ROOT}/models/upscale_models"]=/data/models/upscale_models/ +MOUNTS["${ROOT}/wildcards"]=/data/config/fooocus/wildcards for to_path in "${!MOUNTS[@]}"; do set -Eeuo pipefail From cfc373d1d144f13adab8e095dd6e8f76c3cb951f Mon Sep 17 00:00:00 2001 From: Paul Lamb Date: Thu, 11 Apr 2024 16:44:12 -0700 Subject: [PATCH 005/101] Version bump, fooocus 2.3.1 --- services/fooocus/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile index 7a1ff77..1892f6b 100644 --- a/services/fooocus/Dockerfile +++ b/services/fooocus/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get install 'libgl1-mesa-glx' -y RUN apt-get install 'python-dev' -y # set this to your target branch commit -ARG BRANCH=main SHA=8e62a72a63b30a3067d1a1bc3f8d226824bd9283 +ARG BRANCH=main SHA=e2f9bcb11d06216d6800676c48d8d74d6fd77a4b ENV ROOT=/stable-diffusion RUN --mount=type=cache,target=/root/.cache/pip \ From e9fa4e641a0010c790b4a5ed94c44828bb1b6912 Mon Sep 17 00:00:00 2001 From: au70ma70n Date: Thu, 22 Aug 2024 18:44:43 -0500 Subject: [PATCH 006/101] add forge support --- services/forge/Dockerfile | 78 ++++++++++++++++++++++++++++++++ services/forge/clone.sh | 11 +++++ services/forge/config.py | 79 ++++++++++++++++++++++++++++++++ services/forge/entrypoint.sh | 85 +++++++++++++++++++++++++++++++++++ services/forge/tmp_dockerfile | 56 +++++++++++++++++++++++ 5 files changed, 309 insertions(+) create mode 100644 services/forge/Dockerfile create mode 100644 services/forge/clone.sh create mode 100644 services/forge/config.py create mode 100755 services/forge/entrypoint.sh create mode 100644 services/forge/tmp_dockerfile diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile new file mode 100644 index 0000000..65d0f1e --- /dev/null +++ b/services/forge/Dockerfile @@ -0,0 +1,78 @@ +FROM alpine/git:2.36.2 AS download + +COPY clone.sh /clone.sh + + +RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ + && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif + +RUN . /clone.sh CodeFormer https://github.com/sczhou/CodeFormer.git c5b4593074ba6214284d6acd5f1719b6c5d739af \ + && rm -rf assets inputs + +RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9 +RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c +RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 +RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f +RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917 + + +FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && \ + # we need those + apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ + # extensions needs those + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + + +WORKDIR / +RUN --mount=type=cache,target=/root/.cache/pip \ + git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git && \ + cd stable-diffusion-webui-forge && \ + sed -i '/torch/d' requirements_versions.txt && \ + pip install -r requirements_versions.txt + + +ENV ROOT=/stable-diffusion-webui-forge + +COPY --from=download /repositories/ ${ROOT}/repositories/ +RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt + +# Clone and copy huggingface_guess module +RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingface_guess && \ + cp -r /tmp/huggingface_guess/huggingface_guess ${ROOT}/huggingface_guess + +# Ensure torchvision is correctly installed +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install torchvision==0.18.1 + + +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install pyngrok xformers==0.0.27 pytorch_lightning torchdiffeq torchsde \ + git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ + git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ + git+https://github.com/mlfoundations/open_clip.git@v2.20.0 +# there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc +# maybe move this up to the dependencies list. +RUN apt-get -y install libgoogle-perftools-dev && apt-get clean +ENV LD_PRELOAD=libtcmalloc.so + +COPY . /docker + +RUN \ + # mv ${ROOT}/style.css ${ROOT}/user.css && \ + # one of the ugliest hacks I ever wrote \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + git config --global --add safe.directory '*' + +WORKDIR ${ROOT} +ENV NVIDIA_VISIBLE_DEVICES=all +ENV CLI_ARGS="" +EXPOSE 7860 +ENTRYPOINT ["/docker/entrypoint.sh"] +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} diff --git a/services/forge/clone.sh b/services/forge/clone.sh new file mode 100644 index 0000000..2c37c41 --- /dev/null +++ b/services/forge/clone.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -Eeuox pipefail + +mkdir -p /repositories/"$1" +cd /repositories/"$1" +git init +git remote add origin "$2" +git fetch origin "$3" --depth=1 +git reset --hard "$3" +rm -rf .git \ No newline at end of file diff --git a/services/forge/config.py b/services/forge/config.py new file mode 100644 index 0000000..b06bf45 --- /dev/null +++ b/services/forge/config.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +"""Checks and sets default values for config.json before starting the container.""" + +import json +import re +import os.path +import sys + +DEFAULT_FILEPATH = '/data/config/forge/config.json' + +DEFAULT_OUTDIRS = { + "outdir_samples": "", + "outdir_txt2img_samples": "/output/txt2img", + "outdir_img2img_samples": "/output/img2img", + "outdir_extras_samples": "/output/extras", + "outdir_grids": "", + "outdir_txt2img_grids": "/output/txt2img-grids", + "outdir_img2img_grids": "/output/img2img-grids", + "outdir_save": "/output/saved", + "outdir_init_images": "/output/init-images", +} +RE_VALID_OUTDIR = re.compile(r"(^/output(/\.?[\w\-\_]+)+/?$)|(^\s?$)") + +DEFAULT_OTHER = { + "font": "DejaVuSans.ttf", +} + +def dict_to_json_file(target_file: str, data: dict): + """Write dictionary to specified json file""" + + with open(target_file, 'w') as f: + json.dump(data, f) + +def json_file_to_dict(config_file: str) -> dict|None: + """Load json file into a dictionary. Return None if file does not exist.""" + + if os.path.isfile(config_file): + with open(config_file, 'r') as f: + return json.load(f) + else: + return None + +def replace_if_invalid(value: str, replacement: str, pattern: str|re.Pattern[str]) -> str: + """Returns original value if valid, fallback value if invalid""" + + if re.match(pattern, value): + return value + else: + return replacement + +def check_and_replace_config(config_file: str, target_file: str = None): + """Checks given file for invalid values. Replaces those with fallback values (default: overwrites file).""" + + # Get current user config, or empty if file does not exists + data = json_file_to_dict(config_file) or {} + + # Check and fix output directories + for k, def_val in DEFAULT_OUTDIRS.items(): + if k not in data: + data[k] = def_val + else: + data[k] = replace_if_invalid(value=data[k], replacement=def_val, pattern=RE_VALID_OUTDIR) + + # Check and fix other default settings + for k, def_val in DEFAULT_OTHER.items(): + if k not in data: + data[k] = def_val + + # Write results to file + dict_to_json_file(target_file or config_file, data) + +if __name__ == '__main__': + if len(sys.argv) > 1: + check_and_replace_config(*sys.argv[1:]) + else: + check_and_replace_config(DEFAULT_FILEPATH) + + diff --git a/services/forge/entrypoint.sh b/services/forge/entrypoint.sh new file mode 100755 index 0000000..6532393 --- /dev/null +++ b/services/forge/entrypoint.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +set -Eeuo pipefail + +# TODO: move all mkdir -p ? +mkdir -p /data/config/forge/scripts/ +# mount scripts individually + +echo $ROOT +ls -lha $ROOT + +find "${ROOT}/scripts/" -maxdepth 1 -type l -delete +cp -vrfTs /data/config/forge/scripts/ "${ROOT}/scripts/" + +# Set up config file +python /docker/config.py /data/config/forge/config.json + +if [ ! -f /data/config/forge/ui-config.json ]; then + echo '{}' >/data/config/forge/ui-config.json +fi + +if [ ! -f /data/config/forge/styles.csv ]; then + touch /data/config/forge/styles.csv +fi + +# copy models from original models folder +mkdir -p /data/models/VAE-approx/ /data/models/karlo/ + +rsync -a --info=NAME ${ROOT}/models/VAE-approx/ /data/models/VAE-approx/ +rsync -a --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ + +declare -A MOUNTS + +MOUNTS["/root/.cache"]="/data/.cache" +MOUNTS["${ROOT}/models"]="/data/models" + +MOUNTS["${ROOT}/embeddings"]="/data/embeddings" +MOUNTS["${ROOT}/config.json"]="/data/config/forge/config.json" +MOUNTS["${ROOT}/ui-config.json"]="/data/config/forge/ui-config.json" +MOUNTS["${ROOT}/styles.csv"]="/data/config/forge/styles.csv" +MOUNTS["${ROOT}/extensions"]="/data/config/forge/extensions" +MOUNTS["${ROOT}/config_states"]="/data/config/forge/config_states" + +# extra hacks +MOUNTS["${ROOT}/repositories/CodeFormer/weights/facelib"]="/data/.cache" + +for to_path in "${!MOUNTS[@]}"; do + set -Eeuo pipefail + from_path="${MOUNTS[${to_path}]}" + rm -rf "${to_path}" + if [ ! -f "$from_path" ]; then + mkdir -vp "$from_path" + fi + mkdir -vp "$(dirname "${to_path}")" + ln -sT "${from_path}" "${to_path}" + echo Mounted $(basename "${from_path}") +done + +echo "Installing extension dependencies (if any)" + +# because we build our container as root: +chown -R root ~/.cache/ +chmod 766 ~/.cache/ + +shopt -s nullglob +# For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy +list=(./extensions/*/install.py) +for installscript in "${list[@]}"; do + EXTNAME=$(echo $installscript | cut -d '/' -f 3) + # Skip installing dependencies if extension is disabled in config + if $(jq -e ".disabled_extensions|any(. == \"$EXTNAME\")" config.json); then + echo "Skipping disabled extension ($EXTNAME)" + continue + fi + PYTHONPATH=${ROOT} python "$installscript" +done + +if [ -f "/data/config/forge/startup.sh" ]; then + pushd ${ROOT} + echo "Running startup script" + . /data/config/forge/startup.sh + popd +fi + +exec "$@" diff --git a/services/forge/tmp_dockerfile b/services/forge/tmp_dockerfile new file mode 100644 index 0000000..301d025 --- /dev/null +++ b/services/forge/tmp_dockerfile @@ -0,0 +1,56 @@ +FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && \ + # we need those + apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ + # extensions needs those + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + +WORKDIR / +RUN --mount=type=cache,target=/root/.cache/pip \ + git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git && \ + cd stable-diffusion-webui-forge && \ + pip install -r requirements_versions.txt + +ENV ROOT=/stable-diffusion-webui-forge + +COPY --from=download /repositories/ ${ROOT}/repositories/ +RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt + +# Clone and copy huggingface_guess module +RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingface_guess && \ + cp -r /tmp/huggingface_guess/huggingface_guess ${ROOT}/huggingface_guess + +# Ensure torchvision is correctly installed +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install --upgrade torchvision + +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install pyngrok xformers==0.0.23.post1 \ + git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ + git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ + git+https://github.com/mlfoundations/open_clip.git@v2.20.0 + +# there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc +# maybe move this up to the dependencies list. +RUN apt-get -y install libgoogle-perftools-dev && apt-get clean +ENV LD_PRELOAD=libtcmalloc.so + +COPY . /docker + +RUN \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + git config --global --add safe.directory '*' + +WORKDIR ${ROOT} +ENV PYTHONPATH=${ROOT}:${PYTHONPATH} +ENV NVIDIA_VISIBLE_DEVICES=all +ENV CLI_ARGS="" +EXPOSE 7860 +ENTRYPOINT ["/docker/entrypoint.sh"] +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} \ No newline at end of file From f859c3b2212962373de1757b49cb1e2f5af0104b Mon Sep 17 00:00:00 2001 From: au70ma70n Date: Fri, 23 Aug 2024 11:00:54 -0500 Subject: [PATCH 007/101] Fix forge in compose --- docker-compose.yml | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 970b612..e87ddef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +version: '3.9' x-base_service: &base_service ports: - "${WEBUI_PORT:-7860}:7860" @@ -13,40 +14,56 @@ x-base_service: &base_service - driver: nvidia device_ids: ['0'] capabilities: [compute, utility] - name: webui-docker - services: download: build: ./services/download/ profiles: ["download"] volumes: - *v1 - auto: &automatic <<: *base_service profiles: ["auto"] build: ./services/AUTOMATIC1111 - image: sd-auto:78 + image: sd-auto:72 environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api + forge: &forge + <<: *base_service + profiles: ["forge"] + build: ./services/forge + image: sd-forge-fgcustom:72 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + auto-cpu: <<: *automatic profiles: ["auto-cpu"] deploy: {} environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api - + invoke: &invoke + <<: *base_service + profiles: ["invoke"] + build: ./services/invoke/ + image: sd-invoke:30 + environment: + - PRELOAD=true + - CLI_ARGS=--xformers + # invoke-cpu: + # <<: *invoke + # profiles: ["invoke-cpu"] + # environment: + # - PRELOAD=true + # - CLI_ARGS=--always_use_cpu comfy: &comfy <<: *base_service profiles: ["comfy"] build: ./services/comfy/ - image: sd-comfy:7 + image: sd-comfy:6 environment: - CLI_ARGS= - - comfy-cpu: <<: *comfy profiles: ["comfy-cpu"] From 3ed0a6acf7bfa19ece10c3037def1ea83fd0cbed Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Thu, 16 Jan 2025 20:28:44 +0000 Subject: [PATCH 008/101] updates --- docker-compose.yml | 1 - services/AUTOMATIC1111/Dockerfile | 4 ++-- services/AUTOMATIC1111/clone.sh | 2 +- services/forge/Dockerfile | 5 +---- services/forge/config.py | 1 - 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e87ddef..f49d73d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.9' x-base_service: &base_service ports: - "${WEBUI_PORT:-7860}:7860" diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index d595784..ff0454f 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine/git:2.36.2 as download +FROM alpine/git:2.36.2 AS download COPY clone.sh /clone.sh @@ -30,7 +30,7 @@ WORKDIR / RUN --mount=type=cache,target=/root/.cache/pip \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ cd stable-diffusion-webui && \ - git reset --hard v1.9.4 && \ + git reset --hard v1.10.0 && \ pip install -r requirements_versions.txt diff --git a/services/AUTOMATIC1111/clone.sh b/services/AUTOMATIC1111/clone.sh index cfdf0a2..2c37c41 100644 --- a/services/AUTOMATIC1111/clone.sh +++ b/services/AUTOMATIC1111/clone.sh @@ -8,4 +8,4 @@ git init git remote add origin "$2" git fetch origin "$3" --depth=1 git reset --hard "$3" -rm -rf .git +rm -rf .git \ No newline at end of file diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 65d0f1e..d18f430 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -2,7 +2,6 @@ FROM alpine/git:2.36.2 AS download COPY clone.sh /clone.sh - RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif @@ -35,7 +34,6 @@ RUN --mount=type=cache,target=/root/.cache/pip \ sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt - ENV ROOT=/stable-diffusion-webui-forge COPY --from=download /repositories/ ${ROOT}/repositories/ @@ -51,7 +49,6 @@ RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingfa RUN --mount=type=cache,target=/root/.cache/pip \ pip install torchvision==0.18.1 - RUN --mount=type=cache,target=/root/.cache/pip \ pip install pyngrok xformers==0.0.27 pytorch_lightning torchdiffeq torchsde \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ @@ -75,4 +72,4 @@ ENV NVIDIA_VISIBLE_DEVICES=all ENV CLI_ARGS="" EXPOSE 7860 ENTRYPOINT ["/docker/entrypoint.sh"] -CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} \ No newline at end of file diff --git a/services/forge/config.py b/services/forge/config.py index b06bf45..7ab28d7 100644 --- a/services/forge/config.py +++ b/services/forge/config.py @@ -76,4 +76,3 @@ if __name__ == '__main__': else: check_and_replace_config(DEFAULT_FILEPATH) - From 276f417a7e4894f29e691b57a0be686bbc861ee5 Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Thu, 16 Jan 2025 20:46:19 +0000 Subject: [PATCH 009/101] updates --- docker-compose.yml | 4 ++-- services/AUTOMATIC1111/Dockerfile | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f49d73d..0fba59e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: <<: *base_service profiles: ["auto"] build: ./services/AUTOMATIC1111 - image: sd-auto:72 + image: sd-auto:80 environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api @@ -32,7 +32,7 @@ services: <<: *base_service profiles: ["forge"] build: ./services/forge - image: sd-forge-fgcustom:72 + image: sd-forge:80 environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index ff0454f..047bc95 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -33,6 +33,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ git reset --hard v1.10.0 && \ pip install -r requirements_versions.txt +RUN pip install --upgrade typing-extensions ENV ROOT=/stable-diffusion-webui From 3367764793ec4c15c60f9833551da046ab696a1e Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:14:27 +0000 Subject: [PATCH 010/101] Update README.md updated readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 46b5630..14e8eeb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +I have forked this as abdbarho hasn't been around for a while. I'm not great with git, Linux , docker or stable diffusion but I manage to get along a bit. Slowly. with more commits than it takes. + +I am happy to look at PR's as and when. Also happy to pass this back, as and whe, and if, they return. + + # Stable Diffusion WebUI Docker Run Stable Diffusion on your machine with a nice UI without any hassle! From 015f531c4c76cc343b0e3473b0829076b95e05a7 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:16:13 +0000 Subject: [PATCH 011/101] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14e8eeb..01872d9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -I have forked this as abdbarho hasn't been around for a while. I'm not great with git, Linux , docker or stable diffusion but I manage to get along a bit. Slowly. with more commits than it takes. +I have forked this as AbdBarho hasn't been around for a while. I'm not great with git, Linux , docker or stable diffusion but I manage to get along a bit. Slowly. with more commits than it takes. I am happy to look at PR's as and when. Also happy to pass this back, as and whe, and if, they return. From 20b593f840d17c9e512e6984d75579df489a8783 Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 20 Jan 2025 11:49:41 +0000 Subject: [PATCH 012/101] huggingface_guess was in incorrect location --- services/forge/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index d18f430..807f3ac 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -13,6 +13,7 @@ RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9 RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917 +RUN . /clone.sh huggingface_guess https://github.com/lllyasviel/huggingface_guess.git 70942022b6bcd17d941c1b4172804175758618e2 FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime @@ -42,8 +43,8 @@ RUN --mount=type=cache,target=/root/.cache/pip \ pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt # Clone and copy huggingface_guess module -RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingface_guess && \ - cp -r /tmp/huggingface_guess/huggingface_guess ${ROOT}/huggingface_guess +#RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingface_guess && \ +# cp -r /tmp/huggingface_guess/huggingface_guess ${ROOT}/huggingface_guess # Ensure torchvision is correctly installed RUN --mount=type=cache,target=/root/.cache/pip \ From ae30d6b0af580a0775310c93db4e2672c3c2bd72 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:02:33 +0000 Subject: [PATCH 013/101] Update Dockerfile pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime --- services/AUTOMATIC1111/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 047bc95..2d0559a 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -14,7 +14,8 @@ RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-mod RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 -FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +#FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 From 9e86d3ea7078ac238eb9c10610f12c20cee9ee69 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:37:08 +0000 Subject: [PATCH 014/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 2d0559a..e589afb 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -57,7 +57,7 @@ COPY . /docker RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + #sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ git config --global --add safe.directory '*' WORKDIR ${ROOT} From 56127109197fee55809940fa6378f9c0a8b19b26 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:41:41 +0000 Subject: [PATCH 015/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index e589afb..b3e6d7e 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -14,8 +14,8 @@ RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-mod RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 -#FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime -FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime +FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +#FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -57,7 +57,7 @@ COPY . /docker RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ - #sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ git config --global --add safe.directory '*' WORKDIR ${ROOT} From 8619e741270c621d5ebd142d201142492efb692e Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:56:30 +0000 Subject: [PATCH 016/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index b3e6d7e..026bd54 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -14,8 +14,8 @@ RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-mod RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 -FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime -#FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime +#FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -57,7 +57,8 @@ COPY . /docker RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + # updated from 3.10.to 3.11 + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py && \ git config --global --add safe.directory '*' WORKDIR ${ROOT} From bf55e214ac64bcd75f302602507cf9a068341e03 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Feb 2025 16:36:56 +0000 Subject: [PATCH 017/101] Update entrypoint.sh --- services/AUTOMATIC1111/entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index 35023af..3b4d92b 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -26,8 +26,8 @@ fi # copy models from original models folder mkdir -p /data/models/VAE-approx/ /data/models/karlo/ -rsync -a --info=NAME ${ROOT}/models/VAE-approx/ /data/models/VAE-approx/ -rsync -a --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ +rsync --info=NAME ${ROOT}/models/VAE-approx/ /data/models/VAE-approx/ +rsync --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ declare -A MOUNTS From 1fa117f333de996ca203ed64ec9cbaebaa849412 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Feb 2025 20:39:04 +0000 Subject: [PATCH 018/101] Update Dockerfile 1.10.1 --- services/AUTOMATIC1111/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 026bd54..54d41ba 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -31,7 +31,7 @@ WORKDIR / RUN --mount=type=cache,target=/root/.cache/pip \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ cd stable-diffusion-webui && \ - git reset --hard v1.10.0 && \ + git reset --hard v1.10.1 && \ pip install -r requirements_versions.txt RUN pip install --upgrade typing-extensions From cc08ed6a109881f95b41ad6adc6f5a7b7a351969 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:23:04 +0000 Subject: [PATCH 019/101] Update Dockerfile remove root user requirement --- services/AUTOMATIC1111/Dockerfile | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 54d41ba..a33fb1d 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -24,8 +24,45 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential \ + apt-get clean +ARG PUID=0 +ARG PGID=0 +ARG USER_HOME=/root +# set build args as container environment variables for entrypoint reference +ENV PUID=$PUID +ENV PGID=$PGID +ENV USER_HOME=$USER_HOME + +# if user home does not exist, create it +RUN mkdir -p "$USER_HOME" + +# home already exists, chown it +RUN chown -R "${PUID}:${PGID}" "$USER_HOME" + +# Only groupadd if we're non root +RUN if [ "$PGID" -ne "0" ]; then \ + echo non root group detected; \ + groupadd \ + --gid "$PGID" \ + stablediffusion ;\ + else \ + echo "root group detected" ; \ + fi + +# Only useradd if we're non root +RUN if [ "$PUID" -ne "0" ]; then \ + echo non root user detected; \ + useradd \ + --gid="$PGID" \ + --no-user-group \ + -M \ + --home "$USER_HOME" \ + stablediffusion ; \ + else \ + echo "root group detected" ; \ + fi WORKDIR / RUN --mount=type=cache,target=/root/.cache/pip \ @@ -36,9 +73,13 @@ RUN --mount=type=cache,target=/root/.cache/pip \ RUN pip install --upgrade typing-extensions +RUN chown -R "$PUID:$PGID" /stable-diffusion-webui + +# drop permissions (if build targets non root) +USER $PUID:$PGID ENV ROOT=/stable-diffusion-webui -COPY --from=download /repositories/ ${ROOT}/repositories/ +COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate RUN --mount=type=cache,target=/root/.cache/pip \ From b52f5c6f4bd6248c3a921dc31a4e3d0e13a4393a Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:26:04 +0000 Subject: [PATCH 020/101] Update entrypoint.sh remove root user --- services/AUTOMATIC1111/entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index 3b4d92b..e5b5bcb 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -31,7 +31,8 @@ rsync --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ declare -A MOUNTS -MOUNTS["/root/.cache"]="/data/.cache" +#MOUNTS["/root/.cache"]="/data/.cache" +MOUNTS["${USER_HOME}/.cache"]="/data/.cache" MOUNTS["${ROOT}/models"]="/data/models" MOUNTS["${ROOT}/embeddings"]="/data/embeddings" @@ -58,8 +59,7 @@ done echo "Installing extension dependencies (if any)" -# because we build our container as root: -chown -R root ~/.cache/ +chown -R $PUID:$PGID ~/.cache/ chmod 766 ~/.cache/ shopt -s nullglob From 66a1490c87bd95eba3c1e6012accec20cb953362 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:27:21 +0000 Subject: [PATCH 021/101] Update entrypoint.sh make output belong to user too --- services/AUTOMATIC1111/entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index e5b5bcb..4313803 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -62,6 +62,9 @@ echo "Installing extension dependencies (if any)" chown -R $PUID:$PGID ~/.cache/ chmod 766 ~/.cache/ +chown -R $PUID:$PGID /output +chmod 766 /output + shopt -s nullglob # For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy list=(./extensions/*/install.py) From b642d3a7f25acaf1c12d2721cdca61a3251f11ee Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:34:35 +0000 Subject: [PATCH 022/101] Update Dockerfile fix --- services/AUTOMATIC1111/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index a33fb1d..3f2c893 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -24,7 +24,7 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential \ + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential && \ apt-get clean ARG PUID=0 From 18709fa51227d0394aae30a55b2c7253568cc44e Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:55:04 +0000 Subject: [PATCH 023/101] Update docker-compose.yml --- docker-compose.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 995427e..30db3ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,7 @@ services: profiles: ["download"] volumes: - *v1 + auto: &automatic <<: *base_service profiles: ["auto"] @@ -27,6 +28,8 @@ services: image: sd-auto:80 environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api + - PUID=1000 + - PGID=1000 forge: &forge <<: *base_service @@ -35,6 +38,8 @@ services: image: sd-forge:80 environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + - PUID=1000 + - PGID=1000 auto-cpu: <<: *automatic @@ -42,6 +47,9 @@ services: deploy: {} environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api + - PUID=1000 + - PGID=1000 + invoke: &invoke <<: *base_service profiles: ["invoke"] @@ -50,12 +58,16 @@ services: environment: - PRELOAD=true - CLI_ARGS=--xformers + - PUID=1000 + - PGID=1000 + # invoke-cpu: # <<: *invoke # profiles: ["invoke-cpu"] # environment: # - PRELOAD=true # - CLI_ARGS=--always_use_cpu + comfy: &comfy <<: *base_service profiles: ["comfy"] @@ -63,12 +75,17 @@ services: image: sd-comfy:6 environment: - CLI_ARGS= + - PUID=1000 + - PGID=1000 + comfy-cpu: <<: *comfy profiles: ["comfy-cpu"] deploy: {} environment: - CLI_ARGS=--cpu + - PUID=1000 + - PGID=1000 fooocus: &fooocus <<: *base_service @@ -76,4 +93,6 @@ services: build: ./services/fooocus/ image: sd-fooocus:3 environment: - - CLI_ARGS= \ No newline at end of file + - CLI_ARGS= + - PUID=1000 + - PGID=1000 From fe5caa90661dc3d17a553c2134093c5f26812290 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:06:54 +0000 Subject: [PATCH 024/101] Discard changes to docker-compose.yml --- docker-compose.yml | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 30db3ec..995427e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,6 @@ services: profiles: ["download"] volumes: - *v1 - auto: &automatic <<: *base_service profiles: ["auto"] @@ -28,8 +27,6 @@ services: image: sd-auto:80 environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api - - PUID=1000 - - PGID=1000 forge: &forge <<: *base_service @@ -38,8 +35,6 @@ services: image: sd-forge:80 environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream - - PUID=1000 - - PGID=1000 auto-cpu: <<: *automatic @@ -47,9 +42,6 @@ services: deploy: {} environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api - - PUID=1000 - - PGID=1000 - invoke: &invoke <<: *base_service profiles: ["invoke"] @@ -58,16 +50,12 @@ services: environment: - PRELOAD=true - CLI_ARGS=--xformers - - PUID=1000 - - PGID=1000 - # invoke-cpu: # <<: *invoke # profiles: ["invoke-cpu"] # environment: # - PRELOAD=true # - CLI_ARGS=--always_use_cpu - comfy: &comfy <<: *base_service profiles: ["comfy"] @@ -75,17 +63,12 @@ services: image: sd-comfy:6 environment: - CLI_ARGS= - - PUID=1000 - - PGID=1000 - comfy-cpu: <<: *comfy profiles: ["comfy-cpu"] deploy: {} environment: - CLI_ARGS=--cpu - - PUID=1000 - - PGID=1000 fooocus: &fooocus <<: *base_service @@ -93,6 +76,4 @@ services: build: ./services/fooocus/ image: sd-fooocus:3 environment: - - CLI_ARGS= - - PUID=1000 - - PGID=1000 + - CLI_ARGS= \ No newline at end of file From 268892366134d0850752d116c5eeca1b1846209b Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:21:46 +0000 Subject: [PATCH 025/101] Update Dockerfile add non root --- services/forge/Dockerfile | 49 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 807f3ac..79f4497 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -25,7 +25,45 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential && \ + apt-get clean + +ARG PUID=0 +ARG PGID=0 +ARG USER_HOME=/root +# set build args as container environment variables for entrypoint reference +ENV PUID=$PUID +ENV PGID=$PGID +ENV USER_HOME=$USER_HOME + +# if user home does not exist, create it +RUN mkdir -p "$USER_HOME" + +# home already exists, chown it +RUN chown -R "${PUID}:${PGID}" "$USER_HOME" + +# Only groupadd if we're non root +RUN if [ "$PGID" -ne "0" ]; then \ + echo non root group detected; \ + groupadd \ + --gid "$PGID" \ + stablediffusion ;\ + else \ + echo "root group detected" ; \ + fi + +# Only useradd if we're non root +RUN if [ "$PUID" -ne "0" ]; then \ + echo non root user detected; \ + useradd \ + --gid="$PGID" \ + --no-user-group \ + -M \ + --home "$USER_HOME" \ + stablediffusion ; \ + else \ + echo "root group detected" ; \ + fi WORKDIR / @@ -35,9 +73,14 @@ RUN --mount=type=cache,target=/root/.cache/pip \ sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt +RUN chown -R "$PUID:$PGID" /stable-diffusion-webui + +# drop permissions (if build targets non root) +USER $PUID:$PGID + ENV ROOT=/stable-diffusion-webui-forge -COPY --from=download /repositories/ ${ROOT}/repositories/ +COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate RUN --mount=type=cache,target=/root/.cache/pip \ pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt @@ -73,4 +116,4 @@ ENV NVIDIA_VISIBLE_DEVICES=all ENV CLI_ARGS="" EXPOSE 7860 ENTRYPOINT ["/docker/entrypoint.sh"] -CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} \ No newline at end of file +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} From c1c52f5e538d238e894091774120c06f8e4a9484 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:23:41 +0000 Subject: [PATCH 026/101] Update entrypoint.sh non root --- services/forge/entrypoint.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/services/forge/entrypoint.sh b/services/forge/entrypoint.sh index 6532393..110ed98 100755 --- a/services/forge/entrypoint.sh +++ b/services/forge/entrypoint.sh @@ -31,7 +31,7 @@ rsync -a --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ declare -A MOUNTS -MOUNTS["/root/.cache"]="/data/.cache" +MOUNTS["${USER_HOME}/.cache"]="/data/.cache" MOUNTS["${ROOT}/models"]="/data/models" MOUNTS["${ROOT}/embeddings"]="/data/embeddings" @@ -56,11 +56,12 @@ for to_path in "${!MOUNTS[@]}"; do echo Mounted $(basename "${from_path}") done -echo "Installing extension dependencies (if any)" - -# because we build our container as root: -chown -R root ~/.cache/ +chown -R $PUID:$PGID ~/.cache/ chmod 766 ~/.cache/ +chown -R $PUID:$PGID /output +chmod 766 /output + +echo "Installing extension dependencies (if any)" shopt -s nullglob # For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy From 321046928469f72d6bd73140fd70579ab2287706 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:28:52 +0000 Subject: [PATCH 027/101] Update Dockerfile oops --- services/forge/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 79f4497..dd69f92 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -73,7 +73,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt -RUN chown -R "$PUID:$PGID" /stable-diffusion-webui +RUN chown -R "$PUID:$PGID" /stable-diffusion-webui-forge # drop permissions (if build targets non root) USER $PUID:$PGID From dd08166d5e94afef5a32062977e18922513a7dcd Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 13:52:58 +0000 Subject: [PATCH 028/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 3f2c893..90d3cd1 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -24,7 +24,7 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential && \ + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential libgoogle-perftools-dev && \ apt-get clean ARG PUID=0 From dd4791cf0aef1ed28bf3e40afeb9336018e52c04 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 13:53:18 +0000 Subject: [PATCH 029/101] Update Dockerfile --- services/forge/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index dd69f92..5c32b72 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -25,7 +25,7 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential && \ + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential libgoogle-perftools-dev && \ apt-get clean ARG PUID=0 From b336cbc064db31d169ae790e16ee48487c86a7a0 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:20:43 +0000 Subject: [PATCH 030/101] Update Dockerfile no root changes --- services/comfy/Dockerfile | 44 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 2de504d..47b24c9 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -2,10 +2,50 @@ FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -RUN apt-get update && apt-get install -y git && apt-get clean +RUN apt-get update && apt-get install -y git libgoogle-perftools-dev && apt-get clean + +ARG PUID=0 +ARG PGID=0 +ARG USER_HOME=/root +# set build args as container environment variables for entrypoint reference +ENV PUID=$PUID +ENV PGID=$PGID +ENV USER_HOME=$USER_HOME + +# if user home does not exist, create it +RUN mkdir -p "$USER_HOME" + +# home already exists, chown it +RUN chown -R "${PUID}:${PGID}" "$USER_HOME" + +# Only groupadd if we're non root +RUN if [ "$PGID" -ne "0" ]; then \ + echo non root group detected; \ + groupadd \ + --gid "$PGID" \ + stablediffusion ;\ + else \ + echo "root group detected" ; \ + fi + +# Only useradd if we're non root +RUN if [ "$PUID" -ne "0" ]; then \ + echo non root user detected; \ + useradd \ + --gid="$PGID" \ + --no-user-group \ + -M \ + --home "$USER_HOME" \ + stablediffusion ; \ + else \ + echo "root group detected" ; \ + fi + +RUN chown -R "$PUID:$PGID" /stable-diffusion +USER $PUID:$PGID ENV ROOT=/stable-diffusion -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ git clone https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ cd ${ROOT} && \ git checkout master && \ From 40e1e818beba5edcf8452f972a8a865ff5876245 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:22:09 +0000 Subject: [PATCH 031/101] Update entrypoint.sh no_root --- services/comfy/entrypoint.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index b4299a7..b94ac10 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -6,7 +6,7 @@ mkdir -vp /data/config/comfy/custom_nodes declare -A MOUNTS -MOUNTS["/root/.cache"]="/data/.cache" +MOUNTS["${USER_HOME}/.cache"]="/data/.cache" MOUNTS["${ROOT}/input"]="/data/config/comfy/input" MOUNTS["${ROOT}/output"]="/output/comfy" @@ -28,4 +28,9 @@ if [ -f "/data/config/comfy/startup.sh" ]; then popd fi +chown -R root ~/.cache/ +chmod 766 ~/.cache/ +chown -R $PUID:$PGID ~/.cache/ +chmod 776 ~/.cache/ + exec "$@" From 8c3649469b5f5000be49b0a3774f6d5eb4c8efaf Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:27:18 +0000 Subject: [PATCH 032/101] Update Dockerfile no_root --- services/fooocus/Dockerfile | 52 ++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile index 1892f6b..35ad916 100644 --- a/services/fooocus/Dockerfile +++ b/services/fooocus/Dockerfile @@ -6,17 +6,57 @@ FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -RUN apt-get update && apt-get install -y git && apt-get clean +RUN apt-get update && apt-get install -y git libglib2.0-0 libgl1-mesa-glx python-dev libgoogle-perftools-dev && apt-get clean + +ARG PUID=0 +ARG PGID=0 +ARG USER_HOME=/root +# set build args as container environment variables for entrypoint reference +ENV PUID=$PUID +ENV PGID=$PGID +ENV USER_HOME=$USER_HOME + +# if user home does not exist, create it +RUN mkdir -p "$USER_HOME" + +# home already exists, chown it +RUN chown -R "${PUID}:${PGID}" "$USER_HOME" + +# Only groupadd if we're non root +RUN if [ "$PGID" -ne "0" ]; then \ + echo non root group detected; \ + groupadd \ + --gid "$PGID" \ + stablediffusion ;\ + else \ + echo "root group detected" ; \ + fi + +# Only useradd if we're non root +RUN if [ "$PUID" -ne "0" ]; then \ + echo non root user detected; \ + useradd \ + --gid="$PGID" \ + --no-user-group \ + -M \ + --home "$USER_HOME" \ + stablediffusion ; \ + else \ + echo "root group detected" ; \ + fi + -# add in required packages -RUN apt-get install 'libglib2.0-0' -y -RUN apt-get install 'libgl1-mesa-glx' -y -RUN apt-get install 'python-dev' -y # set this to your target branch commit ARG BRANCH=main SHA=e2f9bcb11d06216d6800676c48d8d74d6fd77a4b ENV ROOT=/stable-diffusion + +RUN chown -R "$PUID:$PGID" /stable-diffusion-webui + +# drop permissions (if build targets non root) +USER $PUID:$PGID + RUN --mount=type=cache,target=/root/.cache/pip \ git clone https://github.com/lllyasviel/Fooocus.git ${ROOT} && \ cd ${ROOT} && \ @@ -38,7 +78,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ pip install -r requirements_versions.txt # add info -COPY . /docker/ +COPY --chown=$PUID:$PGID . /docker RUN cp /docker/config.txt ${ROOT} RUN chmod u+x /docker/entrypoint.sh From d5af00119af1250890d231597e4e7e71bab4ae3a Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:29:31 +0000 Subject: [PATCH 033/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 90d3cd1..b1b9f84 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -65,7 +65,7 @@ RUN if [ "$PUID" -ne "0" ]; then \ fi WORKDIR / -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ cd stable-diffusion-webui && \ git reset --hard v1.10.1 && \ @@ -82,7 +82,7 @@ ENV ROOT=/stable-diffusion-webui COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ pip install pyngrok xformers==0.0.26.post1 \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ @@ -90,11 +90,10 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc # maybe move this up to the dependencies list. -RUN apt-get -y install libgoogle-perftools-dev && apt-get clean ENV LD_PRELOAD=libtcmalloc.so COPY . /docker - +COPY --chown=$PUID:$PGID . /docker RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ From 1e34142322003ab0e4f443f9a169aae0346ba77c Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:34:20 +0000 Subject: [PATCH 034/101] Update Dockerfile no root --- services/forge/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 5c32b72..a0c676d 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -67,7 +67,7 @@ RUN if [ "$PUID" -ne "0" ]; then \ WORKDIR / -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git && \ cd stable-diffusion-webui-forge && \ sed -i '/torch/d' requirements_versions.txt && \ @@ -90,17 +90,17 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # cp -r /tmp/huggingface_guess/huggingface_guess ${ROOT}/huggingface_guess # Ensure torchvision is correctly installed -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ pip install torchvision==0.18.1 -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ pip install pyngrok xformers==0.0.27 pytorch_lightning torchdiffeq torchsde \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ git+https://github.com/mlfoundations/open_clip.git@v2.20.0 # there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc # maybe move this up to the dependencies list. -RUN apt-get -y install libgoogle-perftools-dev && apt-get clean + ENV LD_PRELOAD=libtcmalloc.so COPY . /docker From d2ec770e8b459ecb62acac55610aea942bb98cc4 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:36:59 +0000 Subject: [PATCH 035/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index b1b9f84..8f6b91d 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -92,7 +92,6 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ # maybe move this up to the dependencies list. ENV LD_PRELOAD=libtcmalloc.so -COPY . /docker COPY --chown=$PUID:$PGID . /docker RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ From 7e35f1384675e1b254c979398341b3236b377a0d Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:37:41 +0000 Subject: [PATCH 036/101] Update Dockerfile --- services/comfy/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 47b24c9..ec63220 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -53,7 +53,7 @@ RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ pip install -r requirements.txt WORKDIR ${ROOT} -COPY . /docker/ +COPY --chown=$PUID:$PGID . /docker RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" From 04a09cb31c823a5c1e361df4e1e218b732eb689f Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:38:28 +0000 Subject: [PATCH 037/101] Update entrypoint.sh --- services/comfy/entrypoint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index b94ac10..f10eb66 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -28,8 +28,6 @@ if [ -f "/data/config/comfy/startup.sh" ]; then popd fi -chown -R root ~/.cache/ -chmod 766 ~/.cache/ chown -R $PUID:$PGID ~/.cache/ chmod 776 ~/.cache/ From 658ac3337180986c600952b4f04e972087cf196c Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:39:20 +0000 Subject: [PATCH 038/101] Update Dockerfile --- services/forge/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index a0c676d..3256e9c 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -103,7 +103,7 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ ENV LD_PRELOAD=libtcmalloc.so -COPY . /docker +COPY --chown=$PUID:$PGID . /docker RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ From 8efc56d3ad8b149ca82ef9db3f2731e3a1cf4f0e Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:44:58 +0000 Subject: [PATCH 039/101] Update Dockerfile --- services/forge/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 3256e9c..c3e6f4a 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -82,7 +82,7 @@ ENV ROOT=/stable-diffusion-webui-forge COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt # Clone and copy huggingface_guess module From 4bd3e0bed28bc27ed1d3f2427e6fa9a66479023c Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:48:31 +0000 Subject: [PATCH 040/101] Update Dockerfile --- services/fooocus/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile index 35ad916..890292b 100644 --- a/services/fooocus/Dockerfile +++ b/services/fooocus/Dockerfile @@ -57,7 +57,7 @@ RUN chown -R "$PUID:$PGID" /stable-diffusion-webui # drop permissions (if build targets non root) USER $PUID:$PGID -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ git clone https://github.com/lllyasviel/Fooocus.git ${ROOT} && \ cd ${ROOT} && \ git checkout ${BRANCH} && \ @@ -65,13 +65,13 @@ RUN --mount=type=cache,target=/root/.cache/pip \ pip install -r requirements_versions.txt -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ --mount=type=bind,from=xformers,source=/wheel.whl,target=/xformers-0.0.21-cp310-cp310-linux_x86_64.whl \ pip install /xformers-0.0.21-cp310-cp310-linux_x86_64.whl WORKDIR ${ROOT} -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ git fetch && \ git checkout ${BRANCH} && \ git reset --hard ${SHA} && \ From 07fc05329676ae5e1ace7f755a73c77e135f5380 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:50:08 +0000 Subject: [PATCH 041/101] Update Dockerfile --- services/download/Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/download/Dockerfile b/services/download/Dockerfile index a95ad03..78c11ee 100644 --- a/services/download/Dockerfile +++ b/services/download/Dockerfile @@ -1,6 +1,12 @@ FROM bash:alpine3.19 +ARG PUID=0 +ARG PGID=0 +# set build args as container environment variables for entrypoint reference +ENV PUID=$PUID +ENV PGID=$PGID + RUN apk update && apk add parallel aria2 -COPY . /docker +COPY --chown=$PUID:$PGID . /docker RUN chmod +x /docker/download.sh ENTRYPOINT ["/docker/download.sh"] From 6030daac7a2259f07310c14da2fae3111d51b21f Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:53:41 +0000 Subject: [PATCH 042/101] Update docker-compose.yml remove outdated invoke --- docker-compose.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 995427e..46c17b0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,20 +42,7 @@ services: deploy: {} environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api - invoke: &invoke - <<: *base_service - profiles: ["invoke"] - build: ./services/invoke/ - image: sd-invoke:30 - environment: - - PRELOAD=true - - CLI_ARGS=--xformers - # invoke-cpu: - # <<: *invoke - # profiles: ["invoke-cpu"] - # environment: - # - PRELOAD=true - # - CLI_ARGS=--always_use_cpu + comfy: &comfy <<: *base_service profiles: ["comfy"] @@ -63,6 +50,7 @@ services: image: sd-comfy:6 environment: - CLI_ARGS= + comfy-cpu: <<: *comfy profiles: ["comfy-cpu"] @@ -76,4 +64,4 @@ services: build: ./services/fooocus/ image: sd-fooocus:3 environment: - - CLI_ARGS= \ No newline at end of file + - CLI_ARGS= From 7a1a86e168094eeea9c8df74a8b097df11289a1e Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:11:07 +0000 Subject: [PATCH 043/101] Update Dockerfile fix chmod and make consistent --- services/AUTOMATIC1111/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 8f6b91d..f14f93f 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -65,8 +65,10 @@ RUN if [ "$PUID" -ne "0" ]; then \ fi WORKDIR / +ENV ROOT=/stable-diffusion-webui + RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ - git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ + git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ${ROOT} && \ cd stable-diffusion-webui && \ git reset --hard v1.10.1 && \ pip install -r requirements_versions.txt @@ -77,7 +79,7 @@ RUN chown -R "$PUID:$PGID" /stable-diffusion-webui # drop permissions (if build targets non root) USER $PUID:$PGID -ENV ROOT=/stable-diffusion-webui + COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate From 48955a1a98a2f867a88bcaf8cd777bf1282f93e0 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:12:25 +0000 Subject: [PATCH 044/101] Update Dockerfile fix chmod --- services/comfy/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index ec63220..3984675 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -41,7 +41,6 @@ RUN if [ "$PUID" -ne "0" ]; then \ echo "root group detected" ; \ fi -RUN chown -R "$PUID:$PGID" /stable-diffusion USER $PUID:$PGID ENV ROOT=/stable-diffusion @@ -52,6 +51,8 @@ RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \ pip install -r requirements.txt +RUN chown -R "$PUID:$PGID" "${ROOT}" + WORKDIR ${ROOT} COPY --chown=$PUID:$PGID . /docker RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml ${ROOT} From 317055ffa0b2be21369c7f611d90ae69c931fd9d Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:12:46 +0000 Subject: [PATCH 045/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index f14f93f..b0b0792 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -75,7 +75,7 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ RUN pip install --upgrade typing-extensions -RUN chown -R "$PUID:$PGID" /stable-diffusion-webui +RUN chown -R "$PUID:$PGID" "${ROOT}" # drop permissions (if build targets non root) USER $PUID:$PGID From 7606b126100006f3d0ccf27120055e1d4766c2d8 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:13:23 +0000 Subject: [PATCH 046/101] Update Dockerfile --- services/fooocus/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile index 890292b..c3a77fb 100644 --- a/services/fooocus/Dockerfile +++ b/services/fooocus/Dockerfile @@ -45,14 +45,12 @@ RUN if [ "$PUID" -ne "0" ]; then \ echo "root group detected" ; \ fi - - # set this to your target branch commit ARG BRANCH=main SHA=e2f9bcb11d06216d6800676c48d8d74d6fd77a4b ENV ROOT=/stable-diffusion -RUN chown -R "$PUID:$PGID" /stable-diffusion-webui +RUN chown -R "$PUID:$PGID" "${ROOT}" # drop permissions (if build targets non root) USER $PUID:$PGID From 0f94b77773f93c65e2e8b19643a581dfb9f95e8f Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:14:20 +0000 Subject: [PATCH 047/101] Update Dockerfile --- services/forge/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index c3e6f4a..2134893 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -65,6 +65,7 @@ RUN if [ "$PUID" -ne "0" ]; then \ echo "root group detected" ; \ fi +ENV ROOT=/stable-diffusion-webui-forge WORKDIR / RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ @@ -73,12 +74,11 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt -RUN chown -R "$PUID:$PGID" /stable-diffusion-webui-forge +RUN chown -R "$PUID:$PGID" "${ROOT}" # drop permissions (if build targets non root) USER $PUID:$PGID -ENV ROOT=/stable-diffusion-webui-forge COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate From afcef580cc97c6113ff1eca3b1b0ad2c85e6596f Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:15:04 +0000 Subject: [PATCH 048/101] Update docker.yml add additional interfaces --- .github/workflows/docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index db5d840..1790590 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,6 +16,8 @@ jobs: - auto - comfy - download + - fooocus + - forge runs-on: ubuntu-latest name: ${{ matrix.profile }} steps: From 3e25d0a77c17e4e2e89d9612726233aad9c63427 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:19:25 +0000 Subject: [PATCH 049/101] Update Dockerfile fix chown --- services/fooocus/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/fooocus/Dockerfile b/services/fooocus/Dockerfile index c3a77fb..08b9b5f 100644 --- a/services/fooocus/Dockerfile +++ b/services/fooocus/Dockerfile @@ -50,7 +50,6 @@ ARG BRANCH=main SHA=e2f9bcb11d06216d6800676c48d8d74d6fd77a4b ENV ROOT=/stable-diffusion -RUN chown -R "$PUID:$PGID" "${ROOT}" # drop permissions (if build targets non root) USER $PUID:$PGID @@ -62,6 +61,7 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ git reset --hard ${SHA} && \ pip install -r requirements_versions.txt +RUN chown -R "$PUID:$PGID" "${ROOT}" RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ --mount=type=bind,from=xformers,source=/wheel.whl,target=/xformers-0.0.21-cp310-cp310-linux_x86_64.whl \ From f4d803ac8ff4ecc7bb812a99175c0c8ed899a30a Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:32:39 +0000 Subject: [PATCH 050/101] Update docker.yml try building images --- .github/workflows/docker.yml | 60 +++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1790590..9f67e40 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,14 +12,58 @@ jobs: build: strategy: matrix: - profile: - - auto - - comfy - - download - - fooocus - - forge + include: + - image: simonmcnair/AUTOMATIC1111 + dockerfile: services/AUTOMATIC1111/Dockerfile + context: services/AUTOMATIC1111/ + + - image: simonmcnair/comfy + dockerfile: services/comfy/Dockerfile + context: services/comfy/ + + - image: simonmcnair/download + dockerfile: services/download/Dockerfile + context: services/download/ + + - image: simonmcnair/fooocus + dockerfile: services/fooocus/Dockerfile + context: services/fooocus/ + + - image: simonmcnair/forge + dockerfile: services/forge/Dockerfile + context: services/forge/ + runs-on: ubuntu-latest name: ${{ matrix.profile }} steps: - - uses: actions/checkout@v3 - - run: docker compose --profile ${{ matrix.profile }} build --progress plain + # - uses: actions/checkout@v3 + # - run: docker compose --profile ${{ matrix.profile }} build --progress plain + + - name: Checkout + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ matrix.image }} + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: ${{ matrix.context }} + file: ${{ matrix.dockerfile }} + push: true + #This is needed because it is called main instead of master to get the latest tag in docker + tags: | + # set latest tag for default branch + type=raw,value=latest,enable={{is_default_branch}} + #tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 85ffaee78c0fdf7fdf631021feb0847efba4baef Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:34:48 +0000 Subject: [PATCH 051/101] Update docker.yml --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9f67e40..7315f94 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -48,8 +48,8 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v1 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 From 5b8136312713b0c33faddfda4027f13c548a860f Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:37:28 +0000 Subject: [PATCH 052/101] Update docker.yml --- .github/workflows/docker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7315f94..665c9c0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -62,8 +62,8 @@ jobs: file: ${{ matrix.dockerfile }} push: true #This is needed because it is called main instead of master to get the latest tag in docker - tags: | + # tags: | # set latest tag for default branch - type=raw,value=latest,enable={{is_default_branch}} - #tags: ${{ steps.meta.outputs.tags }} + # type=raw,value=latest,enable={{is_default_branch}} + tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 8f74cec7f91914e91ff9a42976531cef878b8664 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 22:18:55 +0000 Subject: [PATCH 053/101] Update Dockerfile sed needs root for the dir it's in --- services/forge/Dockerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 2134893..d9464f4 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -76,6 +76,12 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ RUN chown -R "$PUID:$PGID" "${ROOT}" +RUN \ + # mv ${ROOT}/style.css ${ROOT}/user.css && \ + # one of the ugliest hacks I ever wrote \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + git config --global --add safe.directory '*' + # drop permissions (if build targets non root) USER $PUID:$PGID @@ -105,11 +111,6 @@ ENV LD_PRELOAD=libtcmalloc.so COPY --chown=$PUID:$PGID . /docker -RUN \ - # mv ${ROOT}/style.css ${ROOT}/user.css && \ - # one of the ugliest hacks I ever wrote \ - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ - git config --global --add safe.directory '*' WORKDIR ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all From c5c5b2b6f028105a5e75a6ee31f735c5c1f71fe1 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 22:19:20 +0000 Subject: [PATCH 054/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index b0b0792..72e6a20 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -77,6 +77,13 @@ RUN pip install --upgrade typing-extensions RUN chown -R "$PUID:$PGID" "${ROOT}" +RUN \ + # mv ${ROOT}/style.css ${ROOT}/user.css && \ + # one of the ugliest hacks I ever wrote \ + # updated from 3.10.to 3.11 + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py && \ + git config --global --add safe.directory '*' + # drop permissions (if build targets non root) USER $PUID:$PGID @@ -95,12 +102,6 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ ENV LD_PRELOAD=libtcmalloc.so COPY --chown=$PUID:$PGID . /docker -RUN \ - # mv ${ROOT}/style.css ${ROOT}/user.css && \ - # one of the ugliest hacks I ever wrote \ - # updated from 3.10.to 3.11 - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py && \ - git config --global --add safe.directory '*' WORKDIR ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all From bfd834d8be4b43a77d5518ed2d59e7898135edc1 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 23:19:46 +0000 Subject: [PATCH 055/101] Update Dockerfile testing --- services/AUTOMATIC1111/Dockerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 72e6a20..8cafbd2 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -67,7 +67,7 @@ RUN if [ "$PUID" -ne "0" ]; then \ WORKDIR / ENV ROOT=/stable-diffusion-webui -RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ +RUN --mount=type=cache,target=/root/.cache/sd \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ${ROOT} && \ cd stable-diffusion-webui && \ git reset --hard v1.10.1 && \ @@ -75,7 +75,6 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ RUN pip install --upgrade typing-extensions -RUN chown -R "$PUID:$PGID" "${ROOT}" RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ @@ -85,13 +84,13 @@ RUN \ git config --global --add safe.directory '*' # drop permissions (if build targets non root) -USER $PUID:$PGID +#USER $PUID:$PGID COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate -RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ +RUN --mount=type=cache,target=/root/.cache/repos \ pip install pyngrok xformers==0.0.26.post1 \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ @@ -101,7 +100,9 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ # maybe move this up to the dependencies list. ENV LD_PRELOAD=libtcmalloc.so -COPY --chown=$PUID:$PGID . /docker +COPY . /docker +RUN chown -R "$PUID:$PGID" "${ROOT}" +RUN chown -R "$PUID:$PGID" /docker WORKDIR ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all From 56564585a134fdc7b2b26921f25f31d18f8bcf9d Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 23:22:40 +0000 Subject: [PATCH 056/101] Update Dockerfile test --- services/forge/Dockerfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index d9464f4..038b2f7 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -20,7 +20,7 @@ FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -RUN --mount=type=cache,target=/var/cache/apt \ +RUN --mount=type=cache,target=/root/apt \ apt-get update && \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ @@ -68,13 +68,12 @@ RUN if [ "$PUID" -ne "0" ]; then \ ENV ROOT=/stable-diffusion-webui-forge WORKDIR / -RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ +RUN --mount=type=cache,target=/root/.cache/forge-repo \ git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git && \ cd stable-diffusion-webui-forge && \ sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt -RUN chown -R "$PUID:$PGID" "${ROOT}" RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ @@ -88,18 +87,16 @@ USER $PUID:$PGID COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate -RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ - pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt +RUN --mount=type=cache,target=/root/.cache/codeformer pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt # Clone and copy huggingface_guess module #RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingface_guess && \ # cp -r /tmp/huggingface_guess/huggingface_guess ${ROOT}/huggingface_guess # Ensure torchvision is correctly installed -RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ - pip install torchvision==0.18.1 +RUN --mount=type=cache,target=/root/.cache/torch pip install torchvision==0.18.1 -RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ +RUN --mount=type=cache,target=/root/.cache/repos \ pip install pyngrok xformers==0.0.27 pytorch_lightning torchdiffeq torchsde \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ @@ -109,7 +106,10 @@ RUN --mount=type=cache,target=${USER_HOME}/.cache/pip \ ENV LD_PRELOAD=libtcmalloc.so -COPY --chown=$PUID:$PGID . /docker +COPY . /docker + +RUN chown -R "$PUID:$PGID" "${ROOT}" +RUN chown -R "$PUID:$PGID" /docker WORKDIR ${ROOT} From 039559e348e69272aa8d6ae485889df019325ab3 Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 19:07:45 +0000 Subject: [PATCH 057/101] add reforge --- .../tmp_dockerfile => reforge/Dockerfile} | 35 ++++++-- services/reforge/clone.sh | 11 +++ services/reforge/config.py | 78 +++++++++++++++++ services/reforge/entrypoint.sh | 85 +++++++++++++++++++ 4 files changed, 201 insertions(+), 8 deletions(-) rename services/{forge/tmp_dockerfile => reforge/Dockerfile} (55%) create mode 100644 services/reforge/clone.sh create mode 100644 services/reforge/config.py create mode 100755 services/reforge/entrypoint.sh diff --git a/services/forge/tmp_dockerfile b/services/reforge/Dockerfile similarity index 55% rename from services/forge/tmp_dockerfile rename to services/reforge/Dockerfile index 301d025..86f58e9 100644 --- a/services/forge/tmp_dockerfile +++ b/services/reforge/Dockerfile @@ -1,3 +1,20 @@ +FROM alpine/git:2.36.2 AS download + +COPY clone.sh /clone.sh + +RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ + && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif + +RUN . /clone.sh CodeFormer https://github.com/sczhou/CodeFormer.git c5b4593074ba6214284d6acd5f1719b6c5d739af \ + && rm -rf assets inputs + +RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9 +RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c +RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 +RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f +RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917 + + FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -9,13 +26,15 @@ RUN --mount=type=cache,target=/var/cache/apt \ # extensions needs those ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + WORKDIR / RUN --mount=type=cache,target=/root/.cache/pip \ - git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git && \ - cd stable-diffusion-webui-forge && \ + git clone https://github.com/Panchovix/stable-diffusion-webui-reForge.git /stable-diffusion-webui-reforge && \ + cd stable-diffusion-webui-reforge && \ + sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt -ENV ROOT=/stable-diffusion-webui-forge +ENV ROOT=/stable-diffusion-webui-reforge COPY --from=download /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate @@ -28,14 +47,13 @@ RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingfa # Ensure torchvision is correctly installed RUN --mount=type=cache,target=/root/.cache/pip \ - pip install --upgrade torchvision + pip install torchvision==0.18.1 RUN --mount=type=cache,target=/root/.cache/pip \ - pip install pyngrok xformers==0.0.23.post1 \ + pip install pyngrok xformers==0.0.27 pytorch_lightning torchdiffeq torchsde \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ - git+https://github.com/mlfoundations/open_clip.git@v2.20.0 - + git+https://github.com/mlfoundations/open_clip.git@v2.20.0 # there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc # maybe move this up to the dependencies list. RUN apt-get -y install libgoogle-perftools-dev && apt-get clean @@ -44,11 +62,12 @@ ENV LD_PRELOAD=libtcmalloc.so COPY . /docker RUN \ + # mv ${ROOT}/style.css ${ROOT}/user.css && \ + # one of the ugliest hacks I ever wrote \ sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ git config --global --add safe.directory '*' WORKDIR ${ROOT} -ENV PYTHONPATH=${ROOT}:${PYTHONPATH} ENV NVIDIA_VISIBLE_DEVICES=all ENV CLI_ARGS="" EXPOSE 7860 diff --git a/services/reforge/clone.sh b/services/reforge/clone.sh new file mode 100644 index 0000000..2c37c41 --- /dev/null +++ b/services/reforge/clone.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -Eeuox pipefail + +mkdir -p /repositories/"$1" +cd /repositories/"$1" +git init +git remote add origin "$2" +git fetch origin "$3" --depth=1 +git reset --hard "$3" +rm -rf .git \ No newline at end of file diff --git a/services/reforge/config.py b/services/reforge/config.py new file mode 100644 index 0000000..7db2f54 --- /dev/null +++ b/services/reforge/config.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +"""Checks and sets default values for config.json before starting the container.""" + +import json +import re +import os.path +import sys + +DEFAULT_FILEPATH = '/data/config/reforge/config.json' + +DEFAULT_OUTDIRS = { + "outdir_samples": "", + "outdir_txt2img_samples": "/output/txt2img", + "outdir_img2img_samples": "/output/img2img", + "outdir_extras_samples": "/output/extras", + "outdir_grids": "", + "outdir_txt2img_grids": "/output/txt2img-grids", + "outdir_img2img_grids": "/output/img2img-grids", + "outdir_save": "/output/saved", + "outdir_init_images": "/output/init-images", +} +RE_VALID_OUTDIR = re.compile(r"(^/output(/\.?[\w\-\_]+)+/?$)|(^\s?$)") + +DEFAULT_OTHER = { + "font": "DejaVuSans.ttf", +} + +def dict_to_json_file(target_file: str, data: dict): + """Write dictionary to specified json file""" + + with open(target_file, 'w') as f: + json.dump(data, f) + +def json_file_to_dict(config_file: str) -> dict|None: + """Load json file into a dictionary. Return None if file does not exist.""" + + if os.path.isfile(config_file): + with open(config_file, 'r') as f: + return json.load(f) + else: + return None + +def replace_if_invalid(value: str, replacement: str, pattern: str|re.Pattern[str]) -> str: + """Returns original value if valid, fallback value if invalid""" + + if re.match(pattern, value): + return value + else: + return replacement + +def check_and_replace_config(config_file: str, target_file: str = None): + """Checks given file for invalid values. Replaces those with fallback values (default: overwrites file).""" + + # Get current user config, or empty if file does not exists + data = json_file_to_dict(config_file) or {} + + # Check and fix output directories + for k, def_val in DEFAULT_OUTDIRS.items(): + if k not in data: + data[k] = def_val + else: + data[k] = replace_if_invalid(value=data[k], replacement=def_val, pattern=RE_VALID_OUTDIR) + + # Check and fix other default settings + for k, def_val in DEFAULT_OTHER.items(): + if k not in data: + data[k] = def_val + + # Write results to file + dict_to_json_file(target_file or config_file, data) + +if __name__ == '__main__': + if len(sys.argv) > 1: + check_and_replace_config(*sys.argv[1:]) + else: + check_and_replace_config(DEFAULT_FILEPATH) + diff --git a/services/reforge/entrypoint.sh b/services/reforge/entrypoint.sh new file mode 100755 index 0000000..1ef5400 --- /dev/null +++ b/services/reforge/entrypoint.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +set -Eeuo pipefail + +# TODO: move all mkdir -p ? +mkdir -p /data/config/reforge/scripts/ +# mount scripts individually + +echo $ROOT +ls -lha $ROOT + +find "${ROOT}/scripts/" -maxdepth 1 -type l -delete +cp -vrfTs /data/config/reforge/scripts/ "${ROOT}/scripts/" + +# Set up config file +python /docker/config.py /data/config/reforge/config.json + +if [ ! -f /data/config/reforge/ui-config.json ]; then + echo '{}' >/data/config/reforge/ui-config.json +fi + +if [ ! -f /data/config/reforge/styles.csv ]; then + touch /data/config/reforge/styles.csv +fi + +# copy models from original models folder +mkdir -p /data/models/VAE-approx/ /data/models/karlo/ + +rsync -a --info=NAME ${ROOT}/models/VAE-approx/ /data/models/VAE-approx/ +rsync -a --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ + +declare -A MOUNTS + +MOUNTS["/root/.cache"]="/data/.cache" +MOUNTS["${ROOT}/models"]="/data/models" + +MOUNTS["${ROOT}/embeddings"]="/data/embeddings" +MOUNTS["${ROOT}/config.json"]="/data/config/reforge/config.json" +MOUNTS["${ROOT}/ui-config.json"]="/data/config/reforge/ui-config.json" +MOUNTS["${ROOT}/styles.csv"]="/data/config/reforge/styles.csv" +MOUNTS["${ROOT}/extensions"]="/data/config/reforge/extensions" +MOUNTS["${ROOT}/config_states"]="/data/config/reforge/config_states" + +# extra hacks +MOUNTS["${ROOT}/repositories/CodeFormer/weights/facelib"]="/data/.cache" + +for to_path in "${!MOUNTS[@]}"; do + set -Eeuo pipefail + from_path="${MOUNTS[${to_path}]}" + rm -rf "${to_path}" + if [ ! -f "$from_path" ]; then + mkdir -vp "$from_path" + fi + mkdir -vp "$(dirname "${to_path}")" + ln -sT "${from_path}" "${to_path}" + echo Mounted $(basename "${from_path}") +done + +echo "Installing extension dependencies (if any)" + +# because we build our container as root: +chown -R root ~/.cache/ +chmod 766 ~/.cache/ + +shopt -s nullglob +# For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy +list=(./extensions/*/install.py) +for installscript in "${list[@]}"; do + EXTNAME=$(echo $installscript | cut -d '/' -f 3) + # Skip installing dependencies if extension is disabled in config + if $(jq -e ".disabled_extensions|any(. == \"$EXTNAME\")" config.json); then + echo "Skipping disabled extension ($EXTNAME)" + continue + fi + PYTHONPATH=${ROOT} python "$installscript" +done + +if [ -f "/data/config/reforge/startup.sh" ]; then + pushd ${ROOT} + echo "Running startup script" + . /data/config/reforge/startup.sh + popd +fi + +exec "$@" From b5ebd4c70948a73d91fa4b530e94bb5b654eb5e1 Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 19:09:13 +0000 Subject: [PATCH 058/101] add reforge --- docker-compose.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 46c17b0..3b0b257 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,15 @@ services: environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api - forge: &forge + forge: &reforge + <<: *base_service + profiles: ["reforge"] + build: ./services/reforge + image: sd-reforge:80 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + + reforge: &forge <<: *base_service profiles: ["forge"] build: ./services/forge From d32b186968098527ad8f81b3facbd6e48e04d6df Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 19:19:00 +0000 Subject: [PATCH 059/101] Update docker-compose.yml fix --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3b0b257..f48837c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api - forge: &reforge + reforge: &reforge <<: *base_service profiles: ["reforge"] build: ./services/reforge @@ -36,7 +36,7 @@ services: environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream - reforge: &forge + forge: &forge <<: *base_service profiles: ["forge"] build: ./services/forge From bd2fcce6b4bba4c718c371c1af369cdde85f2808 Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 19:24:09 +0000 Subject: [PATCH 060/101] try and fix error --- services/reforge/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/reforge/Dockerfile b/services/reforge/Dockerfile index 86f58e9..30332ce 100644 --- a/services/reforge/Dockerfile +++ b/services/reforge/Dockerfile @@ -47,10 +47,10 @@ RUN git clone https://github.com/lllyasviel/huggingface_guess.git /tmp/huggingfa # Ensure torchvision is correctly installed RUN --mount=type=cache,target=/root/.cache/pip \ - pip install torchvision==0.18.1 + pip install torchvision==0.18.1 RUN --mount=type=cache,target=/root/.cache/pip \ - pip install pyngrok xformers==0.0.27 pytorch_lightning torchdiffeq torchsde \ + pip install pyngrok xformers==0.0.27 pytorch_lightning==1.6.5 torchdiffeq torchsde \ git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ git+https://github.com/mlfoundations/open_clip.git@v2.20.0 From db36a12d00f45173387818dde6dbfffc65d33414 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 19:45:49 +0000 Subject: [PATCH 061/101] Update Dockerfile try and fix pydantic error --- services/reforge/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/reforge/Dockerfile b/services/reforge/Dockerfile index 30332ce..e9845cf 100644 --- a/services/reforge/Dockerfile +++ b/services/reforge/Dockerfile @@ -60,6 +60,7 @@ RUN apt-get -y install libgoogle-perftools-dev && apt-get clean ENV LD_PRELOAD=libtcmalloc.so COPY . /docker +RUN pip install --upgrade pydantic RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ @@ -72,4 +73,4 @@ ENV NVIDIA_VISIBLE_DEVICES=all ENV CLI_ARGS="" EXPOSE 7860 ENTRYPOINT ["/docker/entrypoint.sh"] -CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} \ No newline at end of file +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} From d92e9ab826e7581faea7b48e3b5a7f8388ff1252 Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:27:56 +0000 Subject: [PATCH 062/101] set pydantic --- services/reforge/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/reforge/Dockerfile b/services/reforge/Dockerfile index e9845cf..f66d547 100644 --- a/services/reforge/Dockerfile +++ b/services/reforge/Dockerfile @@ -60,7 +60,7 @@ RUN apt-get -y install libgoogle-perftools-dev && apt-get clean ENV LD_PRELOAD=libtcmalloc.so COPY . /docker -RUN pip install --upgrade pydantic +RUN pip install pydantic ==1.10.21 RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ From 0cf468b80b6974ab9caee4cde2fdec209d34b64c Mon Sep 17 00:00:00 2001 From: Simon McNair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:29:51 +0000 Subject: [PATCH 063/101] oops --- services/reforge/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/reforge/Dockerfile b/services/reforge/Dockerfile index f66d547..d52c0c9 100644 --- a/services/reforge/Dockerfile +++ b/services/reforge/Dockerfile @@ -60,7 +60,7 @@ RUN apt-get -y install libgoogle-perftools-dev && apt-get clean ENV LD_PRELOAD=libtcmalloc.so COPY . /docker -RUN pip install pydantic ==1.10.21 +RUN pip install pydantic==1.10.21 RUN \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ From 9a73fad1142afe733b72541589f170362bee0871 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:51:12 +0000 Subject: [PATCH 064/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 8cafbd2..785f2b5 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -2,6 +2,9 @@ FROM alpine/git:2.36.2 AS download COPY clone.sh /clone.sh +RUN rm -rf "/usr/local/share/boost" +RUN rm -rf "$AGENT_TOOLSDIRECTORY" + RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917 RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ From 53153c6f3265cedd223e057c8d9ea5d74bd3443f Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:17:01 +0000 Subject: [PATCH 065/101] Update Dockerfile trying something --- services/AUTOMATIC1111/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 785f2b5..a0ccd12 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -73,8 +73,8 @@ ENV ROOT=/stable-diffusion-webui RUN --mount=type=cache,target=/root/.cache/sd \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ${ROOT} && \ cd stable-diffusion-webui && \ - git reset --hard v1.10.1 && \ - pip install -r requirements_versions.txt + git reset --hard v1.10.1 # && \ + #pip install -r requirements_versions.txt RUN pip install --upgrade typing-extensions From 8fe07a18e3241fe99eb07efcb3c69fe687786b04 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:22:13 +0000 Subject: [PATCH 066/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index a0ccd12..1674103 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -17,8 +17,8 @@ RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-mod RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 -#FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime -FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime +FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +#FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -74,7 +74,7 @@ RUN --mount=type=cache,target=/root/.cache/sd \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ${ROOT} && \ cd stable-diffusion-webui && \ git reset --hard v1.10.1 # && \ - #pip install -r requirements_versions.txt + pip install -r requirements_versions.txt RUN pip install --upgrade typing-extensions From c417634e1f282fe72e8c8e28d8d8b6e8e312e6ef Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:26:20 +0000 Subject: [PATCH 067/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 1674103..a4269dd 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -73,7 +73,7 @@ ENV ROOT=/stable-diffusion-webui RUN --mount=type=cache,target=/root/.cache/sd \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ${ROOT} && \ cd stable-diffusion-webui && \ - git reset --hard v1.10.1 # && \ + git reset --hard v1.10.1 && \ pip install -r requirements_versions.txt RUN pip install --upgrade typing-extensions From fe62a0ff0beba3123e16a8e045d3b47fb434ac0a Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:51:14 +0000 Subject: [PATCH 068/101] Update Dockerfile try a fix --- services/AUTOMATIC1111/Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index a4269dd..cc38822 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -79,11 +79,14 @@ RUN --mount=type=cache,target=/root/.cache/sd \ RUN pip install --upgrade typing-extensions -RUN \ +RUN if [ -d "/opt/conda/lib/python3.10" ]; then \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py ;\ + elif [ -d "/opt/conda/lib/python3.11" ]; then \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py ;\ + fi && \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ # updated from 3.10.to 3.11 - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py && \ git config --global --add safe.directory '*' # drop permissions (if build targets non root) From a740f9da6d6ac1a83669a8f4b6ec19d842cfea46 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:03:43 +0000 Subject: [PATCH 069/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index cc38822..87d2fb6 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -80,8 +80,10 @@ RUN pip install --upgrade typing-extensions RUN if [ -d "/opt/conda/lib/python3.10" ]; then \ + echo Python 3.10 detected; \ sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py ;\ elif [ -d "/opt/conda/lib/python3.11" ]; then \ + echo Python 3.11 detected; \ sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py ;\ fi && \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ From 9a36d6bf354508560fb350b09252b304933bd6ef Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:05:33 +0000 Subject: [PATCH 070/101] Update Dockerfile --- services/forge/Dockerfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/forge/Dockerfile b/services/forge/Dockerfile index 038b2f7..2f20389 100644 --- a/services/forge/Dockerfile +++ b/services/forge/Dockerfile @@ -74,13 +74,20 @@ RUN --mount=type=cache,target=/root/.cache/forge-repo \ sed -i '/torch/d' requirements_versions.txt && \ pip install -r requirements_versions.txt - -RUN \ +RUN if [ -d "/opt/conda/lib/python3.10" ]; then \ + echo Python 3.10 detected; \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py ;\ + elif [ -d "/opt/conda/lib/python3.11" ]; then \ + echo Python 3.11 detected; \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py ;\ + fi && \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + # updated from 3.10.to 3.11 git config --global --add safe.directory '*' + + # drop permissions (if build targets non root) USER $PUID:$PGID From 3db97c9c173cecb3f51a0ccd375767df024ccf28 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:05:54 +0000 Subject: [PATCH 071/101] Update Dockerfile --- services/reforge/Dockerfile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/reforge/Dockerfile b/services/reforge/Dockerfile index d52c0c9..1e625db 100644 --- a/services/reforge/Dockerfile +++ b/services/reforge/Dockerfile @@ -62,12 +62,20 @@ ENV LD_PRELOAD=libtcmalloc.so COPY . /docker RUN pip install pydantic==1.10.21 -RUN \ +RUN if [ -d "/opt/conda/lib/python3.10" ]; then \ + echo Python 3.10 detected; \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py ;\ + elif [ -d "/opt/conda/lib/python3.11" ]; then \ + echo Python 3.11 detected; \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py ;\ + fi && \ # mv ${ROOT}/style.css ${ROOT}/user.css && \ # one of the ugliest hacks I ever wrote \ - sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ + # updated from 3.10.to 3.11 git config --global --add safe.directory '*' + + WORKDIR ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all ENV CLI_ARGS="" From 9a9111d6400555233409a701b194cb5597a996ca Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:07:36 +0000 Subject: [PATCH 072/101] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 01872d9..c973e68 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ I have forked this as AbdBarho hasn't been around for a while. I'm not great wi I am happy to look at PR's as and when. Also happy to pass this back, as and whe, and if, they return. +supports: +- AUTOMATIC1111 +- comfy +- fooocus +- forge +- reforge # Stable Diffusion WebUI Docker From 894b87722b118c01ddc4743cfc35b79feacee40a Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:17:55 +0100 Subject: [PATCH 073/101] Update Dockerfile update Pytorch and add comfy manager --- services/comfy/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 3984675..5a6203f 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,4 +1,4 @@ -FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -51,6 +51,9 @@ RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \ pip install -r requirements.txt +RUN git clone -b 3.6.5 --depth=1 https://github.com/ltdrdata/ComfyUI-Manager ${ROOT}/custom_nodes/comfyui-manager && \ + pip install -r ${ROOT}/custom_nodes/comfyui-manager/requirements.txt + RUN chown -R "$PUID:$PGID" "${ROOT}" WORKDIR ${ROOT} From d6d46fc92d70a1bfd5426107f6079c556eb95cb5 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:19:19 +0100 Subject: [PATCH 074/101] Update Dockerfile change comfy to 3.10 --- services/comfy/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 5a6203f..eb1a9e9 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -45,7 +45,7 @@ USER $PUID:$PGID ENV ROOT=/stable-diffusion RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ - git clone https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ + git clone -b v0.3.10 --depth=1 https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ cd ${ROOT} && \ git checkout master && \ git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \ From f3df34b7ca245834a2396a6e795caafb4206edb7 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:20:41 +0100 Subject: [PATCH 075/101] Update docker-compose.yml add AMD rocm --- docker-compose.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index f48837c..b58b9c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,19 @@ services: environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api + auto-rocm: + <<: *base_service + profiles: ["auto-rocm"] + build: + context: ./services/AUTOMATIC1111 + dockerfile: Dockerfile.rocm + devices: + - "/dev/kfd" + - "/dev/dri" + deploy: {} + environment: + - CLI_ARGS=--allow-code --medvram --enable-insecure-extension-access --api + reforge: &reforge <<: *base_service profiles: ["reforge"] From 8b6b82ebc06f11f6d861a693d5a005643afe316d Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:22:04 +0100 Subject: [PATCH 076/101] Create Dockerfile.rocm first try --- services/AUTOMATIC1111/Dockerfile.rocm | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 services/AUTOMATIC1111/Dockerfile.rocm diff --git a/services/AUTOMATIC1111/Dockerfile.rocm b/services/AUTOMATIC1111/Dockerfile.rocm new file mode 100644 index 0000000..47a39c0 --- /dev/null +++ b/services/AUTOMATIC1111/Dockerfile.rocm @@ -0,0 +1,70 @@ +FROM alpine/git:2.36.2 as download + +COPY clone.sh /clone.sh + + +RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ + && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif + +RUN . /clone.sh CodeFormer https://github.com/sczhou/CodeFormer.git c5b4593074ba6214284d6acd5f1719b6c5d739af \ + && rm -rf assets inputs + +RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9 +RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c +RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 +RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f + + +FROM rocm/pytorch:rocm6.0.2_ubuntu22.04_py3.10_pytorch_2.1.2 + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && \ + # we need those + apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ + # extensions needs those + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + + +RUN python -m pip install --upgrade pip wheel + +WORKDIR / +RUN --mount=type=cache,target=/root/.cache/pip \ + git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ + cd stable-diffusion-webui && \ + git reset --hard cf2772fab0af5573da775e7437e6acdca424f26e && \ + pip install -r requirements_versions.txt + + +ENV ROOT=/stable-diffusion-webui + +COPY --from=download /repositories/ ${ROOT}/repositories/ +RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt + +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install pyngrok xformers==0.0.23.post1 \ + git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ + git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ + git+https://github.com/mlfoundations/open_clip.git@v2.20.0 + +# there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc +# maybe move this up to the dependencies list. +RUN apt-get -y install libgoogle-perftools-dev && apt-get clean +ENV LD_PRELOAD=libtcmalloc.so + +COPY . /docker + +RUN \ + # mv ${ROOT}/style.css ${ROOT}/user.css && \ + # one of the ugliest hacks I ever wrote \ + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/envs/py_3.10/lib/python3.10/site-packages/gradio/routes.py && \ + git config --global --add safe.directory '*' + +WORKDIR ${ROOT} +ENV CLI_ARGS="" +EXPOSE 7860 +ENTRYPOINT ["/docker/entrypoint.sh"] +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} From c40d41563d3c4c328ec26e23f572324c0c728ba4 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:35:06 +0100 Subject: [PATCH 077/101] Update Dockerfile Fix for build --- services/comfy/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index eb1a9e9..ded3cb6 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -45,10 +45,8 @@ USER $PUID:$PGID ENV ROOT=/stable-diffusion RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ - git clone -b v0.3.10 --depth=1 https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ cd ${ROOT} && \ - git checkout master && \ - git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \ + git clone -b v0.3.10 --depth=1 https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ pip install -r requirements.txt RUN git clone -b 3.6.5 --depth=1 https://github.com/ltdrdata/ComfyUI-Manager ${ROOT}/custom_nodes/comfyui-manager && \ From f1eed95e2588fa4b143ee19840ad1b15b56580e6 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:56:09 +0100 Subject: [PATCH 078/101] Update Dockerfile fix for failed build --- services/comfy/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index ded3cb6..325e166 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -45,9 +45,8 @@ USER $PUID:$PGID ENV ROOT=/stable-diffusion RUN --mount=type=cache,target="$USER_HOME"/.cache/pip \ - cd ${ROOT} && \ git clone -b v0.3.10 --depth=1 https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ - pip install -r requirements.txt + pip install -r ${ROOT}/requirements.txt RUN git clone -b 3.6.5 --depth=1 https://github.com/ltdrdata/ComfyUI-Manager ${ROOT}/custom_nodes/comfyui-manager && \ pip install -r ${ROOT}/custom_nodes/comfyui-manager/requirements.txt From 17f1c0ca11162fc5e967b4030619802061cdba43 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:13:31 +0100 Subject: [PATCH 079/101] Create Docker-compose-build.yml this compose is to complete a local build --- Docker-compose-build.yml | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Docker-compose-build.yml diff --git a/Docker-compose-build.yml b/Docker-compose-build.yml new file mode 100644 index 0000000..b58b9c7 --- /dev/null +++ b/Docker-compose-build.yml @@ -0,0 +1,88 @@ +x-base_service: &base_service + ports: + - "${WEBUI_PORT:-7860}:7860" + volumes: + - &v1 ./data:/data + - &v2 ./output:/output + stop_signal: SIGKILL + tty: true + deploy: + resources: + reservations: + devices: + - driver: nvidia + device_ids: ['0'] + capabilities: [compute, utility] +name: webui-docker +services: + download: + build: ./services/download/ + profiles: ["download"] + volumes: + - *v1 + auto: &automatic + <<: *base_service + profiles: ["auto"] + build: ./services/AUTOMATIC1111 + image: sd-auto:80 + environment: + - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api + + auto-rocm: + <<: *base_service + profiles: ["auto-rocm"] + build: + context: ./services/AUTOMATIC1111 + dockerfile: Dockerfile.rocm + devices: + - "/dev/kfd" + - "/dev/dri" + deploy: {} + environment: + - CLI_ARGS=--allow-code --medvram --enable-insecure-extension-access --api + + reforge: &reforge + <<: *base_service + profiles: ["reforge"] + build: ./services/reforge + image: sd-reforge:80 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + + forge: &forge + <<: *base_service + profiles: ["forge"] + build: ./services/forge + image: sd-forge:80 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + + auto-cpu: + <<: *automatic + profiles: ["auto-cpu"] + deploy: {} + environment: + - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api + + comfy: &comfy + <<: *base_service + profiles: ["comfy"] + build: ./services/comfy/ + image: sd-comfy:6 + environment: + - CLI_ARGS= + + comfy-cpu: + <<: *comfy + profiles: ["comfy-cpu"] + deploy: {} + environment: + - CLI_ARGS=--cpu + + fooocus: &fooocus + <<: *base_service + profiles: ["fooocus"] + build: ./services/fooocus/ + image: sd-fooocus:3 + environment: + - CLI_ARGS= From c0e97d1913989b350715ca956e224a33971784ec Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:17:04 +0100 Subject: [PATCH 080/101] Update docker-compose.yml try using images rather than building. Should be quicker. --- docker-compose.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b58b9c7..098f7fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,8 +23,7 @@ services: auto: &automatic <<: *base_service profiles: ["auto"] - build: ./services/AUTOMATIC1111 - image: sd-auto:80 + image: simonmcnair/automatic1111:master environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api @@ -44,16 +43,14 @@ services: reforge: &reforge <<: *base_service profiles: ["reforge"] - build: ./services/reforge - image: sd-reforge:80 + image: simonmcnair/reforge:master environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream forge: &forge <<: *base_service profiles: ["forge"] - build: ./services/forge - image: sd-forge:80 + image: simonmcnair/forge:master environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream @@ -67,8 +64,7 @@ services: comfy: &comfy <<: *base_service profiles: ["comfy"] - build: ./services/comfy/ - image: sd-comfy:6 + image: simonmcnair/comfy:master environment: - CLI_ARGS= @@ -82,7 +78,6 @@ services: fooocus: &fooocus <<: *base_service profiles: ["fooocus"] - build: ./services/fooocus/ - image: sd-fooocus:3 + image: simonmcnair/fooocus:master environment: - CLI_ARGS= From 45dd1ddbab5b3e5bab581e4eea7d884d4c38a5e3 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:19:31 +0100 Subject: [PATCH 081/101] Update docker.yml add rocm and reforge --- .github/workflows/docker.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 665c9c0..a7c9f23 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -17,6 +17,10 @@ jobs: dockerfile: services/AUTOMATIC1111/Dockerfile context: services/AUTOMATIC1111/ + - image: simonmcnair/AUTOMATIC1111-rocm + dockerfile: services/AUTOMATIC1111/Dockerfile.rocm + context: services/AUTOMATIC1111/ + - image: simonmcnair/comfy dockerfile: services/comfy/Dockerfile context: services/comfy/ @@ -33,6 +37,10 @@ jobs: dockerfile: services/forge/Dockerfile context: services/forge/ + - image: simonmcnair/reforge + dockerfile: services/reforge/Dockerfile + context: services/reforge/ + runs-on: ubuntu-latest name: ${{ matrix.profile }} steps: From 72ffe451745ea2240dcd599712f4c90549aeb3a0 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:22:24 +0100 Subject: [PATCH 082/101] Update docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 098f7fd..6dda583 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ x-base_service: &base_service name: webui-docker services: download: - build: ./services/download/ + image: simonmcnair/download:master profiles: ["download"] volumes: - *v1 From 70858ae56fffe4a334bc3d39fa9a1f1119c34ddb Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:23:57 +0100 Subject: [PATCH 083/101] Update docker-compose.yml --- docker-compose.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6dda583..b86c2e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,9 +30,7 @@ services: auto-rocm: <<: *base_service profiles: ["auto-rocm"] - build: - context: ./services/AUTOMATIC1111 - dockerfile: Dockerfile.rocm + image: simonmcnair/automatic1111-rocm:master devices: - "/dev/kfd" - "/dev/dri" From 657ad995365ca39666368566e3bcd7fe1858a173 Mon Sep 17 00:00:00 2001 From: ExtraTNT <56388556+ExtraTNT@users.noreply.github.com> Date: Thu, 10 Apr 2025 08:44:54 +0200 Subject: [PATCH 084/101] fix docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b86c2e3..4acdfaa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api - auto-rocm: + auto-rocm: <<: *base_service profiles: ["auto-rocm"] image: simonmcnair/automatic1111-rocm:master From b959dcf21bf3f04081cf5f59eecb44d44e6715bd Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 5 May 2025 09:58:02 +0100 Subject: [PATCH 085/101] Update Dockerfile --- services/comfy/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 325e166..839ba93 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -60,4 +60,6 @@ RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" EXPOSE 7860 ENTRYPOINT ["/docker/entrypoint.sh"] -CMD python -u main.py --listen --port 7860 ${CLI_ARGS} +#CMD python -u main.py --listen --port 7860 ${CLI_ARGS} +CMD sh -c "python3 -c 'import os; print(f\"Running as UID={os.getuid()}, GID={os.getgid()}\")' && python -u main.py --listen --port 7860 ${CLI_ARGS}" + From eed0ad0738230bac20ecac2c087059206d488af8 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 5 May 2025 10:02:02 +0100 Subject: [PATCH 086/101] Update entrypoint.sh --- services/comfy/entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index f10eb66..3818002 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -28,6 +28,11 @@ if [ -f "/data/config/comfy/startup.sh" ]; then popd fi +# Only chown if not running as root (UID != 0) +if [ "$(id -u)" -ne 0 ]; then + chown -R "$(id -u):$(id -g)" ~ 2>/dev/null || true +fi + chown -R $PUID:$PGID ~/.cache/ chmod 776 ~/.cache/ From 6615a2cd3709b4ea64e3ad63ccd1272c50bbf0b5 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 7 May 2025 22:46:51 +0100 Subject: [PATCH 087/101] Update Docker-compose-build.yml oops --- Docker-compose-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docker-compose-build.yml b/Docker-compose-build.yml index b58b9c7..83073ea 100644 --- a/Docker-compose-build.yml +++ b/Docker-compose-build.yml @@ -28,7 +28,7 @@ services: environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api - auto-rocm: + auto-rocm: <<: *base_service profiles: ["auto-rocm"] build: From d5fe95f9a6815aeead87a417fe21ae1f9a57c7fe Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 7 May 2025 22:48:50 +0100 Subject: [PATCH 088/101] Update Dockerfile.rocm --- services/AUTOMATIC1111/Dockerfile.rocm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/AUTOMATIC1111/Dockerfile.rocm b/services/AUTOMATIC1111/Dockerfile.rocm index 47a39c0..4014980 100644 --- a/services/AUTOMATIC1111/Dockerfile.rocm +++ b/services/AUTOMATIC1111/Dockerfile.rocm @@ -2,6 +2,8 @@ FROM alpine/git:2.36.2 as download COPY clone.sh /clone.sh +RUN rm -rf "/usr/local/share/boost" +RUN rm -rf "$AGENT_TOOLSDIRECTORY" RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif From e30123a8937cf389203eee0d925cce71ba7601e9 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 7 May 2025 22:50:09 +0100 Subject: [PATCH 089/101] Update Dockerfile.rocm --- services/AUTOMATIC1111/Dockerfile.rocm | 1 + 1 file changed, 1 insertion(+) diff --git a/services/AUTOMATIC1111/Dockerfile.rocm b/services/AUTOMATIC1111/Dockerfile.rocm index 4014980..eab7fc1 100644 --- a/services/AUTOMATIC1111/Dockerfile.rocm +++ b/services/AUTOMATIC1111/Dockerfile.rocm @@ -15,6 +15,7 @@ RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f1 RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f +RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 FROM rocm/pytorch:rocm6.0.2_ubuntu22.04_py3.10_pytorch_2.1.2 From a024ec1cbc7c167e70d4ac05fdfd3b5d989016a0 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 7 May 2025 22:51:09 +0100 Subject: [PATCH 090/101] Update Dockerfile.rocm --- services/AUTOMATIC1111/Dockerfile.rocm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/AUTOMATIC1111/Dockerfile.rocm b/services/AUTOMATIC1111/Dockerfile.rocm index eab7fc1..b463fa2 100644 --- a/services/AUTOMATIC1111/Dockerfile.rocm +++ b/services/AUTOMATIC1111/Dockerfile.rocm @@ -27,7 +27,8 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential libgoogle-perftools-dev && \ + apt-get clean RUN python -m pip install --upgrade pip wheel From 18ad18cd2a462a85b3d4604c5881e09e4dc6f203 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Wed, 7 May 2025 22:53:46 +0100 Subject: [PATCH 091/101] Update Dockerfile --- services/AUTOMATIC1111/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 87d2fb6..d558c5d 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -5,8 +5,6 @@ COPY clone.sh /clone.sh RUN rm -rf "/usr/local/share/boost" RUN rm -rf "$AGENT_TOOLSDIRECTORY" -RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917 - RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif From d72392cd38f8c58674fabeba633f53db0f483307 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Thu, 8 May 2025 08:23:13 +0100 Subject: [PATCH 092/101] Update docker.yml see if this makes the build work --- .github/workflows/docker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a7c9f23..5c06abb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -17,9 +17,9 @@ jobs: dockerfile: services/AUTOMATIC1111/Dockerfile context: services/AUTOMATIC1111/ - - image: simonmcnair/AUTOMATIC1111-rocm - dockerfile: services/AUTOMATIC1111/Dockerfile.rocm - context: services/AUTOMATIC1111/ + # - image: simonmcnair/AUTOMATIC1111-rocm + # dockerfile: services/AUTOMATIC1111/Dockerfile.rocm + # context: services/AUTOMATIC1111/ - image: simonmcnair/comfy dockerfile: services/comfy/Dockerfile From ab47d2c699e759045f3e0ae194288afca97c5985 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Mon, 7 Jul 2025 07:58:25 +0200 Subject: [PATCH 093/101] Update --- .dockerignore | 11 ++++ .gitignore | 2 + data/.gitignore | 1 + docker-compose.yml | 36 +++++++++-- docs/FAQ.md | 72 +++++++++++++++++++++ docs/Home.md | 1 + docs/Podman-Support.md | 25 ++++++++ docs/Screenshots.md | 11 ++++ docs/Setup.md | 51 +++++++++++++++ docs/Usage.md | 73 +++++++++++++++++++++ services/AUTOMATIC1111/Dockerfile | 17 +++-- services/AUTOMATIC1111/entrypoint.sh | 3 +- services/comfy/Dockerfile | 75 ++++++++++++++++++---- services/comfy/entrypoint.sh | 92 +++++++++++++++++++-------- services/comfy/extra_model_paths.yaml | 30 +++++---- 15 files changed, 435 insertions(+), 65 deletions(-) create mode 100644 .dockerignore create mode 100644 docs/FAQ.md create mode 100644 docs/Home.md create mode 100644 docs/Podman-Support.md create mode 100644 docs/Screenshots.md create mode 100644 docs/Setup.md create mode 100644 docs/Usage.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..aab110a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.devscripts +.github +.vscode +.idea +.editorconfig +.gitattributes +.gitignore +*.md +docs +data +output diff --git a/.gitignore b/.gitignore index 2a011a1..9d34c3f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ # VSCode specific *.code-workspace /.vscode +.idea +TODO.md diff --git a/data/.gitignore b/data/.gitignore index 946349a..f20063c 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -2,3 +2,4 @@ /config /embeddings /models +/states diff --git a/docker-compose.yml b/docker-compose.yml index 970b612..5d94433 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,4 @@ x-base_service: &base_service - ports: - - "${WEBUI_PORT:-7860}:7860" volumes: - &v1 ./data:/data - &v2 ./output:/output @@ -8,11 +6,16 @@ x-base_service: &base_service tty: true deploy: resources: +# limits: +# cpus: 8 +# memory: 48G reservations: +# cpus: 4 +# memory: 24G devices: - driver: nvidia device_ids: ['0'] - capabilities: [compute, utility] + capabilities: [compute, utility, gpu] name: webui-docker @@ -28,6 +31,8 @@ services: profiles: ["auto"] build: ./services/AUTOMATIC1111 image: sd-auto:78 + ports: + - "${WEBUI_PORT:-7860}:7860" environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api @@ -35,6 +40,8 @@ services: <<: *automatic profiles: ["auto-cpu"] deploy: {} + ports: + - "${WEBUI_PORT:-7860}:7860" environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api @@ -43,13 +50,34 @@ services: profiles: ["comfy"] build: ./services/comfy/ image: sd-comfy:7 + volumes: + - ./data/models:/opt/comfyui/models + - ./data/config/comfy/custom_nodes:/opt/comfyui/custom_nodes + - ./output/comfy:/opt/comfyui/output + - ./data/models/configs:/opt/comfyui/user/default/ + ports: + - "${COMFYUI_PORT:-7861}:7861" environment: + - COMFYUI_PATH=/opt/comfyui + - COMFYUI_MODEL_PATH=/opt/comfyui/models - CLI_ARGS= - +# - TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1 comfy-cpu: <<: *comfy profiles: ["comfy-cpu"] deploy: {} + ports: + - "${COMFYUI_PORT:-7861}:7861" environment: - CLI_ARGS=--cpu + + auto-full: + <<: *base_service + profiles: [ "full" ] + build: ./services/AUTOMATIC1111 + image: sd-auto:78 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api + ports: + - "${WEBUI_PORT:-7860}:7860" diff --git a/docs/FAQ.md b/docs/FAQ.md new file mode 100644 index 0000000..841b36c --- /dev/null +++ b/docs/FAQ.md @@ -0,0 +1,72 @@ +# General + +Unfortunately, AMD GPUs [#63](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/63) and MacOs [#35](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/35) are not supported, contributions to add support are very welcome. + +## `auto` exists with error code 137 + +This is an indicator that the container does not have enough RAM, you need at least 12GB, recommended 16GB. + +You might need to [adjust the size of the docker virtual machine RAM](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/296#issuecomment-1480318829) depending on your OS. + +## Dockerfile parse error +``` +Error response from daemon: dockerfile parse error line 33: unknown instruction: GIT +ERROR: Service 'model' failed to build : Build failed +``` +Update docker to the latest version, and make sure you are using `docker compose` instead of `docker-compose`. [#16](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/16), also, try setting the environment variable `DOCKER_BUILDKIT=1` + +## Unknown Flag `--profile` + +Update docker to the latest version, and see [this comment](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/165#issuecomment-1296155667), try setting the environment variable mentioned in the previous point. + +## Output is a always green image +use `--precision full --no-half`. [#9](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/9) + + +## Found no NVIDIA driver on your system even though the drivers are installed and `nvidia-smi` shows it + +add `NVIDIA_DRIVER_CAPABILITIES=compute,utility` and `NVIDIA_VISIBLE_DEVICES=all` to container can resolve this problem [#348](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/348#issuecomment-1449250332) + + +--- + +# Linux + +### Error response from daemon: could not select device driver "nvidia" with capabilities: `[[gpu]]` + +Install [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) and restart the docker service [#81](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/81) + + +### `docker compose --profile auto up --build` fails with `OSError` + +This might be related to the `overlay2` storage driver used by docker overlayed on zfs, change to the `zfs` storage driver [#433](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/433#issuecomment-1694520689) + +--- + +# Windows / WSL + + +## Build fails at [The Shell command](https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/5af482ed8c975df6aa0210225ad68b218d4f61da/build/Dockerfile#L11), `/bin/bash` not found in WSL. + +Edit the corresponding docker file, and change the SHELL from `/bin/bash` to `//bin/bash` [#21](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/21), note: this is a hack and something in your wsl is messed up. + + +## Build fails with credentials errors when logged in via SSH on WSL2/Windows +You can try forcing plain text auth creds storage by removing line with "credStore" from ~/.docker/config.json (in WSL). [#56](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/56) + +## `unable to access 'https://github.com/...': Could not resolve host: github.com` or any domain +Set the `build/network` of the service you are starting to `host` [#114](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/114#issue-1393683083) + +## Other build errors on windows +* Make sure: + * Windows 10 release >= 2021H2 (required for WSL to see the GPU) + * WSL2 (check with `wsl -l -v`) + * Latest Docker Desktop +* You might need to create a [`.wslconfig`](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#example-wslconfig-file) and increase memory, if you have 16GB RAM, set the limit to something around 12GB, [#34](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/34) [#64](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/64) +* You might also need to [force wsl to allow file permissions](https://superuser.com/a/1646556) + +--- + +# AWS + +You have to use one of AWS's GPU-enabled VMs and their Deep Learning OS images. These have the right divers, the toolkit and all the rest already installed and optimized. [#70](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/70) diff --git a/docs/Home.md b/docs/Home.md new file mode 100644 index 0000000..0122e41 --- /dev/null +++ b/docs/Home.md @@ -0,0 +1 @@ +Welcome to the stable-diffusion-webui-docker wiki! diff --git a/docs/Podman-Support.md b/docs/Podman-Support.md new file mode 100644 index 0000000..a28fb38 --- /dev/null +++ b/docs/Podman-Support.md @@ -0,0 +1,25 @@ +Thanks to [RedTopper](https://github.com/RedTopper) for this guide! [#352](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/352) + + +On an selinux machine like Fedora, append `:z` to the volume mounts. This tells selinux that the files are shared between containers (required for download and your UI of choice to access the same files). *Properly merging :z with an override will work in podman compose 1.0.7, specifically commit https://github.com/containers/podman-compose/commit/0b853f29f44b846bee749e7ae9a5b42679f2649f* + +```yaml +x-base_service: &base_service + volumes: + - &v1 ./data:/data:z + - &v2 ./output:/output:z +``` + +You'll also need to add the runtime and security opts to allow access to your GPU. This can be specified in an override, no new versions required! More information can be found at this RedHat post: [How to enable NVIDIA GPUs in containers](https://www.redhat.com/en/blog/how-use-gpus-containers-bare-metal-rhel-8). + +```yaml +x-base_service: &base_service + ... + runtime: nvidia + security_opt: + - label=type:nvidia_container_t +``` + +I also had to add `,Z` to the pip/apt caches for them to work. On the first build everything will be fine without the fix, but on the second+ build, you may get a "file not found" when pip goes to install a package from the cache. Here's a script to do this easily, along with more info: https://github.com/RedTopper/Stable-Diffusion-Webui-Podman/blob/podman/selinux-cache.sh. + +Lastly, delete all the services you don't want to use. *Using `--profile` will work in podman compose 1.0.7, specifically commit https://github.com/containers/podman-compose/commit/8d8df0bc2816d8e8fa142781d9018a06fe0d08ed* \ No newline at end of file diff --git a/docs/Screenshots.md b/docs/Screenshots.md new file mode 100644 index 0000000..638b2e5 --- /dev/null +++ b/docs/Screenshots.md @@ -0,0 +1,11 @@ +# AUTOMATIC1111 + +| Text to image | Image to image | Extras | +| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | +| ![](https://user-images.githubusercontent.com/24505302/189541954-46afd772-d0c8-4005-874c-e2eca40c02f2.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541956-5b528de7-1b5d-479f-a1db-d3f5a53afc59.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541957-cf78b352-a071-486d-8889-f26952779a61.jpg) | + +# lstein (invokeAI) + +| Text to image | Image to image | Extras | +| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | +| ![](https://user-images.githubusercontent.com/24505302/195158552-39f58cb6-cfcc-4141-9995-a626e3760752.jpg) | ![](https://user-images.githubusercontent.com/24505302/195158553-152a0ab8-c0fd-4087-b121-4823bcd8d6b5.jpg) | ![](https://user-images.githubusercontent.com/24505302/195158548-e118206e-c519-4915-85d6-4c248eb10fc0.jpg) | diff --git a/docs/Setup.md b/docs/Setup.md new file mode 100644 index 0000000..303f80c --- /dev/null +++ b/docs/Setup.md @@ -0,0 +1,51 @@ +# Make sure you have the *latest* version of docker and docker compose installed + +TLDR: + +clone this repo and run: +```bash +docker compose --profile download up --build +# wait until its done, then: +docker compose --profile [ui] up --build +# where [ui] is one of: auto | auto-cpu | comfy | comfy-cpu +``` +if you don't know which ui to choose, `auto` is good start. + +Then access from http://localhost:7860/ + +Unfortunately, AMD GPUs [#63](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/63) and Mac [#35](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/35) are not supported, contributions to add support are very welcome!!!!!!!!!! + + +If you face any problems, check the [FAQ page](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/FAQ), or [create a new issue](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues). + +### Detailed Steps + +First of all, clone this repo, you can do this with `git`, or you can download a zip file. Please always use the most up-to-date state from the `master` branch. Even though we have releases, everything is changing and breaking all the time. + + +After cloning, open a terminal in the folder and run: + +``` +docker compose --profile download up --build +``` +This will download all of the required models / files, and validate their integrity. You only have to download the data once (regardless of the UI). There are roughly 12GB of data to be downloaded. + +Next, choose which UI you want to run (you can easily change later): +- `auto`: The most popular fork, many features with neat UI, [Repo by AUTOMATIC1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) +- `auto-cpu`: for users without a GPU. +- `comfy`: A graph based workflow UI, very powerful, [Repo by comfyanonymous](https://github.com/comfyanonymous/ComfyUI) + + +After the download is done, you can run the UI using: +```bash +docker compose --profile [ui] up --build +# for example: +# docker compose --profile invoke up --build +# or +# docker compose --profile auto up --build +``` + +Will start the app on http://localhost:7860/. Feel free to try out the different UIs. + + +Note: the first start will take some time since other models will be downloaded, these will be cached in the `data` folder, so next runs are faster. First time setup might take between 15 minutes and 1 hour depending on your internet connection, other times are much faster, roughly 20 seconds. \ No newline at end of file diff --git a/docs/Usage.md b/docs/Usage.md new file mode 100644 index 0000000..0f013ad --- /dev/null +++ b/docs/Usage.md @@ -0,0 +1,73 @@ +Assuming you [setup everything correctly](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Setup), you can run any UI (interchangeably, but not in parallel) using the command: +```bash +docker compose --profile [ui] up --build +``` +where `[ui]` is one of `auto`, `auto-cpu`, `comfy`, or `comfy-cpu`. + +### Mounts + +The `data` and `output` folders are always mounted into the container as `/data` and `/output`, use them so if you want to transfer anything from / to the container. + +### Updates +if you want to update to the latest version, just pull the changes +```bash +git pull +``` + +You can also checkout specific tags if you want. + +### Customization +If you want to customize the behaviour of the uis, you can create a `docker-compose.override.yml` and override whatever you want from the [main `docker-compose.yml` file](https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/docker-compose.yml). Example: + +```yml +services: + auto: + environment: + - CLI_ARGS=--lowvram +``` + +Possible configuration: + +# `auto` +By default: `--medvram` is given, which allow you to use this model on a 6GB GPU, you can also use `--lowvram` for lower end GPUs. Remove these arguments if you are using a (relatively) high end GPU, like 40XX series cards, as these arguments will slow you down. + +[You can find the full list of cli arguments here.](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/shared.py) + +### Custom models + +Put the weights in the folder `data/StableDiffusion`, you can then change the model from the settings tab. + +### General Config +There is multiple files in `data/config/auto` such as `config.json` and `ui-config.json` which let you which contain additional config for the UI. + +### Scripts +put your scripts `data/config/auto/scripts` and restart the container + +### Extensions + +You can use the UI to install extensions, or, you can put your extensions in `data/config/auto/extensions`. + +Different extensions require additional dependencies. Some of them might conflict with each other and changing versions of packages could break things. This container will try to install missing extension dependencies on startup, but it won't resolve any problems for you. + +There is also the option to create a script `data/config/auto/startup.sh` which will be called on container startup, in case you want to install any additional dependencies for your extensions or anything else. + + +An example of your `startup.sh` might looks like this: +```sh +#!/bin/bash + +# opencv-python-headless to not rely on opengl and drivers. +pip install -q --force-reinstall opencv-python-headless +``` + +NOTE: dependencies of extensions might get lost when you create a new container, hence the installing them in the startup script is important. + +It is not recommended to modify the Dockerfile for the sole purpose of supporting some extension (unless you truly know what you are doing). + +### **DONT OPEN AN ISSUE IF A SCRIPT OR AN EXTENSION IS NOT WORKING** + +I maintain neither the UI nor the extension, I can't help you. + + +# `auto-cpu` +CPU instance of the above, some stuff might not work, use at your own risk. diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index d595784..b8e5751 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine/git:2.36.2 as download +FROM alpine/git:2.36.2 AS download COPY clone.sh /clone.sh @@ -13,8 +13,8 @@ RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interr RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 - FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +#FROM pytorch/pytorch:2.7.1-cuda12.8-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -25,14 +25,12 @@ RUN --mount=type=cache,target=/var/cache/apt \ # extensions needs those ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential - WORKDIR / RUN --mount=type=cache,target=/root/.cache/pip \ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ cd stable-diffusion-webui && \ - git reset --hard v1.9.4 && \ - pip install -r requirements_versions.txt - +# git reset --hard v1.9.4 && \ + pip install -r requirements_versions.txt && pip install --upgrade typing-extensions ENV ROOT=/stable-diffusion-webui @@ -60,7 +58,8 @@ RUN \ WORKDIR ${ROOT} ENV NVIDIA_VISIBLE_DEVICES=all -ENV CLI_ARGS="" -EXPOSE 7860 +ARG CLI_ARGS="" +ENV WEBUI_PORT=7860 +EXPOSE $WEBUI_PORT ENTRYPOINT ["/docker/entrypoint.sh"] -CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} +CMD python -u webui.py --listen --port $WEBUI_PORT ${CLI_ARGS} diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index 35023af..968d52c 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash - +#set -x set -Eeuo pipefail # TODO: move all mkdir -p ? @@ -50,6 +50,7 @@ for to_path in "${!MOUNTS[@]}"; do rm -rf "${to_path}" if [ ! -f "$from_path" ]; then mkdir -vp "$from_path" +# mkdir -vp "$from_path" || true fi mkdir -vp "$(dirname "${to_path}")" ln -sT "${from_path}" "${to_path}" diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 2de504d..4684b5a 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,22 +1,69 @@ -FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime +# Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use +ARG COMFYUI_VERSION=v0.3.43 +ARG COMFYUI_MANAGER_VERSION=3.33.3 +ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime + +# This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch +FROM pytorch/pytorch:${PYTORCH_VERSION} ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -RUN apt-get update && apt-get install -y git && apt-get clean +RUN apt update --assume-yes && \ + apt install --assume-yes \ + git \ + sudo \ + build-essential \ + libgl1-mesa-glx \ + libglib2.0-0 \ + libsm6 \ + libxext6 \ + ffmpeg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* -ENV ROOT=/stable-diffusion -RUN --mount=type=cache,target=/root/.cache/pip \ - git clone https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ - cd ${ROOT} && \ - git checkout master && \ - git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \ - pip install -r requirements.txt +# Clones the ComfyUI repository and checks out the latest release +RUN git clone --depth=1 https://github.com/comfyanonymous/ComfyUI.git /opt/comfyui && \ + cd /opt/comfyui && \ + git fetch origin ${COMFYUI_VERSION} && \ + git checkout FETCH_HEAD -WORKDIR ${ROOT} +# Clones the ComfyUI Manager repository and checks out the latest release; ComfyUI Manager is an extension for ComfyUI that enables users to install +# custom nodes and download models directly from the ComfyUI interface; instead of installing it to "/opt/comfyui/custom_nodes/ComfyUI-Manager", which +# is the directory it is meant to be installed in, it is installed to its own directory; the entrypoint will symlink the directory to the correct +# location upon startup; the reason for this is that the ComfyUI Manager must be installed in the same directory that it installs custom nodes to, but +# this directory is mounted as a volume, so that the custom nodes are not installed inside of the container and are not lost when the container is +# removed; this way, the custom nodes are installed on the host machine +RUN git clone --depth=1 https://github.com/Comfy-Org/ComfyUI-Manager.git /opt/comfyui-manager && \ + cd /opt/comfyui-manager && \ + git fetch origin ${COMFYUI_MANAGER_VERSION} && \ + git checkout FETCH_HEAD + +# Installs the required Python packages for both ComfyUI and the ComfyUI Manager +RUN pip install \ + --requirement /opt/comfyui/requirements.txt \ + --requirement /opt/comfyui-manager/requirements.txt + +RUN pip3 install --no-cache-dir \ + opencv-python \ + diffusers \ + triton \ + sageattention \ + psutil + +# Sets the working directory to the ComfyUI directory +WORKDIR /opt/comfyui COPY . /docker/ -RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml ${ROOT} +RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml /opt/comfyui ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" -EXPOSE 7860 -ENTRYPOINT ["/docker/entrypoint.sh"] -CMD python -u main.py --listen --port 7860 ${CLI_ARGS} +EXPOSE 7861 + +# Adds the startup script to the container; the startup script will create all necessary directories in the models and custom nodes volumes that were +# mounted to the container and symlink the ComfyUI Manager to the correct directory; it will also create a user with the same UID and GID as the user +# that started the container, so that the files created by the container are owned by the user that started the container and not the root user +ENTRYPOINT ["/bin/bash", "/docker/entrypoint.sh"] + +# On startup, ComfyUI is started at its default port; the IP address is changed from localhost to 0.0.0.0, because Docker is only forwarding traffic +# to the IP address it assigns to the container, which is unknown at build time; listening to 0.0.0.0 means that ComfyUI listens to all incoming +# traffic; the auto-launch feature is disabled, because we do not want (nor is it possible) to open a browser window in a Docker container +CMD ["/opt/conda/bin/python", "main.py", "--listen", "0.0.0.0", "--port", "7861", "--disable-auto-launch"] diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index b4299a7..aee8a09 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -1,31 +1,71 @@ #!/bin/bash -set -Eeuo pipefail - -mkdir -vp /data/config/comfy/custom_nodes - -declare -A MOUNTS - -MOUNTS["/root/.cache"]="/data/.cache" -MOUNTS["${ROOT}/input"]="/data/config/comfy/input" -MOUNTS["${ROOT}/output"]="/output/comfy" - -for to_path in "${!MOUNTS[@]}"; do - set -Eeuo pipefail - from_path="${MOUNTS[${to_path}]}" - rm -rf "${to_path}" - if [ ! -f "$from_path" ]; then - mkdir -vp "$from_path" - fi - mkdir -vp "$(dirname "${to_path}")" - ln -sT "${from_path}" "${to_path}" - echo Mounted $(basename "${from_path}") +# Creates the directories for the models inside of the volume that is mounted from the host +echo "Creating directories for models..." +MODEL_DIRECTORIES=( + "checkpoints" + "clip" + "clip_vision" + "configs" + "controlnet" + "diffusers" + "diffusion_models" + "embeddings" + "gligen" + "hypernetworks" + "loras" + "photomaker" + "style_models" + "text_encoders" + "unet" + "upscale_models" + "vae" + "vae_approx" +) +for MODEL_DIRECTORY in ${MODEL_DIRECTORIES[@]}; do + mkdir -p /opt/comfyui/models/$MODEL_DIRECTORY done -if [ -f "/data/config/comfy/startup.sh" ]; then - pushd ${ROOT} - . /data/config/comfy/startup.sh - popd -fi +# Creates the symlink for the ComfyUI Manager to the custom nodes directory, which is also mounted from the host +echo "Creating symlink for ComfyUI Manager..." +rm --force /opt/comfyui/custom_nodes/ComfyUI-Manager +ln -s \ + /opt/comfyui-manager \ + /opt/comfyui/custom_nodes/ComfyUI-Manager -exec "$@" +# The custom nodes that were installed using the ComfyUI Manager may have requirements of their own, which are not installed when the container is +# started for the first time; this loops over all custom nodes and installs the requirements of each custom node +echo "Installing requirements for custom nodes..." +for CUSTOM_NODE_DIRECTORY in /opt/comfyui/custom_nodes/*; +do + if [ "$CUSTOM_NODE_DIRECTORY" != "/opt/comfyui/custom_nodes/ComfyUI-Manager" ]; + then + if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ]; + then + CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/} + CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ } + echo "Installing requirements for $CUSTOM_NODE_NAME..." + pip install --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt" + fi + fi +done + +# Under normal circumstances, the container would be run as the root user, which is not ideal, because the files that are created by the container in +# the volumes mounted from the host, i.e., custom nodes and models downloaded by the ComfyUI Manager, are owned by the root user; the user can specify +# the user ID and group ID of the host user as environment variables when starting the container; if these environment variables are set, a non-root +# user with the specified user ID and group ID is created, and the container is run as this user +if [ -z "$USER_ID" ] || [ -z "$GROUP_ID" ]; +then + echo "Running container as $USER..." + exec "$@" +else + echo "Creating non-root user..." + getent group $GROUP_ID > /dev/null 2>&1 || groupadd --gid $GROUP_ID comfyui-user + id -u $USER_ID > /dev/null 2>&1 || useradd --uid $USER_ID --gid $GROUP_ID --create-home comfyui-user + chown --recursive $USER_ID:$GROUP_ID /opt/comfyui + chown --recursive $USER_ID:$GROUP_ID /opt/comfyui-manager + export PATH=$PATH:/home/comfyui-user/.local/bin + + echo "Running container as $USER..." + sudo --set-home --preserve-env=PATH --user \#$USER_ID "$@" +fi diff --git a/services/comfy/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index eb374eb..4ef41c8 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -1,25 +1,33 @@ a111: - base_path: /data + base_path: /opt/comfyui +# base_path: /data checkpoints: models/Stable-diffusion - configs: models/Stable-diffusion + configs: models/configs vae: models/VAE - loras: models/Lora + loras: | + models/Lora + models/loras + hypernetworks: models/hypernetworks + controlnet: models/controlnet + gligen: models/GLIGEN + clip: models/CLIPEncoder + embeddings: embeddings + + unet: models/unet upscale_models: | models/RealESRGAN models/ESRGAN models/SwinIR models/GFPGAN - hypernetworks: models/hypernetworks - controlnet: models/ControlNet - gligen: models/GLIGEN - clip: models/CLIPEncoder - embeddings: embeddings - - custom_nodes: config/comfy/custom_nodes + models/upscale_models + diffusion_models: models/diffusion_models + text_encoders: models/text_encoders + clip_vision: models/clip_vision + custom_nodes: /opt/comfyui/custom_nodes +# custom_nodes: config/comfy/custom_nodes # TODO: I am unsure about these, need more testing # style_models: config/comfy/style_models # t2i_adapter: config/comfy/t2i_adapter - # clip_vision: config/comfy/clip_vision # diffusers: config/comfy/diffusers From b4941ea474a0817680e4cf7f96b1807dccfe44ff Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Fri, 18 Jul 2025 17:06:53 +0200 Subject: [PATCH 094/101] Upgrade comfyui versions & add convert_2_safetensors service --- data/.gitignore | 1 + docker-compose.yml | 8 + services/comfy/Dockerfile | 4 +- services/convert2safetensors/Dockerfile | 26 +++ .../convert_2_safetensors.py | 160 ++++++++++++++++++ services/convert2safetensors/entrypoint.sh | 6 + services/convert2safetensors/requirements.txt | 5 + 7 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 services/convert2safetensors/Dockerfile create mode 100644 services/convert2safetensors/convert_2_safetensors.py create mode 100644 services/convert2safetensors/entrypoint.sh create mode 100644 services/convert2safetensors/requirements.txt diff --git a/data/.gitignore b/data/.gitignore index f20063c..1241499 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -3,3 +3,4 @@ /embeddings /models /states +/convert diff --git a/docker-compose.yml b/docker-compose.yml index 5d94433..2fc68e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -81,3 +81,11 @@ services: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api ports: - "${WEBUI_PORT:-7860}:7860" + + convertor: + <<: *base_service + profiles: [ "convert" ] + build: ./services/convert2safetensors + image: sd-convert + volumes: + - ./data/convert:/opt/convert2safetensors/models diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 4684b5a..89ce958 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,6 +1,6 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.43 -ARG COMFYUI_MANAGER_VERSION=3.33.3 +ARG COMFYUI_VERSION=v0.3.44 +ARG COMFYUI_MANAGER_VERSION=3.33.8 ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime # This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch diff --git a/services/convert2safetensors/Dockerfile b/services/convert2safetensors/Dockerfile new file mode 100644 index 0000000..d6f144f --- /dev/null +++ b/services/convert2safetensors/Dockerfile @@ -0,0 +1,26 @@ +ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime +FROM pytorch/pytorch:${PYTORCH_VERSION} + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 + +RUN apt update --assume-yes && \ +# apt install --assume-yes \ +# git \ +# sudo \ +# build-essential \ +# libgl1-mesa-glx \ +# libglib2.0-0 \ +# libsm6 \ +# libxext6 \ +# ffmpeg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /opt/convert2safetensors +COPY . /opt/convert2safetensors/ +RUN chmod u+x /opt/convert2safetensors/entrypoint.sh + +RUN pip install --requirement /opt/convert2safetensors/requirements.txt + +ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" +ENTRYPOINT ["/bin/bash", "/opt/convert2safetensors/entrypoint.sh"] diff --git a/services/convert2safetensors/convert_2_safetensors.py b/services/convert2safetensors/convert_2_safetensors.py new file mode 100644 index 0000000..086c9e0 --- /dev/null +++ b/services/convert2safetensors/convert_2_safetensors.py @@ -0,0 +1,160 @@ +import argparse +import json +import os +import shutil +import torch +from collections import defaultdict +from safetensors.torch import load_file, save_file +from tqdm import tqdm + + +def shared_pointers(tensors): + ptrs = defaultdict(list) + for k, v in tensors.items(): + ptrs[v.data_ptr()].append(k) + return [names for names in ptrs.values() if len(names) > 1] + + +def check_file_size(sf_filename, pt_filename): + sf_size = os.stat(sf_filename).st_size + pt_size = os.stat(pt_filename).st_size + if (sf_size - pt_size) / pt_size > 0.01: + raise RuntimeError(f"File size difference exceeds 1% between {sf_filename} and {pt_filename}") + + +def convert_file(pt_filename, sf_filename, copy_add_data=True, allow_pickle=False): + try: + loaded = torch.load(pt_filename, map_location="cpu", weights_only=not allow_pickle) + except Exception as e: + print(f"[WARNING] Failed to load '{pt_filename}': {e}") + return # Skip this file + loaded = loaded.get("state_dict", loaded) + shared = shared_pointers(loaded) + + for shared_weights in shared: + for name in shared_weights[1:]: + loaded.pop(name) + + loaded = {k: v.contiguous().half() for k, v in loaded.items()} + + source_folder = os.path.dirname(pt_filename) + dest_folder = os.path.dirname(sf_filename) + os.makedirs(dest_folder, exist_ok=True) + save_file(loaded, sf_filename, metadata={"format": "pt"}) + check_file_size(sf_filename, pt_filename) + if copy_add_data: + copy_additional_files(source_folder, dest_folder) + + reloaded = load_file(sf_filename) + for k, v in loaded.items(): + if not torch.equal(v, reloaded[k]): + raise RuntimeError(f"Mismatch in tensors for key {k}.") + + +def rename(pt_filename): + filename, ext = os.path.splitext(pt_filename) + local = f"{filename}.safetensors" + local = local.replace("pytorch_model", "model") + return local + + +def copy_additional_files(source_folder, dest_folder): + for file in os.listdir(source_folder): + file_path = os.path.join(source_folder, file) + if os.path.isfile(file_path) and not file.endswith(('.bin', '.py', '.pt', '.pth')): + shutil.copy(file_path, dest_folder) + + +def find_index_file(source_folder): + for file in os.listdir(source_folder): + if file.endswith('.bin.index.json'): + return file + return None + + +def convert_files(source_folder, dest_folder, delete_old, use_dest_folder, allow_pickle): + index_file = find_index_file(source_folder) + if index_file: + index_file = os.path.join(source_folder, index_file) + with open(index_file) as f: + index_data = json.load(f) + for pt_filename in tqdm(set(index_data["weight_map"].values()), desc="Converting files"): + full_pt_filename = os.path.join(source_folder, pt_filename) + sf_filename = os.path.join(dest_folder, rename(pt_filename)) if use_dest_folder else os.path.join( + os.path.dirname(full_pt_filename), rename(pt_filename)) + convert_file(full_pt_filename, sf_filename, copy_add_data=False, allow_pickle=allow_pickle) + if delete_old: + os.remove(full_pt_filename) + index_path = os.path.join(dest_folder, "model.safetensors.index.json") if use_dest_folder else os.path.join( + os.path.dirname(index_file), "model.safetensors.index.json") + with open(index_path, "w") as f: + new_map = {k: rename(v) for k, v in index_data["weight_map"].items()} + json.dump({**index_data, "weight_map": new_map}, f, indent=4) + else: + for pt_filename in tqdm(os.listdir(source_folder), desc="Converting files"): + if pt_filename.endswith(('.bin', '.pt', '.pth')): + full_pt_filename = os.path.join(source_folder, pt_filename) + sf_filename = os.path.join(dest_folder, rename(pt_filename)) if use_dest_folder else os.path.join( + os.path.dirname(full_pt_filename), rename(pt_filename)) + convert_file(full_pt_filename, sf_filename, copy_add_data=False, allow_pickle=allow_pickle) + if delete_old: + os.remove(full_pt_filename) + + copy_additional_files(source_folder, dest_folder) + + +def convert_batch(source_dir, dest_dir, delete_old, use_dest_folder, allow_pickle): + files_to_convert = [] + for root, _, files in os.walk(source_dir): + for file in files: + if file.endswith(('.bin', '.pt', '.pth')): + files_to_convert.append(os.path.join(root, file)) + for full_model_path in tqdm(files_to_convert, desc="Converting batch of models"): + sf_filename = os.path.join(dest_dir, os.path.relpath(rename(full_model_path), + source_dir)) if use_dest_folder else os.path.join( + os.path.dirname(full_model_path), rename(full_model_path)) + os.makedirs(os.path.dirname(sf_filename), exist_ok=True) + convert_file(full_model_path, sf_filename, copy_add_data=False, allow_pickle=allow_pickle) + if delete_old: + os.remove(full_model_path) + + +def main(): + parser = argparse.ArgumentParser(description="Convert PyTorch model files to SafeTensors format.") + parser.add_argument("--source", required=False, default=os.getcwd(), + help="Source folder containing .pth/.pt/.bin files") + parser.add_argument("--dest", required=False, + help="Destination folder for .safetensors files. If not specified, will use default.") + parser.add_argument("--delete-old", action="store_true", + help="Delete original PyTorch files after conversion") + parser.add_argument("--batch", action="store_true", + help="Recursively convert a batch of models from subdirectories") + parser.add_argument("--allow-pickle", action="store_true", + help="Allow loading legacy models with full object deserialization (trusted sources only!)") + + args = parser.parse_args() + + source_folder = os.path.abspath(args.source) + dest_folder = os.path.abspath(args.dest) if args.dest else os.path.join( + source_folder, os.path.basename(source_folder) + "_safetensors") + use_dest_folder = bool(args.dest) + + if args.batch: + convert_batch(source_folder, dest_folder, args.delete_old, use_dest_folder, args.allow_pickle) + else: + if any(fname.endswith(('.bin', '.pt', '.pth')) for fname in os.listdir(source_folder)): + if "pytorch_model.bin" in os.listdir(source_folder): + sf_filename = os.path.join(dest_folder, "model.safetensors") if use_dest_folder else os.path.join( + source_folder, "model.safetensors") + convert_file(os.path.join(source_folder, "pytorch_model.bin"), sf_filename, + copy_add_data=True, allow_pickle=args.allow_pickle) + if args.delete_old: + os.remove(os.path.join(source_folder, "pytorch_model.bin")) + else: + convert_files(source_folder, dest_folder, args.delete_old, use_dest_folder, args.allow_pickle) + else: + raise RuntimeError("No valid model files found in the specified directory.") + + +if __name__ == "__main__": + main() diff --git a/services/convert2safetensors/entrypoint.sh b/services/convert2safetensors/entrypoint.sh new file mode 100644 index 0000000..3500eb5 --- /dev/null +++ b/services/convert2safetensors/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -ex + +echo "Running container as $USER" +echo "Running container as $USER..." +python convert_2_safetensors.py --source ./models/input --dest ./models/output --allow-pickle diff --git a/services/convert2safetensors/requirements.txt b/services/convert2safetensors/requirements.txt new file mode 100644 index 0000000..0ed85e7 --- /dev/null +++ b/services/convert2safetensors/requirements.txt @@ -0,0 +1,5 @@ +safetensors +argparse +torch +tqdm +numpy From 68afd2b96845d54b4cb1d7396e891fc06ccb84d0 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Thu, 31 Jul 2025 02:12:04 +0200 Subject: [PATCH 095/101] Add swarmui --- data/.gitignore | 8 +-- docker-compose.yml | 52 +++++++++++------ services/convert2safetensors/entrypoint.sh | 1 - services/swarmui/Dockerfile | 68 ++++++++++++++++++++++ services/swarmui/entrypoint.sh | 20 +++++++ 5 files changed, 124 insertions(+), 25 deletions(-) create mode 100644 services/swarmui/Dockerfile create mode 100644 services/swarmui/entrypoint.sh diff --git a/data/.gitignore b/data/.gitignore index 1241499..a68d087 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,6 +1,2 @@ -/.cache -/config -/embeddings -/models -/states -/convert +/* +!/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index 2fc68e3..3456818 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,7 @@ x-base_service: &base_service - volumes: - - &v1 ./data:/data - - &v2 ./output:/output stop_signal: SIGKILL tty: true + restart: unless-stopped deploy: resources: # limits: @@ -17,6 +15,17 @@ x-base_service: &base_service device_ids: ['0'] capabilities: [compute, utility, gpu] +x-auto_service: &auto_service + <<: *base_service + container_name: auto + build: ./services/AUTOMATIC1111 + image: sd-auto:78 + ports: + - "${WEBUI_PORT:-7860}:7860" + volumes: + - &v1 ./data:/data + - &v2 ./output:/output + name: webui-docker services: @@ -26,18 +35,14 @@ services: volumes: - *v1 - auto: &automatic - <<: *base_service + auto: + <<: *auto_service profiles: ["auto"] - build: ./services/AUTOMATIC1111 - image: sd-auto:78 - ports: - - "${WEBUI_PORT:-7860}:7860" environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api auto-cpu: - <<: *automatic + <<: *auto_service profiles: ["auto-cpu"] deploy: {} ports: @@ -45,10 +50,17 @@ services: environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api + auto-full: + <<: *auto_service + profiles: [ "full" ] + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --no-half-vae --api + comfy: &comfy <<: *base_service profiles: ["comfy"] - build: ./services/comfy/ + container_name: comfy + build: ./services/comfy image: sd-comfy:7 volumes: - ./data/models:/opt/comfyui/models @@ -72,15 +84,19 @@ services: environment: - CLI_ARGS=--cpu - auto-full: + swarmui: <<: *base_service - profiles: [ "full" ] - build: ./services/AUTOMATIC1111 - image: sd-auto:78 - environment: - - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api + profiles: ["swarmui"] + container_name: swarmui + build: ./services/swarmui + image: sd-swarmui ports: - - "${WEBUI_PORT:-7860}:7860" + - "${SWARMUI_PORT:-7801}:7801" + volumes: + - ./data/swarmui:/SwarmUI/Data +# - "backend:/app/dlbackend" + - ./data/models:/SwarmUI/Models + - ./output/swarmui:/SwarmUI/Output convertor: <<: *base_service diff --git a/services/convert2safetensors/entrypoint.sh b/services/convert2safetensors/entrypoint.sh index 3500eb5..091bb63 100644 --- a/services/convert2safetensors/entrypoint.sh +++ b/services/convert2safetensors/entrypoint.sh @@ -2,5 +2,4 @@ set -ex echo "Running container as $USER" -echo "Running container as $USER..." python convert_2_safetensors.py --source ./models/input --dest ./models/output --allow-pickle diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile new file mode 100644 index 0000000..9d8fc9f --- /dev/null +++ b/services/swarmui/Dockerfile @@ -0,0 +1,68 @@ +ARG SWARMUI_VERSION=0.9.6-Beta +ARG DOTNET_VERSION=8.0-bookworm-slim + +FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build +ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 +ENV SWARM_PATH="/SwarmUI" +#ENV SWARM_PATH=/opt/swarmui + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && \ + apt-get install -y git + +WORKDIR ${SWARM_PATH} + +# Clones the SwarmUI repository and checks out the latest release +RUN git clone --depth=1 https://github.com/mcmonkeyprojects/SwarmUI.git ${SWARM_PATH} && \ + cd ${SWARM_PATH} && \ + git fetch origin ${SWARMUI_VERSION} && \ + git checkout FETCH_HEAD + +RUN dotnet build src/SwarmUI.csproj --configuration Release -o ./bin + +# RUN +FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim +ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 +ENV SWARM_PATH="/SwarmUI" +#ENV SWARM_PATH=/opt/swarmui +ARG SWARMUI_USER_ID=1000 +ARG SWARMUI_GROUP_ID=1000 + +ARG GPU_TYPE="nv" +ENV NVIDIA_VISIBLE_DEVICES=all +ENV CLI_ARGS="" + +RUN addgroup --gid $SWARMUI_GROUP_ID swarmui && \ + adduser --uid $SWARMUI_USER_ID --gid $SWARMUI_GROUP_ID --gecos "" --disabled-password swarmui + +COPY --from=build ${SWARM_PATH} "${SWARM_PATH}/" + +RUN mkdir -p "${SWARM_PATH}/Data" && \ + chown -R swarmui:swarmui ${SWARM_PATH} +ENV HOME=${SWARM_PATH} + +RUN --mount=type=cache,target=/var/cache/apt \ + apt update --assume-yes && \ + apt install -y \ + git \ + wget \ + build-essential \ + python3.11 \ + python3.11-venv \ + python3.11-dev \ + python3-pip \ + ffmpeg \ + libglib2.0-0 \ + libgl1 + +WORKDIR ${SWARM_PATH} + +USER swarmui + +RUN chmod +x ${SWARM_PATH}/launchtools/comfy-install-linux.sh && \ + ${SWARM_PATH}/launchtools/comfy-install-linux.sh ${GPU_TYPE} + +EXPOSE 7801 + +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh", "--launch_mode", "none", "--host", "0.0.0.0"] diff --git a/services/swarmui/entrypoint.sh b/services/swarmui/entrypoint.sh new file mode 100644 index 0000000..34e001b --- /dev/null +++ b/services/swarmui/entrypoint.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Ensure correct local path. +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPT_DIR" + +# Add dotnet non-admin-install to path +export PATH="$SCRIPT_DIR/.dotnet:~/.dotnet:$PATH" + +# Default env configuration, gets overwritten by the C# code's settings handler +export ASPNETCORE_ENVIRONMENT="Production" +export ASPNETCORE_URLS="http://*:7801" +# Actual runner. +cd "$HOME" +dotnet ./bin/SwarmUI.dll "$@" + +# Exit code 42 means restart, anything else = don't. +if [ $? == 42 ]; then + . /entrypoint.sh "$@" +fi From 94aa949b540fd296dc90bea8cfd777e024228378 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Sat, 2 Aug 2025 04:28:08 +0200 Subject: [PATCH 096/101] Update docker compose --- Docker-compose-build.yml | 88 ------------------- README.md | 1 + docker-compose.yml | 84 ++++++++++-------- .../{Dockerfile.rocm => ROCM.dockerfile} | 0 4 files changed, 46 insertions(+), 127 deletions(-) delete mode 100644 Docker-compose-build.yml rename services/AUTOMATIC1111/{Dockerfile.rocm => ROCM.dockerfile} (100%) diff --git a/Docker-compose-build.yml b/Docker-compose-build.yml deleted file mode 100644 index 83073ea..0000000 --- a/Docker-compose-build.yml +++ /dev/null @@ -1,88 +0,0 @@ -x-base_service: &base_service - ports: - - "${WEBUI_PORT:-7860}:7860" - volumes: - - &v1 ./data:/data - - &v2 ./output:/output - stop_signal: SIGKILL - tty: true - deploy: - resources: - reservations: - devices: - - driver: nvidia - device_ids: ['0'] - capabilities: [compute, utility] -name: webui-docker -services: - download: - build: ./services/download/ - profiles: ["download"] - volumes: - - *v1 - auto: &automatic - <<: *base_service - profiles: ["auto"] - build: ./services/AUTOMATIC1111 - image: sd-auto:80 - environment: - - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api - - auto-rocm: - <<: *base_service - profiles: ["auto-rocm"] - build: - context: ./services/AUTOMATIC1111 - dockerfile: Dockerfile.rocm - devices: - - "/dev/kfd" - - "/dev/dri" - deploy: {} - environment: - - CLI_ARGS=--allow-code --medvram --enable-insecure-extension-access --api - - reforge: &reforge - <<: *base_service - profiles: ["reforge"] - build: ./services/reforge - image: sd-reforge:80 - environment: - - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream - - forge: &forge - <<: *base_service - profiles: ["forge"] - build: ./services/forge - image: sd-forge:80 - environment: - - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream - - auto-cpu: - <<: *automatic - profiles: ["auto-cpu"] - deploy: {} - environment: - - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api - - comfy: &comfy - <<: *base_service - profiles: ["comfy"] - build: ./services/comfy/ - image: sd-comfy:6 - environment: - - CLI_ARGS= - - comfy-cpu: - <<: *comfy - profiles: ["comfy-cpu"] - deploy: {} - environment: - - CLI_ARGS=--cpu - - fooocus: &fooocus - <<: *base_service - profiles: ["fooocus"] - build: ./services/fooocus/ - image: sd-fooocus:3 - environment: - - CLI_ARGS= diff --git a/README.md b/README.md index c973e68..2f449c7 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ supports: - fooocus - forge - reforge +- swarmui # Stable Diffusion WebUI Docker diff --git a/docker-compose.yml b/docker-compose.yml index 712a6fa..617545d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,39 +41,6 @@ services: environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api -# TODO check docker image -# auto-rocm: -# <<: *base_service -# profiles: ["auto-rocm"] -# image: simonmcnair/automatic1111-rocm:master -# devices: -# - "/dev/kfd" -# - "/dev/dri" -# deploy: {} -# environment: -# - CLI_ARGS=--allow-code --medvram --enable-insecure-extension-access --api -# -# reforge: &reforge -# <<: *base_service -# profiles: ["reforge"] -# image: simonmcnair/reforge:master -# environment: -# - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream -# -# forge: &forge -# <<: *base_service -# profiles: ["forge"] -# image: simonmcnair/forge:master -# environment: -# - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream -# -# fooocus: &fooocus -# <<: *base_service -# profiles: ["fooocus"] -# image: simonmcnair/fooocus:master -# environment: -# - CLI_ARGS= - auto-cpu: <<: *auto_service profiles: ["auto-cpu"] @@ -89,6 +56,19 @@ services: environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --no-half-vae --api + auto-rocm: + <<: *base_service + profiles: ["auto-rocm"] + build: + context: ./services/AUTOMATIC1111 + dockerfile: ROCM.dockerfile + devices: + - "/dev/kfd" + - "/dev/dri" + deploy: {} + environment: + - CLI_ARGS=--allow-code --medvram --enable-insecure-extension-access --api + comfy: &comfy <<: *base_service profiles: ["comfy"] @@ -129,12 +109,38 @@ services: - ./data/swarmui:/SwarmUI/Data # - "backend:/app/dlbackend" - ./data/models:/SwarmUI/Models + - ./data/embeddings:/SwarmUI/Models/Embeddings - ./output/swarmui:/SwarmUI/Output - convertor: + reforge: &reforge <<: *base_service - profiles: [ "convert" ] - build: ./services/convert2safetensors - image: sd-convert - volumes: - - ./data/convert:/opt/convert2safetensors/models + profiles: ["reforge"] + build: ./services/reforge + image: sd-reforge:80 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + + forge: &forge + <<: *base_service + profiles: ["forge"] + build: ./services/forge + image: sd-forge:80 + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream + + fooocus: &fooocus + <<: *base_service + profiles: ["fooocus"] + build: ./services/fooocus/ + image: sd-fooocus:3 + environment: + - CLI_ARGS= + +# TODO rm old +# convertor: +# <<: *base_service +# profiles: [ "convert" ] +# build: ./services/convert2safetensors +# image: sd-convert +# volumes: +# - ./data/convert:/opt/convert2safetensors/models diff --git a/services/AUTOMATIC1111/Dockerfile.rocm b/services/AUTOMATIC1111/ROCM.dockerfile similarity index 100% rename from services/AUTOMATIC1111/Dockerfile.rocm rename to services/AUTOMATIC1111/ROCM.dockerfile From 99928ec8003657cbaac990790bcf3df57e838104 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Tue, 19 Aug 2025 06:19:30 +0200 Subject: [PATCH 097/101] Update comfyui, add comfyui manager to swarmui, TODOs --- docker-compose.yml | 25 ++++--- services/AUTOMATIC1111/entrypoint.sh | 14 ++-- services/comfy/Dockerfile | 2 +- services/swarmui/Dockerfile | 33 +++++++-- services/swarmui/comfy-install-linux.sh | 96 +++++++++++++++++++++++++ services/swarmui/entrypoint.sh | 28 +++++++- 6 files changed, 174 insertions(+), 24 deletions(-) create mode 100644 services/swarmui/comfy-install-linux.sh diff --git a/docker-compose.yml b/docker-compose.yml index 617545d..1864239 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,17 +15,20 @@ x-base_service: &base_service device_ids: ['0'] capabilities: [compute, utility, gpu] -x-auto_service: &auto_service +x-defaults: &defaults <<: *base_service - container_name: auto - build: ./services/AUTOMATIC1111 - image: sd-auto:78 ports: - "${WEBUI_PORT:-7860}:7860" volumes: - &v1 ./data:/data - &v2 ./output:/output +x-auto_service: &auto_service + <<: *defaults + container_name: auto + build: ./services/AUTOMATIC1111 + image: sd-auto:78 + name: webui-docker services: @@ -45,8 +48,6 @@ services: <<: *auto_service profiles: ["auto-cpu"] deploy: {} - ports: - - "${WEBUI_PORT:-7860}:7860" environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api @@ -57,8 +58,9 @@ services: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --no-half-vae --api auto-rocm: - <<: *base_service + <<: *auto_service profiles: ["auto-rocm"] + container_name: auto-rocm build: context: ./services/AUTOMATIC1111 dockerfile: ROCM.dockerfile @@ -77,9 +79,9 @@ services: image: sd-comfy:7 volumes: - ./data/models:/opt/comfyui/models + - ./data/models/configs:/opt/comfyui/user/default/ - ./data/config/comfy/custom_nodes:/opt/comfyui/custom_nodes - ./output/comfy:/opt/comfyui/output - - ./data/models/configs:/opt/comfyui/user/default/ ports: - "${COMFYUI_PORT:-7861}:7861" environment: @@ -107,10 +109,15 @@ services: - "${SWARMUI_PORT:-7801}:7801" volumes: - ./data/swarmui:/SwarmUI/Data -# - "backend:/app/dlbackend" - ./data/models:/SwarmUI/Models - ./data/embeddings:/SwarmUI/Models/Embeddings +# comfyui + - ./data/config/comfy/custom_nodes:/SwarmUI/dlbackend/ComfyUI/custom_nodes* +# TODO fix permissions + - ./data/models/configs:/SwarmUI/dlbackend/ComfyUI/user/default/ +# output - ./output/swarmui:/SwarmUI/Output + - ./output/swarmui/comfy:/SwarmUI/dlbackend/ComfyUI/output reforge: &reforge <<: *base_service diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index 5143c1b..d007e95 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -31,8 +31,8 @@ rsync --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ declare -A MOUNTS -#MOUNTS["/root/.cache"]="/data/.cache" -MOUNTS["${USER_HOME}/.cache"]="/data/.cache" +MOUNTS["/root/.cache"]="/data/.cache" +#MOUNTS["${USER_HOME}/.cache"]="/data/.cache" MOUNTS["${ROOT}/models"]="/data/models" MOUNTS["${ROOT}/embeddings"]="/data/embeddings" @@ -60,11 +60,11 @@ done echo "Installing extension dependencies (if any)" -chown -R $PUID:$PGID ~/.cache/ -chmod 766 ~/.cache/ - -chown -R $PUID:$PGID /output -chmod 766 /output +#chown -R $PUID:$PGID ~/.cache/ +#chmod 766 ~/.cache/ +# +#chown -R $PUID:$PGID /output +#chmod 766 /output shopt -s nullglob # For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 89ce958..783c5d1 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,5 +1,5 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.44 +ARG COMFYUI_VERSION=v0.3.50 ARG COMFYUI_MANAGER_VERSION=3.33.8 ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index 9d8fc9f..b328c65 100644 --- a/services/swarmui/Dockerfile +++ b/services/swarmui/Dockerfile @@ -1,10 +1,13 @@ ARG SWARMUI_VERSION=0.9.6-Beta +ARG COMFYUI_VERSION=v0.3.50 +ARG COMFYUI_MANAGER_VERSION=3.33.8 ARG DOTNET_VERSION=8.0-bookworm-slim +ARG SWARM_PATH="/SwarmUI" +#ENV SWARM_PATH=/opt/swarmui FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build +ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 -ENV SWARM_PATH="/SwarmUI" -#ENV SWARM_PATH=/opt/swarmui RUN --mount=type=cache,target=/var/cache/apt \ apt-get update && \ @@ -22,9 +25,9 @@ RUN dotnet build src/SwarmUI.csproj --configuration Release -o ./bin # RUN FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim +ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 -ENV SWARM_PATH="/SwarmUI" -#ENV SWARM_PATH=/opt/swarmui + ARG SWARMUI_USER_ID=1000 ARG SWARMUI_GROUP_ID=1000 @@ -55,13 +58,31 @@ RUN --mount=type=cache,target=/var/cache/apt \ libglib2.0-0 \ libgl1 +RUN git clone --depth=1 https://github.com/comfyanonymous/ComfyUI.git /opt/comfyui && \ + cd /opt/comfyui && \ + git fetch origin ${COMFYUI_VERSION} && \ + git checkout FETCH_HEAD + +RUN git clone --depth=1 https://github.com/Comfy-Org/ComfyUI-Manager.git /opt/comfyui-manager && \ + cd /opt/comfyui-manager && \ + git fetch origin ${COMFYUI_MANAGER_VERSION} && \ + git checkout FETCH_HEAD + WORKDIR ${SWARM_PATH} +ENV COMFYUI_PATH="/SwarmUI/dlbackend/ComfyUI" +ENV CUSTOM_NODES_PATH="/SwarmUI/dlbackend/ComfyUI/custom_nodes" -USER swarmui - +COPY comfy-install-linux.sh ${SWARM_PATH}/launchtools/ RUN chmod +x ${SWARM_PATH}/launchtools/comfy-install-linux.sh && \ ${SWARM_PATH}/launchtools/comfy-install-linux.sh ${GPU_TYPE} +RUN chown -R swarmui:swarmui ${COMFYUI_PATH}/venv +RUN chown -R swarmui:swarmui ${COMFYUI_PATH} +RUN git config --global --add safe.directory ${COMFYUI_PATH} + +ENV PATH="${COMFYUI_PATH}/venv/bin:$PATH" +ENV PYTHONPATH="${CUSTOM_NODES_PATH}:${PYTHONPATH}" +USER swarmui EXPOSE 7801 COPY entrypoint.sh / diff --git a/services/swarmui/comfy-install-linux.sh b/services/swarmui/comfy-install-linux.sh new file mode 100644 index 0000000..fde2708 --- /dev/null +++ b/services/swarmui/comfy-install-linux.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +# Check if GPU type is provided +if [ $# -eq 0 ]; then + >&2 echo "Error: GPU type not specified. Please use 'amd' or 'nv' as an argument." + exit 1 +fi + +GPU_TYPE=$1 + +# Validate GPU type +if [ "$GPU_TYPE" != "amd" ] && [ "$GPU_TYPE" != "nv" ]; then + >&2 echo "Error: Invalid GPU type. Please use 'amd' or 'nv'." + exit 1 +fi + +mkdir dlbackend + +# Creates the symlink for the ComfyUI directory +echo "Creating symlink for ComfyUI..." +rm --force ${CUSTOM_NODES_PATH}/ComfyUI-Manager +ln -s \ + /opt/comfyui \ + ${COMFYUI_PATH} + +echo "Creating symlink for ComfyUI Manager..." +rm --force ${CUSTOM_NODES_PATH}/ComfyUI-Manager +ln -s \ + /opt/comfyui-manager \ + ${CUSTOM_NODES_PATH}/ComfyUI-Manager + +#cd ComfyUI +cd ${COMFYUI_PATH} + +# Try to find a good python executable, and dodge unsupported python versions +for pyvers in python3.11 python3.10 python3.12 python3 python +do + python=`which $pyvers` + if [ "$python" != "" ]; then + break + fi +done +if [ "$python" == "" ]; then + >&2 echo "ERROR: cannot find python3" + >&2 echo "Please follow the install instructions in the readme!" + exit 1 +fi + +# Validate venv +venv=`$python -m venv 2>&1` +case $venv in + *usage*) + : + ;; + *) + >&2 echo "ERROR: python venv is not installed" + >&2 echo "Please follow the install instructions in the readme!" + >&2 echo "If on Ubuntu/Debian, you may need: sudo apt install python3-venv" + exit 1 + ;; +esac + +# Make and activate the venv. "python3" in the venv is now the python executable. +if [ -z "${SWARM_NO_VENV}" ]; then + echo "Making venv..." + $python -s -m venv venv + source venv/bin/activate + python=python3 + python3 -m ensurepip --upgrade +else + echo "swarm_no_venv set, will not create venv" +fi + +# Install PyTorch based on GPU type +if [ "$GPU_TYPE" == "nv" ]; then + echo "install nvidia torch..." + $python -s -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu128 +elif [ "$GPU_TYPE" == "amd" ]; then + echo "install amd torch..." + $python -s -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.3 +fi + +echo "install general requirements..." +$python -s -m pip install --no-cache-dir \ + triton \ + sageattention \ + opencv-python \ + diffusers \ + psutil + +# Installs the required Python packages for both ComfyUI and the ComfyUI Manager +$python -s -m pip install --no-cache-dir \ + --requirement ${COMFYUI_PATH}/requirements.txt \ + --requirement ${CUSTOM_NODES_PATH}/ComfyUI-Manager/requirements.txt + +echo "Installation completed for $GPU_TYPE GPU." diff --git a/services/swarmui/entrypoint.sh b/services/swarmui/entrypoint.sh index 34e001b..168881c 100644 --- a/services/swarmui/entrypoint.sh +++ b/services/swarmui/entrypoint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +#set -x # Ensure correct local path. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$SCRIPT_DIR" @@ -10,6 +10,32 @@ export PATH="$SCRIPT_DIR/.dotnet:~/.dotnet:$PATH" # Default env configuration, gets overwritten by the C# code's settings handler export ASPNETCORE_ENVIRONMENT="Production" export ASPNETCORE_URLS="http://*:7801" + +# TODO fix permissions +#chown -R swarmui:swarmui ${COMFYUI_PATH}/user/default/ +chmod -R 755 ${COMFYUI_PATH}/user/default/ +chmod -R 755 /opt/comfyui/user/default/ + +echo "Using Python at: $(which python)" +echo "Python version: $(python --version)" + +# The custom nodes that were installed using the ComfyUI Manager may have requirements of their own, which are not installed when the container is +# started for the first time; this loops over all custom nodes and installs the requirements of each custom node +echo "Installing requirements for custom nodes..." +for CUSTOM_NODE_DIRECTORY in ${CUSTOM_NODES_PATH}/*; +do + if [ "$CUSTOM_NODE_DIRECTORY" != "${CUSTOM_NODES_PATH}/ComfyUI-Manager" ]; + then + if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ]; + then + CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/} + CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ } + echo "Installing requirements for $CUSTOM_NODE_NAME..." + python3 -s -m pip install --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt" + fi + fi +done + # Actual runner. cd "$HOME" dotnet ./bin/SwarmUI.dll "$@" From 01f26a370440a4d113cf69c32d364e2c62805c3a Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Mon, 25 Aug 2025 02:56:46 +0200 Subject: [PATCH 098/101] Update comfyui & pre-install requirements --- docker-compose.yml | 2 +- services/comfy/Dockerfile | 9 ++++-- services/comfy/install/.gitignore | 2 ++ services/comfy/install/install.sh | 52 +++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 services/comfy/install/.gitignore create mode 100644 services/comfy/install/install.sh diff --git a/docker-compose.yml b/docker-compose.yml index 1864239..38253f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -112,7 +112,7 @@ services: - ./data/models:/SwarmUI/Models - ./data/embeddings:/SwarmUI/Models/Embeddings # comfyui - - ./data/config/comfy/custom_nodes:/SwarmUI/dlbackend/ComfyUI/custom_nodes* + - ./data/config/comfy/custom_nodes:/SwarmUI/dlbackend/ComfyUI/custom_nodes # TODO fix permissions - ./data/models/configs:/SwarmUI/dlbackend/ComfyUI/user/default/ # output diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 783c5d1..af625f1 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,5 +1,5 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.50 +ARG COMFYUI_VERSION=v0.3.52 ARG COMFYUI_MANAGER_VERSION=3.33.8 ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime @@ -50,12 +50,17 @@ RUN pip3 install --no-cache-dir \ sageattention \ psutil +# Pre-install previously used custom nodes requirements from volume +COPY ./install/merged-requirements.txt* /docker/requirements.txt +RUN sh -c '[ -f /docker/requirements.txt ] && pip install --no-cache-dir -r /docker/requirements.txt \ + || echo "merged-requirements.txt not found, skipping pre-install."' + # Sets the working directory to the ComfyUI directory WORKDIR /opt/comfyui COPY . /docker/ RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml /opt/comfyui -ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" +ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="\${PYTHONPATH}:\${PWD}" CLI_ARGS="" EXPOSE 7861 # Adds the startup script to the container; the startup script will create all necessary directories in the models and custom nodes volumes that were diff --git a/services/comfy/install/.gitignore b/services/comfy/install/.gitignore new file mode 100644 index 0000000..c290e5e --- /dev/null +++ b/services/comfy/install/.gitignore @@ -0,0 +1,2 @@ +reqs +merged-requirements.txt diff --git a/services/comfy/install/install.sh b/services/comfy/install/install.sh new file mode 100644 index 0000000..c88b9e6 --- /dev/null +++ b/services/comfy/install/install.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Get custom nodes requirements and merge latest versions +REQ_PATH="data/config/comfy/custom_nodes" +BUILD_PATH="services/comfy/install" + +mkdir -p ${BUILD_PATH}/reqs +for f in ${REQ_PATH}/*/requirements.txt; do \ + node=$(basename $(dirname "$f")); \ + cp "$f" ${BUILD_PATH}/reqs/${node}-requirements.txt; \ +done +find ${BUILD_PATH}/reqs -maxdepth 1 -name "*requirements.txt" -exec cat {} + \ + | grep -v '^#' \ + | grep -v '^git' \ + | sed 's/==.*//' \ + | awk '{print tolower($0)}' \ + | sed 's/[[:space:]]//g' \ + | sort -u \ + | awk ' + { + line = $0; + if (line ~ /^[[:space:]]*$/) { next } + if (line ~ /git\+/ || line ~ /\[.*\]/) { + print "Z_" line, "0", line + next + } + split(line, a, "[<>=]") + package = a[1] + version = a[2] + gsub(/[[:space:]]+/, "", package) + gsub(/_/, "-", package) + if (version == "") { + version = "0" + } + print package, version, line + } + ' \ + | sort -k1,1 -V -k2,2 \ + | awk ' + { + if (prev_package != $1) { + if (NR > 1) { + print prev_line + } + prev_package = $1 + } + prev_line = $3 + } + END { + print prev_line + } + ' \ + > ${BUILD_PATH}/merged-requirements.txt From 1e1c593cd1020e6c571d11103f22336670df6d65 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Fri, 5 Sep 2025 01:14:52 +0200 Subject: [PATCH 099/101] Update swarmui & comfyui, pre-install custom nodes requirements for swarmui, fix permissions & TODOs --- README.md | 5 ++- docker-compose.yml | 7 +++- services/comfy/Dockerfile | 4 +- services/comfy/install/install.sh | 2 +- services/swarmui/Dockerfile | 18 +++++---- services/swarmui/comfy-install-linux.sh | 8 ++++ services/swarmui/entrypoint.sh | 4 +- services/swarmui/install/.gitignore | 2 + services/swarmui/install/install.sh | 52 +++++++++++++++++++++++++ 9 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 services/swarmui/install/.gitignore create mode 100644 services/swarmui/install/install.sh diff --git a/README.md b/README.md index 2f449c7..a753ea1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ supports: - fooocus - forge - reforge -- swarmui +- swarmui _**(be aware comfyui backend can take some time to start, up to a minute or 2)**_ + +#### TODOs +1. [ ] Fix [Warning] [ComfyUI-0/STDERR] NameError: name 'NODE_CLASS_MAPPINGS' is not defined # Stable Diffusion WebUI Docker diff --git a/docker-compose.yml b/docker-compose.yml index 38253f6..f931269 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -113,11 +113,14 @@ services: - ./data/embeddings:/SwarmUI/Models/Embeddings # comfyui - ./data/config/comfy/custom_nodes:/SwarmUI/dlbackend/ComfyUI/custom_nodes -# TODO fix permissions - - ./data/models/configs:/SwarmUI/dlbackend/ComfyUI/user/default/ +# - ./data/models/configs:/SwarmUI/dlbackend/ComfyUI/user/default/ # TODO rm old + - ./data/config/configs:/SwarmUI/dlbackend/ComfyUI/user/default/ # output - ./output/swarmui:/SwarmUI/Output - ./output/swarmui/comfy:/SwarmUI/dlbackend/ComfyUI/output + environment: + - COMFYUI_PATH=/opt/comfyui + - COMFYUI_MODEL_PATH=/opt/comfyui/models reforge: &reforge <<: *base_service diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index af625f1..7128ef5 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,6 +1,6 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.52 -ARG COMFYUI_MANAGER_VERSION=3.33.8 +ARG COMFYUI_VERSION=v0.3.57 +ARG COMFYUI_MANAGER_VERSION=3.35 ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime # This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch diff --git a/services/comfy/install/install.sh b/services/comfy/install/install.sh index c88b9e6..7a4420d 100644 --- a/services/comfy/install/install.sh +++ b/services/comfy/install/install.sh @@ -1,7 +1,7 @@ #!/bin/bash # Get custom nodes requirements and merge latest versions REQ_PATH="data/config/comfy/custom_nodes" -BUILD_PATH="services/comfy/install" +BUILD_PATH=$(dirname "$0") mkdir -p ${BUILD_PATH}/reqs for f in ${REQ_PATH}/*/requirements.txt; do \ diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index b328c65..37ab817 100644 --- a/services/swarmui/Dockerfile +++ b/services/swarmui/Dockerfile @@ -1,10 +1,11 @@ ARG SWARMUI_VERSION=0.9.6-Beta -ARG COMFYUI_VERSION=v0.3.50 -ARG COMFYUI_MANAGER_VERSION=3.33.8 +ARG COMFYUI_VERSION=v0.3.57 +ARG COMFYUI_MANAGER_VERSION=3.35 ARG DOTNET_VERSION=8.0-bookworm-slim ARG SWARM_PATH="/SwarmUI" #ENV SWARM_PATH=/opt/swarmui +# BUILD FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 @@ -58,6 +59,7 @@ RUN --mount=type=cache,target=/var/cache/apt \ libglib2.0-0 \ libgl1 +# Install ComfyUI RUN git clone --depth=1 https://github.com/comfyanonymous/ComfyUI.git /opt/comfyui && \ cd /opt/comfyui && \ git fetch origin ${COMFYUI_VERSION} && \ @@ -69,19 +71,21 @@ RUN git clone --depth=1 https://github.com/Comfy-Org/ComfyUI-Manager.git /opt/co git checkout FETCH_HEAD WORKDIR ${SWARM_PATH} +RUN chown -R swarmui:swarmui /opt/comfyui +RUN git config --global --add safe.directory /opt/comfyui + ENV COMFYUI_PATH="/SwarmUI/dlbackend/ComfyUI" ENV CUSTOM_NODES_PATH="/SwarmUI/dlbackend/ComfyUI/custom_nodes" +# Pre-install previously used custom nodes requirements from volume +COPY ./install/merged-requirements.txt* /docker/requirements.txt COPY comfy-install-linux.sh ${SWARM_PATH}/launchtools/ RUN chmod +x ${SWARM_PATH}/launchtools/comfy-install-linux.sh && \ ${SWARM_PATH}/launchtools/comfy-install-linux.sh ${GPU_TYPE} -RUN chown -R swarmui:swarmui ${COMFYUI_PATH}/venv -RUN chown -R swarmui:swarmui ${COMFYUI_PATH} -RUN git config --global --add safe.directory ${COMFYUI_PATH} - +RUN chown -R swarmui:swarmui ${COMFYUI_PATH}/venv # Reapplied again bc of permissions issues, maybe related to a symlink/docker/windows bug ENV PATH="${COMFYUI_PATH}/venv/bin:$PATH" -ENV PYTHONPATH="${CUSTOM_NODES_PATH}:${PYTHONPATH}" +ENV PYTHONPATH="${CUSTOM_NODES_PATH}:\${PYTHONPATH}" USER swarmui EXPOSE 7801 diff --git a/services/swarmui/comfy-install-linux.sh b/services/swarmui/comfy-install-linux.sh index fde2708..4e667ae 100644 --- a/services/swarmui/comfy-install-linux.sh +++ b/services/swarmui/comfy-install-linux.sh @@ -93,4 +93,12 @@ $python -s -m pip install --no-cache-dir \ --requirement ${COMFYUI_PATH}/requirements.txt \ --requirement ${CUSTOM_NODES_PATH}/ComfyUI-Manager/requirements.txt +# Pre-install previously used custom nodes requirements from volume +if [ -f "/docker/requirements.txt" ]; then + echo "pre-install custom nodes requirements..." + $python -s -m pip install --no-cache-dir -r /docker/requirements.txt +elif [ "$GPU_TYPE" == "amd" ]; then + echo "merged-requirements.txt not found, skipping pre-install." +fi + echo "Installation completed for $GPU_TYPE GPU." diff --git a/services/swarmui/entrypoint.sh b/services/swarmui/entrypoint.sh index 168881c..f73c98a 100644 --- a/services/swarmui/entrypoint.sh +++ b/services/swarmui/entrypoint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#set -x +set -x # Ensure correct local path. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$SCRIPT_DIR" @@ -11,8 +11,6 @@ export PATH="$SCRIPT_DIR/.dotnet:~/.dotnet:$PATH" export ASPNETCORE_ENVIRONMENT="Production" export ASPNETCORE_URLS="http://*:7801" -# TODO fix permissions -#chown -R swarmui:swarmui ${COMFYUI_PATH}/user/default/ chmod -R 755 ${COMFYUI_PATH}/user/default/ chmod -R 755 /opt/comfyui/user/default/ diff --git a/services/swarmui/install/.gitignore b/services/swarmui/install/.gitignore new file mode 100644 index 0000000..c290e5e --- /dev/null +++ b/services/swarmui/install/.gitignore @@ -0,0 +1,2 @@ +reqs +merged-requirements.txt diff --git a/services/swarmui/install/install.sh b/services/swarmui/install/install.sh new file mode 100644 index 0000000..7a4420d --- /dev/null +++ b/services/swarmui/install/install.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Get custom nodes requirements and merge latest versions +REQ_PATH="data/config/comfy/custom_nodes" +BUILD_PATH=$(dirname "$0") + +mkdir -p ${BUILD_PATH}/reqs +for f in ${REQ_PATH}/*/requirements.txt; do \ + node=$(basename $(dirname "$f")); \ + cp "$f" ${BUILD_PATH}/reqs/${node}-requirements.txt; \ +done +find ${BUILD_PATH}/reqs -maxdepth 1 -name "*requirements.txt" -exec cat {} + \ + | grep -v '^#' \ + | grep -v '^git' \ + | sed 's/==.*//' \ + | awk '{print tolower($0)}' \ + | sed 's/[[:space:]]//g' \ + | sort -u \ + | awk ' + { + line = $0; + if (line ~ /^[[:space:]]*$/) { next } + if (line ~ /git\+/ || line ~ /\[.*\]/) { + print "Z_" line, "0", line + next + } + split(line, a, "[<>=]") + package = a[1] + version = a[2] + gsub(/[[:space:]]+/, "", package) + gsub(/_/, "-", package) + if (version == "") { + version = "0" + } + print package, version, line + } + ' \ + | sort -k1,1 -V -k2,2 \ + | awk ' + { + if (prev_package != $1) { + if (NR > 1) { + print prev_line + } + prev_package = $1 + } + prev_line = $3 + } + END { + print prev_line + } + ' \ + > ${BUILD_PATH}/merged-requirements.txt From 8ea0542cbff4ea5b3dc454a580f9f3982f5c6ef9 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Thu, 18 Sep 2025 11:35:37 +0200 Subject: [PATCH 100/101] Update comfyui pytorch & swarmui sdk, fix some paths & cleanup --- docker-compose.yml | 23 +-- services/comfy/Dockerfile | 4 +- services/comfy/extra_model_paths.yaml | 3 +- services/convert2safetensors/Dockerfile | 26 --- .../convert_2_safetensors.py | 160 ------------------ services/convert2safetensors/entrypoint.sh | 5 - services/convert2safetensors/requirements.txt | 5 - services/swarmui/Dockerfile | 10 +- services/swarmui/entrypoint.sh | 1 - 9 files changed, 17 insertions(+), 220 deletions(-) delete mode 100644 services/convert2safetensors/Dockerfile delete mode 100644 services/convert2safetensors/convert_2_safetensors.py delete mode 100644 services/convert2safetensors/entrypoint.sh delete mode 100644 services/convert2safetensors/requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml index f931269..bb740c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ x-auto_service: &auto_service <<: *defaults container_name: auto build: ./services/AUTOMATIC1111 - image: sd-auto:78 + image: sd-auto:latest name: webui-docker @@ -76,10 +76,10 @@ services: profiles: ["comfy"] container_name: comfy build: ./services/comfy - image: sd-comfy:7 + image: sd-comfy:latest volumes: - ./data/models:/opt/comfyui/models - - ./data/models/configs:/opt/comfyui/user/default/ + - ./data/config/configs:/opt/comfyui/user/default/ - ./data/config/comfy/custom_nodes:/opt/comfyui/custom_nodes - ./output/comfy:/opt/comfyui/output ports: @@ -104,7 +104,7 @@ services: profiles: ["swarmui"] container_name: swarmui build: ./services/swarmui - image: sd-swarmui + image: sd-swarmui:latest ports: - "${SWARMUI_PORT:-7801}:7801" volumes: @@ -126,7 +126,7 @@ services: <<: *base_service profiles: ["reforge"] build: ./services/reforge - image: sd-reforge:80 + image: sd-reforge:latest environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream @@ -134,7 +134,7 @@ services: <<: *base_service profiles: ["forge"] build: ./services/forge - image: sd-forge:80 + image: sd-forge:latest environment: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api --pin-shared-memory --cuda-malloc --cuda-stream @@ -142,15 +142,6 @@ services: <<: *base_service profiles: ["fooocus"] build: ./services/fooocus/ - image: sd-fooocus:3 + image: sd-fooocus:latest environment: - CLI_ARGS= - -# TODO rm old -# convertor: -# <<: *base_service -# profiles: [ "convert" ] -# build: ./services/convert2safetensors -# image: sd-convert -# volumes: -# - ./data/convert:/opt/convert2safetensors/models diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 7128ef5..340029d 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,7 +1,7 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.57 +ARG COMFYUI_VERSION=v0.3.59 ARG COMFYUI_MANAGER_VERSION=3.35 -ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime +ARG PYTORCH_VERSION=2.8.0-cuda12.9-cudnn9-runtime # This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch FROM pytorch/pytorch:${PYTORCH_VERSION} diff --git a/services/comfy/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index 4ef41c8..a0fce2b 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -3,7 +3,8 @@ a111: # base_path: /data checkpoints: models/Stable-diffusion - configs: models/configs + configs: user/default +# configs: models/configs vae: models/VAE loras: | models/Lora diff --git a/services/convert2safetensors/Dockerfile b/services/convert2safetensors/Dockerfile deleted file mode 100644 index d6f144f..0000000 --- a/services/convert2safetensors/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime -FROM pytorch/pytorch:${PYTORCH_VERSION} - -ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 - -RUN apt update --assume-yes && \ -# apt install --assume-yes \ -# git \ -# sudo \ -# build-essential \ -# libgl1-mesa-glx \ -# libglib2.0-0 \ -# libsm6 \ -# libxext6 \ -# ffmpeg && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -WORKDIR /opt/convert2safetensors -COPY . /opt/convert2safetensors/ -RUN chmod u+x /opt/convert2safetensors/entrypoint.sh - -RUN pip install --requirement /opt/convert2safetensors/requirements.txt - -ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" -ENTRYPOINT ["/bin/bash", "/opt/convert2safetensors/entrypoint.sh"] diff --git a/services/convert2safetensors/convert_2_safetensors.py b/services/convert2safetensors/convert_2_safetensors.py deleted file mode 100644 index 086c9e0..0000000 --- a/services/convert2safetensors/convert_2_safetensors.py +++ /dev/null @@ -1,160 +0,0 @@ -import argparse -import json -import os -import shutil -import torch -from collections import defaultdict -from safetensors.torch import load_file, save_file -from tqdm import tqdm - - -def shared_pointers(tensors): - ptrs = defaultdict(list) - for k, v in tensors.items(): - ptrs[v.data_ptr()].append(k) - return [names for names in ptrs.values() if len(names) > 1] - - -def check_file_size(sf_filename, pt_filename): - sf_size = os.stat(sf_filename).st_size - pt_size = os.stat(pt_filename).st_size - if (sf_size - pt_size) / pt_size > 0.01: - raise RuntimeError(f"File size difference exceeds 1% between {sf_filename} and {pt_filename}") - - -def convert_file(pt_filename, sf_filename, copy_add_data=True, allow_pickle=False): - try: - loaded = torch.load(pt_filename, map_location="cpu", weights_only=not allow_pickle) - except Exception as e: - print(f"[WARNING] Failed to load '{pt_filename}': {e}") - return # Skip this file - loaded = loaded.get("state_dict", loaded) - shared = shared_pointers(loaded) - - for shared_weights in shared: - for name in shared_weights[1:]: - loaded.pop(name) - - loaded = {k: v.contiguous().half() for k, v in loaded.items()} - - source_folder = os.path.dirname(pt_filename) - dest_folder = os.path.dirname(sf_filename) - os.makedirs(dest_folder, exist_ok=True) - save_file(loaded, sf_filename, metadata={"format": "pt"}) - check_file_size(sf_filename, pt_filename) - if copy_add_data: - copy_additional_files(source_folder, dest_folder) - - reloaded = load_file(sf_filename) - for k, v in loaded.items(): - if not torch.equal(v, reloaded[k]): - raise RuntimeError(f"Mismatch in tensors for key {k}.") - - -def rename(pt_filename): - filename, ext = os.path.splitext(pt_filename) - local = f"{filename}.safetensors" - local = local.replace("pytorch_model", "model") - return local - - -def copy_additional_files(source_folder, dest_folder): - for file in os.listdir(source_folder): - file_path = os.path.join(source_folder, file) - if os.path.isfile(file_path) and not file.endswith(('.bin', '.py', '.pt', '.pth')): - shutil.copy(file_path, dest_folder) - - -def find_index_file(source_folder): - for file in os.listdir(source_folder): - if file.endswith('.bin.index.json'): - return file - return None - - -def convert_files(source_folder, dest_folder, delete_old, use_dest_folder, allow_pickle): - index_file = find_index_file(source_folder) - if index_file: - index_file = os.path.join(source_folder, index_file) - with open(index_file) as f: - index_data = json.load(f) - for pt_filename in tqdm(set(index_data["weight_map"].values()), desc="Converting files"): - full_pt_filename = os.path.join(source_folder, pt_filename) - sf_filename = os.path.join(dest_folder, rename(pt_filename)) if use_dest_folder else os.path.join( - os.path.dirname(full_pt_filename), rename(pt_filename)) - convert_file(full_pt_filename, sf_filename, copy_add_data=False, allow_pickle=allow_pickle) - if delete_old: - os.remove(full_pt_filename) - index_path = os.path.join(dest_folder, "model.safetensors.index.json") if use_dest_folder else os.path.join( - os.path.dirname(index_file), "model.safetensors.index.json") - with open(index_path, "w") as f: - new_map = {k: rename(v) for k, v in index_data["weight_map"].items()} - json.dump({**index_data, "weight_map": new_map}, f, indent=4) - else: - for pt_filename in tqdm(os.listdir(source_folder), desc="Converting files"): - if pt_filename.endswith(('.bin', '.pt', '.pth')): - full_pt_filename = os.path.join(source_folder, pt_filename) - sf_filename = os.path.join(dest_folder, rename(pt_filename)) if use_dest_folder else os.path.join( - os.path.dirname(full_pt_filename), rename(pt_filename)) - convert_file(full_pt_filename, sf_filename, copy_add_data=False, allow_pickle=allow_pickle) - if delete_old: - os.remove(full_pt_filename) - - copy_additional_files(source_folder, dest_folder) - - -def convert_batch(source_dir, dest_dir, delete_old, use_dest_folder, allow_pickle): - files_to_convert = [] - for root, _, files in os.walk(source_dir): - for file in files: - if file.endswith(('.bin', '.pt', '.pth')): - files_to_convert.append(os.path.join(root, file)) - for full_model_path in tqdm(files_to_convert, desc="Converting batch of models"): - sf_filename = os.path.join(dest_dir, os.path.relpath(rename(full_model_path), - source_dir)) if use_dest_folder else os.path.join( - os.path.dirname(full_model_path), rename(full_model_path)) - os.makedirs(os.path.dirname(sf_filename), exist_ok=True) - convert_file(full_model_path, sf_filename, copy_add_data=False, allow_pickle=allow_pickle) - if delete_old: - os.remove(full_model_path) - - -def main(): - parser = argparse.ArgumentParser(description="Convert PyTorch model files to SafeTensors format.") - parser.add_argument("--source", required=False, default=os.getcwd(), - help="Source folder containing .pth/.pt/.bin files") - parser.add_argument("--dest", required=False, - help="Destination folder for .safetensors files. If not specified, will use default.") - parser.add_argument("--delete-old", action="store_true", - help="Delete original PyTorch files after conversion") - parser.add_argument("--batch", action="store_true", - help="Recursively convert a batch of models from subdirectories") - parser.add_argument("--allow-pickle", action="store_true", - help="Allow loading legacy models with full object deserialization (trusted sources only!)") - - args = parser.parse_args() - - source_folder = os.path.abspath(args.source) - dest_folder = os.path.abspath(args.dest) if args.dest else os.path.join( - source_folder, os.path.basename(source_folder) + "_safetensors") - use_dest_folder = bool(args.dest) - - if args.batch: - convert_batch(source_folder, dest_folder, args.delete_old, use_dest_folder, args.allow_pickle) - else: - if any(fname.endswith(('.bin', '.pt', '.pth')) for fname in os.listdir(source_folder)): - if "pytorch_model.bin" in os.listdir(source_folder): - sf_filename = os.path.join(dest_folder, "model.safetensors") if use_dest_folder else os.path.join( - source_folder, "model.safetensors") - convert_file(os.path.join(source_folder, "pytorch_model.bin"), sf_filename, - copy_add_data=True, allow_pickle=args.allow_pickle) - if args.delete_old: - os.remove(os.path.join(source_folder, "pytorch_model.bin")) - else: - convert_files(source_folder, dest_folder, args.delete_old, use_dest_folder, args.allow_pickle) - else: - raise RuntimeError("No valid model files found in the specified directory.") - - -if __name__ == "__main__": - main() diff --git a/services/convert2safetensors/entrypoint.sh b/services/convert2safetensors/entrypoint.sh deleted file mode 100644 index 091bb63..0000000 --- a/services/convert2safetensors/entrypoint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -ex - -echo "Running container as $USER" -python convert_2_safetensors.py --source ./models/input --dest ./models/output --allow-pickle diff --git a/services/convert2safetensors/requirements.txt b/services/convert2safetensors/requirements.txt deleted file mode 100644 index 0ed85e7..0000000 --- a/services/convert2safetensors/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -safetensors -argparse -torch -tqdm -numpy diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index 37ab817..0919d64 100644 --- a/services/swarmui/Dockerfile +++ b/services/swarmui/Dockerfile @@ -1,9 +1,11 @@ ARG SWARMUI_VERSION=0.9.6-Beta -ARG COMFYUI_VERSION=v0.3.57 +ARG COMFYUI_VERSION=v0.3.59 ARG COMFYUI_MANAGER_VERSION=3.35 -ARG DOTNET_VERSION=8.0-bookworm-slim +ARG DOTNET_VERSION=9.0-bookworm-slim +#ARG DOTNET_VERSION=8.0-bookworm-slim +ARG ASPNET_VERSION=9.0-bookworm-slim +#ARG ASPNET_VERSION=8.0-bookworm-slim ARG SWARM_PATH="/SwarmUI" -#ENV SWARM_PATH=/opt/swarmui # BUILD FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build @@ -25,7 +27,7 @@ RUN git clone --depth=1 https://github.com/mcmonkeyprojects/SwarmUI.git ${SWARM_ RUN dotnet build src/SwarmUI.csproj --configuration Release -o ./bin # RUN -FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim +FROM mcr.microsoft.com/dotnet/aspnet:${ASPNET_VERSION} ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 diff --git a/services/swarmui/entrypoint.sh b/services/swarmui/entrypoint.sh index f73c98a..9ed20fd 100644 --- a/services/swarmui/entrypoint.sh +++ b/services/swarmui/entrypoint.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -x # Ensure correct local path. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$SCRIPT_DIR" From 24c6100742bd260f4239196479d38f8381f0e727 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Thu, 18 Sep 2025 15:39:36 +0200 Subject: [PATCH 101/101] Update swarmui --- services/swarmui/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index 0919d64..f2ca9ed 100644 --- a/services/swarmui/Dockerfile +++ b/services/swarmui/Dockerfile @@ -1,4 +1,4 @@ -ARG SWARMUI_VERSION=0.9.6-Beta +ARG SWARMUI_VERSION=0.9.7-Beta ARG COMFYUI_VERSION=v0.3.59 ARG COMFYUI_MANAGER_VERSION=3.35 ARG DOTNET_VERSION=9.0-bookworm-slim