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 01/20] 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 | 88 +++++++++++++++++++-------- services/comfy/extra_model_paths.yaml | 30 +++++---- 15 files changed, 433 insertions(+), 63 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 000000000..aab110a78 --- /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 2a011a105..9d34c3ff5 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 946349a5f..f20063c99 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 970b61211..5d94433b4 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 000000000..841b36c8b --- /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 000000000..0122e4125 --- /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 000000000..a28fb38ba --- /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 000000000..638b2e5ed --- /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 000000000..303f80c68 --- /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 000000000..0f013ad16 --- /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 d59578442..b8e5751cf 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 35023af21..968d52c1c 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 2de504d85..4684b5a0a 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/* + +# 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 + +# 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 -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 +# 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 -WORKDIR ${ROOT} +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 b4299a717..aee8a09f8 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 +# 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 -MOUNTS["/root/.cache"]="/data/.cache" -MOUNTS["${ROOT}/input"]="/data/config/comfy/input" -MOUNTS["${ROOT}/output"]="/output/comfy" +# 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 -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}") +# 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 -if [ -f "/data/config/comfy/startup.sh" ]; then - pushd ${ROOT} - . /data/config/comfy/startup.sh - popd -fi +# 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 -exec "$@" + 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 eb374eb30..4ef41c89f 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 - upscale_models: | - models/RealESRGAN - models/ESRGAN - models/SwinIR - models/GFPGAN + loras: | + models/Lora + models/loras hypernetworks: models/hypernetworks - controlnet: models/ControlNet + controlnet: models/controlnet gligen: models/GLIGEN clip: models/CLIPEncoder embeddings: embeddings - custom_nodes: config/comfy/custom_nodes + unet: models/unet + upscale_models: | + models/RealESRGAN + models/ESRGAN + models/SwinIR + models/GFPGAN + 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 02/20] 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 f20063c99..124149908 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 5d94433b4..2fc68e3bc 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 4684b5a0a..89ce95847 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 000000000..d6f144f15 --- /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 000000000..086c9e002 --- /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 000000000..3500eb5cd --- /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 000000000..0ed85e7cc --- /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 03/20] 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 124149908..a68d087bf 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 2fc68e3bc..345681897 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 3500eb5cd..091bb63cf 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 000000000..9d8fc9ff0 --- /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 000000000..34e001b88 --- /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 04/20] 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 83073ea2b..000000000 --- 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 c973e68dc..2f449c762 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 712a6face..617545d25 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 05/20] 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 617545d25..186423926 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 5143c1bb9..d007e95eb 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 89ce95847..783c5d1ca 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 9d8fc9ff0..b328c65a0 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 -WORKDIR ${SWARM_PATH} +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 -USER swarmui +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" +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 000000000..fde270856 --- /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 34e001b88..168881c12 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 06/20] 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 186423926..38253f6d4 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 783c5d1ca..af625f1a8 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 000000000..c290e5eaf --- /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 000000000..c88b9e659 --- /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 07/20] 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 2f449c762..a753ea1e5 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 38253f6d4..f93126948 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 af625f1a8..7128ef5c0 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 c88b9e659..7a4420d3b 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 b328c65a0..37ab81720 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 fde270856..4e667aeea 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 168881c12..f73c98a7b 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 000000000..c290e5eaf --- /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 000000000..7a4420d3b --- /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 08/20] 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 f93126948..bb740c5fb 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 7128ef5c0..340029d98 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 4ef41c89f..a0fce2b88 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 d6f144f15..000000000 --- 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 086c9e002..000000000 --- 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 091bb63cf..000000000 --- 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 0ed85e7cc..000000000 --- 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 37ab81720..0919d64b0 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 f73c98a7b..9ed20fd7c 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 09/20] Update swarmui --- services/swarmui/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index 0919d64b0..f2ca9ed24 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 From dfde056a225671f15c0d83a35402b38955c9638b Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Sun, 30 Nov 2025 03:38:39 +0100 Subject: [PATCH 10/20] Update comfyui image & add ai toolkit --- .gitignore | 1 + docker-compose.yml | 28 +++++++ services/ai-toolkit/Dockerfile | 7 ++ services/ai-toolkit/entrypoint.sh | 7 ++ services/comfy/Dockerfile | 121 ++++++++++++++++++++++++++++-- 5 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 services/ai-toolkit/Dockerfile create mode 100644 services/ai-toolkit/entrypoint.sh diff --git a/.gitignore b/.gitignore index 9d34c3ff5..4eaf90080 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /.vscode .idea TODO.md +*.env diff --git a/docker-compose.yml b/docker-compose.yml index bb740c5fb..c8ee8c076 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,6 +77,8 @@ services: container_name: comfy build: ./services/comfy image: sd-comfy:latest +# command: +# - python main.py --preview-method auto --force-fp16 volumes: - ./data/models:/opt/comfyui/models - ./data/config/configs:/opt/comfyui/user/default/ @@ -145,3 +147,29 @@ services: image: sd-fooocus:latest environment: - CLI_ARGS= + + ai-toolkit: + <<: *base_service + profiles: [ "ai-toolkit" ] + container_name: ai-toolkit + build: ./services/ai-toolkit + image: sd-aitoolkit:latest + ports: + - "8675:8675" + volumes: + - ./data/.cache/huggingface/hub:/root/.cache/huggingface/hub +# - ./data/aitk_db.db:/app/ai-toolkit/aitk_db.db + - ./data/datasets:/app/ai-toolkit/datasets + - ./data/config/ai-toolkit:/app/ai-toolkit/config + - ./data/models:/app/ai-toolkit/models + - ./output/ai-toolkit:/app/ai-toolkit/output + environment: + - AI_TOOLKIT_AUTH=${AI_TOOLKIT_AUTH:-password} + - NODE_ENV=production + - TZ=UTC + secrets: + - my_secret + +secrets: + my_secret: + file: ./services/ai-toolkit/secret.env diff --git a/services/ai-toolkit/Dockerfile b/services/ai-toolkit/Dockerfile new file mode 100644 index 000000000..1c9f5d209 --- /dev/null +++ b/services/ai-toolkit/Dockerfile @@ -0,0 +1,7 @@ +FROM ostris/aitoolkit:latest + +ADD --chmod=755 entrypoint.sh /docker/ + +ENTRYPOINT ["/bin/bash", "/docker/entrypoint.sh"] +CMD ["/start.sh"] + diff --git a/services/ai-toolkit/entrypoint.sh b/services/ai-toolkit/entrypoint.sh new file mode 100644 index 000000000..ebd5981b5 --- /dev/null +++ b/services/ai-toolkit/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# get envs files and export envars +export $(egrep -v '^#' /run/secrets/* | xargs) +# if need some specific file, where password is the secret name +# export $(egrep -v '^#' /run/secrets/password| xargs) +# call the dockerfile's entrypoint +source /start.sh diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 340029d98..c0268e665 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,7 +1,9 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.59 -ARG COMFYUI_MANAGER_VERSION=3.35 -ARG PYTORCH_VERSION=2.8.0-cuda12.9-cudnn9-runtime +ARG COMFYUI_VERSION=v0.3.71 +#ARG COMFYUI_MANAGER_VERSION=3.35 +ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel +# number of CPU's use for compilation +ARG CPUS=10 # This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch FROM pytorch/pytorch:${PYTORCH_VERSION} @@ -17,7 +19,42 @@ RUN apt update --assume-yes && \ libglib2.0-0 \ libsm6 \ libxext6 \ - ffmpeg && \ + autoconf \ + automake \ + cmake \ + git-core \ + libass-dev \ + libfreetype6-dev \ + libgnutls28-dev \ + libmp3lame-dev \ + libsdl2-dev \ + libtool \ + libva-dev \ + libvdpau-dev \ + libvorbis-dev \ + libxcb1-dev \ + libxcb-shm0-dev \ + libxcb-xfixes0-dev \ + meson \ + ninja-build \ + pkg-config \ + texinfo \ + wget \ + yasm \ + zlib1g-dev \ + nasm \ + libunistring-dev \ + libaom-dev \ + libx265-dev \ + libx264-dev \ + libnuma-dev \ + libfdk-aac-dev \ + libc6 \ + libc6-dev \ + unzip \ + libnuma1 \ +# ffmpeg \ + && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -34,9 +71,10 @@ RUN git clone --depth=1 https://github.com/comfyanonymous/ComfyUI.git /opt/comfy # 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 + cd /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 \ @@ -47,8 +85,75 @@ RUN pip3 install --no-cache-dir \ opencv-python \ diffusers \ triton \ + torchsde \ + nvidia-ml-py \ sageattention \ - psutil + flash-attention \ + psutil \ + nvitop + +# compile ffmpeg +RUN mkdir -p ~/ffmpeg_sources ~/bin && \ + cd ~/ffmpeg_sources && \ + wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \ + tar xjvf ffmpeg-snapshot.tar.bz2 && \ + cd ffmpeg && \ + PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ + --prefix="$HOME/ffmpeg_build" \ + --pkg-config-flags="--static" \ + --extra-cflags="-I$HOME/ffmpeg_build/include" \ + --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ + --extra-libs="-lpthread -lm" \ + --ld="g++" \ + --bindir="$HOME/bin" \ + --enable-gpl \ + --enable-gnutls \ + --enable-libass \ + --enable-libfdk-aac \ + --enable-libfreetype \ + --enable-libmp3lame \ + --enable-libx264 \ + --enable-libx265 \ + --enable-nonfree && \ + PATH="$HOME/bin:$PATH" make -j $CPUS && \ + make install && \ + hash -r + +# install ffmpeg-nvidia adapter +RUN mkdir ~/nv && cd ~/nv && \ + git clone https://github.com/FFmpeg/nv-codec-headers.git && \ + cd nv-codec-headers && make install + +# compile ffmpeg with cuda +RUN cd ~/nv && \ + git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ && \ + cd ffmpeg && \ + ./configure \ + --enable-nonfree \ + --enable-nvenc \ + --enable-cuda \ + --enable-cuda-nvcc \ + --enable-cuvid \ + --extra-cflags=-I/usr/local/cuda/include \ + --extra-ldflags=-L/usr/local/cuda/lib64 \ + --disable-static \ + --enable-gpl \ + --enable-gnutls \ + --enable-shared \ + --enable-libaom \ + --enable-libass \ + --enable-libfdk-aac \ + --enable-libfreetype \ + --enable-libmp3lame \ + --enable-libvorbis \ + --enable-libx264 \ + --enable-libx265 \ +# --enable-libnpp \ # ERROR: libnpp support is deprecated, version 13.0 and up are not supported \ +# --enable-libopus \ # not found : install ? +# --enable-libvpx \ + && \ + make -j $CPUS && \ + make install # Pre-install previously used custom nodes requirements from volume COPY ./install/merged-requirements.txt* /docker/requirements.txt From 7776180f12a909e85315cc13425539dcbe331bbd Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Wed, 10 Dec 2025 00:36:58 +0100 Subject: [PATCH 11/20] Update comfyui image --- README.md | 5 + docker-compose.yml | 1 + services/comfy/Dockerfile | 214 +++++++++++++++++++++++++- services/comfy/requirements-build.txt | 11 ++ services/comfy/requirements.txt | 20 +++ 5 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 services/comfy/requirements-build.txt create mode 100644 services/comfy/requirements.txt diff --git a/README.md b/README.md index a753ea1e5..c75439bac 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ Run Stable Diffusion on your machine with a nice UI without any hassle! Visit the wiki for [Setup](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Setup) and [Usage](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Usage) instructions, checkout the [FAQ](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/FAQ) page if you face any problems, or create a new issue! +``` +docker compose --profile comfy up --build +docker compose --progress=plain --profile=comfy up --build +``` + ## Features This repository provides multiple UIs for you to play around with stable diffusion: diff --git a/docker-compose.yml b/docker-compose.yml index c8ee8c076..93d6320ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -82,6 +82,7 @@ services: volumes: - ./data/models:/opt/comfyui/models - ./data/config/configs:/opt/comfyui/user/default/ + - ./data/config/comfyui_manager/:/opt/comfyui/user/__manager/ - ./data/config/comfy/custom_nodes:/opt/comfyui/custom_nodes - ./output/comfy:/opt/comfyui/output ports: diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index c0268e665..4862127d0 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,13 +1,188 @@ +############################################################################### +# Stage 0 — CUDA-enabled development base +# This replaces NVIDIA's cuda:-devel images for dev builds. +############################################################################### +FROM ubuntu:22.04 AS cuda-dev-base + +# Non-interactive apt + NVIDIA environment variables +ENV DEBIAN_FRONTEND=noninteractive +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVARCH=x86_64 +ENV CUDA_VERSION=12.4.1 +ENV PYTORCH_VERSION=2.6.0 + +# Core development tools +RUN apt-get update -qq && apt-get install -y --no-install-recommends \ + build-essential \ + gnupg2 \ + curl \ + ca-certificates \ + wget \ + software-properties-common \ + && rm -rf /var/lib/apt/lists/* + +# Add NVIDIA CUDA repo key +RUN curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/${NVARCH}/cuda-keyring_1.1-1_all.deb \ + -o cuda-keyring.deb \ + && dpkg -i cuda-keyring.deb \ + && rm cuda-keyring.deb + +# NVIDIA repo pinning (recommended) +RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/${NVARCH}/cuda-ubuntu2204.pin \ + && mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600 + +# CUDA 12.4 toolkit + libraries +RUN apt-get update -qq && apt-get install -y --no-install-recommends \ + cuda-cudart-12-4 \ + cuda-compiler-12-4 \ + cuda-libraries-12-4 \ + cuda-libraries-dev-12-4 \ + cuda-compat-12-4 \ + && rm -rf /var/lib/apt/lists/* + +# Other dev helpers +RUN apt-get update -qq && apt-get install -y --no-install-recommends \ + cmake \ + git \ + && rm -rf /var/lib/apt/lists/* + +# CUDA environment setup +ENV CUDA_HOME="/usr/local/cuda" +ENV PATH="${CUDA_HOME}/bin:${PATH}" +#ENV LD_LIBRARY_PATH="${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}" + +############################################################################### +# Stage 1 — dev-base (now built on top of your cuda-dev-base) +# Adds PyTorch build prerequisites, ccache, image libs, etc. +############################################################################### +FROM cuda-dev-base AS dev-base + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ccache \ + libjpeg-dev \ + libpng-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN /usr/sbin/update-ccache-symlinks +RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache + +ENV PATH=/opt/conda/bin:$PATH + +############################################################################### +# Stage 2 — Conda install (unchanged) +############################################################################### +FROM dev-base AS conda +ARG PYTHON_VERSION=3.11 +ARG TARGETPLATFORM + +RUN case ${TARGETPLATFORM} in \ + "linux/arm64") MINICONDA_ARCH=aarch64 ;; \ + *) MINICONDA_ARCH=x86_64 ;; \ + esac \ + && curl -fsSL -o ~/miniconda.sh \ + "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${MINICONDA_ARCH}.sh" + +COPY requirements.txt requirements-build.txt ./ + +RUN chmod +x ~/miniconda.sh \ + && bash ~/miniconda.sh -b -p /opt/conda \ + && rm ~/miniconda.sh \ + && /opt/conda/bin/conda install -y \ + python=${PYTHON_VERSION} \ + cmake conda-build pyyaml numpy ipython \ + && /opt/conda/bin/python -m pip install -r requirements.txt \ + && /opt/conda/bin/conda clean -ya + +############################################################################### +# Stage 3 — Fetch submodules +############################################################################### +FROM dev-base AS submodule-update +ARG PYTORCH_VERSION +RUN git clone https://github.com/pytorch/pytorch.git /opt/pytorch && \ + cd /opt/pytorch && \ + git fetch origin v${PYTORCH_VERSION} && \ + git checkout FETCH_HEAD +WORKDIR /opt/pytorch +RUN git submodule update --init --recursive + +############################################################################### +# Stage 4 — Install PyTorch from wheels into Conda +############################################################################### +FROM conda AS conda-installs +ARG CONDA_VERSION=25.7.0 +ARG CUDA_PATH=cu124 +ARG INSTALL_CHANNEL=whl +ARG CUDA_VERSION +ARG TARGETPLATFORM + +RUN /opt/conda/bin/conda install -y python=${PYTHON_VERSION} conda=${CONDA_VERSION} + +RUN case ${TARGETPLATFORM} in \ + "linux/arm64") \ + pip install --extra-index-url https://download.pytorch.org/whl/cpu/ \ + "torch==${PYTORCH_VERSION}" torchvision torchaudio ;; \ + *) \ + pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ \ + "torch==${PYTORCH_VERSION}" torchvision torchaudio ;; \ + esac \ + && /opt/conda/bin/conda clean -ya + +RUN /opt/conda/bin/pip install torchelastic + +RUN IS_CUDA=$(python -c "import torch; print(torch.cuda._is_compiled())"); \ + echo "CUDA Enabled: $IS_CUDA"; \ + if [ "$IS_CUDA" != "True" ] && [ -n "${CUDA_VERSION}" ]; then exit 1; fi + +############################################################################### +# Stage 5 — Official Runtime image (remains Ubuntu-only) +############################################################################### +FROM conda-installs AS official +ARG PYTORCH_VERSION +ARG TRITON_VERSION +ARG TARGETPLATFORM +ARG CUDA_VERSION + +LABEL com.nvidia.volumes.needed="nvidia_driver" + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates libjpeg-dev libpng-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN if [ -n "${TRITON_VERSION}" ] && [ "${TARGETPLATFORM}" != "linux/arm64" ]; then \ + apt-get update && apt-get install -y gcc; \ + rm -rf /var/lib/apt/lists/*; \ + fi + +ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${CUDA_HOME}/lib64:${LD_LIBRARY_PATH} +ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH +ENV PYTORCH_VERSION=${PYTORCH_VERSION} + +WORKDIR /workspace + +############################################################################### +# Stage 6 — Dev image (inherits CUDA 12.4 from your base) +############################################################################### +FROM official AS dev + +COPY --from=conda /opt/conda /opt/conda +COPY --from=submodule-update /opt/pytorch /opt/pytorch + +############################################################################### +# Stage 7 — ComfyUI image +############################################################################### + +FROM dev +# This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch +#ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel +#FROM pytorch/pytorch:${PYTORCH_VERSION} + # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.71 +ARG COMFYUI_VERSION=v0.3.76 #ARG COMFYUI_MANAGER_VERSION=3.35 -ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel # number of CPU's use for compilation ARG CPUS=10 -# 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 update --assume-yes && \ @@ -81,17 +256,40 @@ RUN pip install \ --requirement /opt/comfyui/requirements.txt \ --requirement /opt/comfyui-manager/requirements.txt -RUN pip3 install --no-cache-dir \ +RUN pip install --no-cache-dir \ opencv-python \ + opencv-contrib-python \ diffusers \ triton \ torchsde \ nvidia-ml-py \ sageattention \ - flash-attention \ + packaging \ + ninja \ + compel \ psutil \ nvitop +ENV TORCH_CUDA_ARCH_LIST="8.0;8.6;8.9;9.0" + +# PyTorch include/lib for ABI correctness +ENV CFLAGS="-I/opt/conda/lib/python3.11/site-packages/torch/include \ + -I/opt/conda/lib/python3.11/site-packages/torch/include/torch/csrc/api/include \ + -I/opt/conda/lib/python3.11/site-packages/torch/include/TH \ + -I/opt/conda/lib/python3.11/site-packages/torch/include/THC" + +ENV CXXFLAGS="${CFLAGS}" +ENV LDFLAGS="-L/opt/conda/lib/python3.11/site-packages/torch/lib" + +# NVCC compatibility flags for CUDA 12.4 + GCC 11 (Ubuntu 22.04) +ENV NVCCFLAGS="--threads=4 -Xcompiler -Wno-float-conversion" + +ARG FLASH_ATTENTION_VERSION=2.5.9.post1 +ARG GPU_ARCHS=native +ARG MAX_JOBS=4 +RUN GPU_ARCHS=${GPU_ARCHS} MAX_JOBS=${MAX_JOBS} pip install --no-cache-dir --no-build-isolation \ + "flash-attn==${FLASH_ATTENTION_VERSION}" --verbose + # compile ffmpeg RUN mkdir -p ~/ffmpeg_sources ~/bin && \ cd ~/ffmpeg_sources && \ @@ -165,7 +363,7 @@ 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 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/requirements-build.txt b/services/comfy/requirements-build.txt new file mode 100644 index 000000000..85923ae39 --- /dev/null +++ b/services/comfy/requirements-build.txt @@ -0,0 +1,11 @@ +# Build System requirements +setuptools>=70.1.0 +cmake>=3.27 +ninja +numpy +packaging +pyyaml +requests +six # dependency chain: NNPACK -> PeachPy -> six +typing-extensions>=4.10.0 +pip # not technically needed, but this makes setup.py invocation work diff --git a/services/comfy/requirements.txt b/services/comfy/requirements.txt new file mode 100644 index 000000000..e9b5d4482 --- /dev/null +++ b/services/comfy/requirements.txt @@ -0,0 +1,20 @@ +# Python dependencies required for development + +# Build System requirements +--requirement requirements-build.txt + +# Install / Development extra requirements +build[uv] # for building sdist and wheel +expecttest>=0.3.0 +filelock +fsspec>=0.8.5 +hypothesis +jinja2 +lintrunner ; platform_machine != "s390x" and platform_machine != "riscv64" +networkx>=2.5.1 +optree>=0.13.0 +psutil +spin +sympy>=1.13.3 +typing-extensions>=4.13.2 +wheel From 7c069d12c45d1250bdb2dbbbc7a8f48f239a5135 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Tue, 23 Dec 2025 05:02:32 +0100 Subject: [PATCH 12/20] Update comfyui image --- services/comfy/Dockerfile | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 4862127d0..ec4dcc2c8 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -178,7 +178,7 @@ FROM dev #FROM pytorch/pytorch:${PYTORCH_VERSION} # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.76 +ARG COMFYUI_VERSION=v0.5.1 #ARG COMFYUI_MANAGER_VERSION=3.35 # number of CPU's use for compilation ARG CPUS=10 @@ -284,39 +284,13 @@ ENV LDFLAGS="-L/opt/conda/lib/python3.11/site-packages/torch/lib" # NVCC compatibility flags for CUDA 12.4 + GCC 11 (Ubuntu 22.04) ENV NVCCFLAGS="--threads=4 -Xcompiler -Wno-float-conversion" +# install flash-attention ARG FLASH_ATTENTION_VERSION=2.5.9.post1 ARG GPU_ARCHS=native ARG MAX_JOBS=4 RUN GPU_ARCHS=${GPU_ARCHS} MAX_JOBS=${MAX_JOBS} pip install --no-cache-dir --no-build-isolation \ "flash-attn==${FLASH_ATTENTION_VERSION}" --verbose -# compile ffmpeg -RUN mkdir -p ~/ffmpeg_sources ~/bin && \ - cd ~/ffmpeg_sources && \ - wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \ - tar xjvf ffmpeg-snapshot.tar.bz2 && \ - cd ffmpeg && \ - PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ - --prefix="$HOME/ffmpeg_build" \ - --pkg-config-flags="--static" \ - --extra-cflags="-I$HOME/ffmpeg_build/include" \ - --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ - --extra-libs="-lpthread -lm" \ - --ld="g++" \ - --bindir="$HOME/bin" \ - --enable-gpl \ - --enable-gnutls \ - --enable-libass \ - --enable-libfdk-aac \ - --enable-libfreetype \ - --enable-libmp3lame \ - --enable-libx264 \ - --enable-libx265 \ - --enable-nonfree && \ - PATH="$HOME/bin:$PATH" make -j $CPUS && \ - make install && \ - hash -r - # install ffmpeg-nvidia adapter RUN mkdir ~/nv && cd ~/nv && \ git clone https://github.com/FFmpeg/nv-codec-headers.git && \ From 0b607e72a3d66ad6ef5888a1d4bd6a1493efa103 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Tue, 13 Jan 2026 04:01:26 +0100 Subject: [PATCH 13/20] Update comfyui image --- services/comfy/Dockerfile | 4 ++- services/swarmui/Dockerfile | 36 ++++++++++++++++--------- services/swarmui/comfy-install-linux.sh | 9 ++++--- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index ec4dcc2c8..3de868646 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -178,7 +178,7 @@ FROM dev #FROM pytorch/pytorch:${PYTORCH_VERSION} # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.5.1 +ARG COMFYUI_VERSION=v0.8.2 #ARG COMFYUI_MANAGER_VERSION=3.35 # number of CPU's use for compilation ARG CPUS=10 @@ -300,6 +300,8 @@ RUN mkdir ~/nv && cd ~/nv && \ RUN cd ~/nv && \ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ && \ cd ffmpeg && \ + CFLAGS="-D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE -I/usr/local/cuda/include" \ + LDFLAGS="-L/usr/local/cuda/lib64" \ ./configure \ --enable-nonfree \ --enable-nvenc \ diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index f2ca9ed24..f320e1edb 100644 --- a/services/swarmui/Dockerfile +++ b/services/swarmui/Dockerfile @@ -1,6 +1,6 @@ ARG SWARMUI_VERSION=0.9.7-Beta -ARG COMFYUI_VERSION=v0.3.59 -ARG COMFYUI_MANAGER_VERSION=3.35 +ARG COMFYUI_VERSION=v0.8.2 +#ARG COMFYUI_MANAGER_VERSION=3.35 ARG DOTNET_VERSION=9.0-bookworm-slim #ARG DOTNET_VERSION=8.0-bookworm-slim ARG ASPNET_VERSION=9.0-bookworm-slim @@ -31,6 +31,9 @@ FROM mcr.microsoft.com/dotnet/aspnet:${ASPNET_VERSION} ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 +ENV USER_NAME="root" +#ENV USER="swarmui" +ENV GROUP_NAME="root" ARG SWARMUI_USER_ID=1000 ARG SWARMUI_GROUP_ID=1000 @@ -38,13 +41,15 @@ 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 +#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} +RUN mkdir -p "${SWARM_PATH}/Data" +RUN chown -R $(id -u):$(id -g) ${SWARM_PATH} +#RUN chown -R ${USER_NAME}:${GROUP_NAME} ${SWARM_PATH} +#RUN chown -R swarmui:swarmui ${SWARM_PATH} ENV HOME=${SWARM_PATH} RUN --mount=type=cache,target=/var/cache/apt \ @@ -68,15 +73,18 @@ RUN git clone --depth=1 https://github.com/comfyanonymous/ComfyUI.git /opt/comfy 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 + cd /opt/comfyui-manager +# cd /opt/comfyui-manager && \ +# git fetch origin ${COMFYUI_MANAGER_VERSION} && \ +# git checkout FETCH_HEAD WORKDIR ${SWARM_PATH} -RUN chown -R swarmui:swarmui /opt/comfyui +RUN chown -R $(id -u):$(id -g) /opt/comfyui +#RUN chown -R ${USER_NAME}:${GROUP_NAME} /opt/comfyui RUN git config --global --add safe.directory /opt/comfyui ENV COMFYUI_PATH="/SwarmUI/dlbackend/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 @@ -85,10 +93,14 @@ 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 # Reapplied again bc of permissions issues, maybe related to a symlink/docker/windows bug +RUN chown -R $(id -u):$(id -g) ${SWARM_PATH} +#RUN chown -R ${USER_NAME}:${GROUP_NAME} /opt/comfyui +#RUN chown -R swarmui:swarmui ${SWARM_PATH} # Reapplied again bc of permissions issues, maybe related to a symlink/docker/windows bug +#RUN chown -R swarmui:swarmui ${COMFYUI_PATH} # Reapplied again bc of permissions issues, maybe related to a symlink/docker/windows bug +#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}" -USER swarmui +#USER swarmui EXPOSE 7801 COPY entrypoint.sh / diff --git a/services/swarmui/comfy-install-linux.sh b/services/swarmui/comfy-install-linux.sh index 4e667aeea..5760cd1e6 100644 --- a/services/swarmui/comfy-install-linux.sh +++ b/services/swarmui/comfy-install-linux.sh @@ -82,11 +82,14 @@ fi echo "install general requirements..." $python -s -m pip install --no-cache-dir \ - triton \ - sageattention \ opencv-python \ diffusers \ - psutil + triton \ + torchsde \ + nvidia-ml-py \ + sageattention \ + psutil \ + nvitop # Installs the required Python packages for both ComfyUI and the ComfyUI Manager $python -s -m pip install --no-cache-dir \ From 32b8b5ae7e30d9ea0340b90a984122f94613266a Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:13:27 +0100 Subject: [PATCH 14/20] Update comfyui image (pytorch, cuda & flash-att2), reduce libs size & clean cache, fix user permissions & volumes --- docker-compose.yml | 12 +- services/comfy/Dockerfile | 474 ++++++++++---------------- services/comfy/entrypoint.sh | 19 +- services/comfy/extra_model_paths.yaml | 19 +- 4 files changed, 200 insertions(+), 324 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 93d6320ca..bef5b9205 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -75,21 +75,25 @@ services: <<: *base_service profiles: ["comfy"] container_name: comfy - build: ./services/comfy + build: + context: ./services/comfy/ + dockerfile: Dockerfile image: sd-comfy:latest + restart: no # command: # - python main.py --preview-method auto --force-fp16 volumes: - ./data/models:/opt/comfyui/models - - ./data/config/configs:/opt/comfyui/user/default/ - - ./data/config/comfyui_manager/:/opt/comfyui/user/__manager/ - ./data/config/comfy/custom_nodes:/opt/comfyui/custom_nodes + - ./data/config/comfy/user:/opt/comfyui/user - ./output/comfy:/opt/comfyui/output ports: - "${COMFYUI_PORT:-7861}:7861" environment: - COMFYUI_PATH=/opt/comfyui - COMFYUI_MODEL_PATH=/opt/comfyui/models + - USER_ID=1000 + - GROUP_ID=1000 - CLI_ARGS= # - TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1 @@ -124,6 +128,8 @@ services: environment: - COMFYUI_PATH=/opt/comfyui - COMFYUI_MODEL_PATH=/opt/comfyui/models +# - USER_ID=1000 +# - GROUP_ID=1000 reforge: &reforge <<: *base_service diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 3de868646..82c72a478 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,319 +1,74 @@ -############################################################################### -# Stage 0 — CUDA-enabled development base -# This replaces NVIDIA's cuda:-devel images for dev builds. -############################################################################### -FROM ubuntu:22.04 AS cuda-dev-base - -# Non-interactive apt + NVIDIA environment variables -ENV DEBIAN_FRONTEND=noninteractive -ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility -ENV NVIDIA_VISIBLE_DEVICES=all -ENV NVARCH=x86_64 -ENV CUDA_VERSION=12.4.1 -ENV PYTORCH_VERSION=2.6.0 - -# Core development tools -RUN apt-get update -qq && apt-get install -y --no-install-recommends \ - build-essential \ - gnupg2 \ - curl \ - ca-certificates \ - wget \ - software-properties-common \ - && rm -rf /var/lib/apt/lists/* - -# Add NVIDIA CUDA repo key -RUN curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/${NVARCH}/cuda-keyring_1.1-1_all.deb \ - -o cuda-keyring.deb \ - && dpkg -i cuda-keyring.deb \ - && rm cuda-keyring.deb - -# NVIDIA repo pinning (recommended) -RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/${NVARCH}/cuda-ubuntu2204.pin \ - && mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600 - -# CUDA 12.4 toolkit + libraries -RUN apt-get update -qq && apt-get install -y --no-install-recommends \ - cuda-cudart-12-4 \ - cuda-compiler-12-4 \ - cuda-libraries-12-4 \ - cuda-libraries-dev-12-4 \ - cuda-compat-12-4 \ - && rm -rf /var/lib/apt/lists/* - -# Other dev helpers -RUN apt-get update -qq && apt-get install -y --no-install-recommends \ - cmake \ - git \ - && rm -rf /var/lib/apt/lists/* - -# CUDA environment setup -ENV CUDA_HOME="/usr/local/cuda" -ENV PATH="${CUDA_HOME}/bin:${PATH}" -#ENV LD_LIBRARY_PATH="${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}" - -############################################################################### -# Stage 1 — dev-base (now built on top of your cuda-dev-base) -# Adds PyTorch build prerequisites, ccache, image libs, etc. -############################################################################### -FROM cuda-dev-base AS dev-base - -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ccache \ - libjpeg-dev \ - libpng-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN /usr/sbin/update-ccache-symlinks -RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache - -ENV PATH=/opt/conda/bin:$PATH - -############################################################################### -# Stage 2 — Conda install (unchanged) -############################################################################### -FROM dev-base AS conda -ARG PYTHON_VERSION=3.11 -ARG TARGETPLATFORM - -RUN case ${TARGETPLATFORM} in \ - "linux/arm64") MINICONDA_ARCH=aarch64 ;; \ - *) MINICONDA_ARCH=x86_64 ;; \ - esac \ - && curl -fsSL -o ~/miniconda.sh \ - "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${MINICONDA_ARCH}.sh" - -COPY requirements.txt requirements-build.txt ./ - -RUN chmod +x ~/miniconda.sh \ - && bash ~/miniconda.sh -b -p /opt/conda \ - && rm ~/miniconda.sh \ - && /opt/conda/bin/conda install -y \ - python=${PYTHON_VERSION} \ - cmake conda-build pyyaml numpy ipython \ - && /opt/conda/bin/python -m pip install -r requirements.txt \ - && /opt/conda/bin/conda clean -ya - -############################################################################### -# Stage 3 — Fetch submodules -############################################################################### -FROM dev-base AS submodule-update -ARG PYTORCH_VERSION -RUN git clone https://github.com/pytorch/pytorch.git /opt/pytorch && \ - cd /opt/pytorch && \ - git fetch origin v${PYTORCH_VERSION} && \ - git checkout FETCH_HEAD -WORKDIR /opt/pytorch -RUN git submodule update --init --recursive - -############################################################################### -# Stage 4 — Install PyTorch from wheels into Conda -############################################################################### -FROM conda AS conda-installs -ARG CONDA_VERSION=25.7.0 -ARG CUDA_PATH=cu124 -ARG INSTALL_CHANNEL=whl -ARG CUDA_VERSION -ARG TARGETPLATFORM - -RUN /opt/conda/bin/conda install -y python=${PYTHON_VERSION} conda=${CONDA_VERSION} - -RUN case ${TARGETPLATFORM} in \ - "linux/arm64") \ - pip install --extra-index-url https://download.pytorch.org/whl/cpu/ \ - "torch==${PYTORCH_VERSION}" torchvision torchaudio ;; \ - *) \ - pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ \ - "torch==${PYTORCH_VERSION}" torchvision torchaudio ;; \ - esac \ - && /opt/conda/bin/conda clean -ya - -RUN /opt/conda/bin/pip install torchelastic - -RUN IS_CUDA=$(python -c "import torch; print(torch.cuda._is_compiled())"); \ - echo "CUDA Enabled: $IS_CUDA"; \ - if [ "$IS_CUDA" != "True" ] && [ -n "${CUDA_VERSION}" ]; then exit 1; fi - -############################################################################### -# Stage 5 — Official Runtime image (remains Ubuntu-only) -############################################################################### -FROM conda-installs AS official -ARG PYTORCH_VERSION -ARG TRITON_VERSION -ARG TARGETPLATFORM -ARG CUDA_VERSION - -LABEL com.nvidia.volumes.needed="nvidia_driver" - -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates libjpeg-dev libpng-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN if [ -n "${TRITON_VERSION}" ] && [ "${TARGETPLATFORM}" != "linux/arm64" ]; then \ - apt-get update && apt-get install -y gcc; \ - rm -rf /var/lib/apt/lists/*; \ - fi - -ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${CUDA_HOME}/lib64:${LD_LIBRARY_PATH} -ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH -ENV PYTORCH_VERSION=${PYTORCH_VERSION} - -WORKDIR /workspace - -############################################################################### -# Stage 6 — Dev image (inherits CUDA 12.4 from your base) -############################################################################### -FROM official AS dev - -COPY --from=conda /opt/conda /opt/conda -COPY --from=submodule-update /opt/pytorch /opt/pytorch - -############################################################################### -# Stage 7 — ComfyUI image -############################################################################### - -FROM dev -# This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch -#ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel -#FROM pytorch/pytorch:${PYTORCH_VERSION} - -# Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.8.2 -#ARG COMFYUI_MANAGER_VERSION=3.35 -# number of CPU's use for compilation -ARG CPUS=10 +ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel +FROM pytorch/pytorch:${PYTORCH_VERSION} AS build +ARG COMFYUI_VERSION=v0.9.2 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 \ - autoconf \ - automake \ - cmake \ - git-core \ - libass-dev \ - libfreetype6-dev \ - libgnutls28-dev \ - libmp3lame-dev \ - libsdl2-dev \ - libtool \ - libva-dev \ - libvdpau-dev \ - libvorbis-dev \ - libxcb1-dev \ - libxcb-shm0-dev \ - libxcb-xfixes0-dev \ - meson \ - ninja-build \ - pkg-config \ - texinfo \ - wget \ - yasm \ - zlib1g-dev \ - nasm \ - libunistring-dev \ - libaom-dev \ - libx265-dev \ - libx264-dev \ - libnuma-dev \ - libfdk-aac-dev \ - libc6 \ - libc6-dev \ - unzip \ - libnuma1 \ -# ffmpeg \ +RUN python --version + +RUN apt update && apt install -y \ + build-essential \ + git \ + git-core \ + autoconf \ + automake \ + cmake \ + libtool \ + meson \ + ninja-build \ + pkg-config \ + texinfo \ + yasm \ + nasm \ + wget \ + unzip \ + \ + # FFmpeg / codec headers + libass-dev \ + libfreetype6-dev \ + libgnutls28-dev \ + libmp3lame-dev \ + libsdl2-dev \ + libva-dev \ + libvdpau-dev \ + libvorbis-dev \ + libxcb1-dev \ + libxcb-shm0-dev \ + libxcb-xfixes0-dev \ + libaom-dev \ + libx264-dev \ + libx265-dev \ + libfdk-aac-dev \ + libnuma-dev \ + libssl-dev \ + libunistring-dev \ + zlib1g-dev \ + libc6-dev \ + \ + ca-certificates \ && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# 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 - -# 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 -# 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 pip install --no-cache-dir \ - opencv-python \ - opencv-contrib-python \ - diffusers \ - triton \ - torchsde \ - nvidia-ml-py \ - sageattention \ - packaging \ - ninja \ - compel \ - psutil \ - nvitop - -ENV TORCH_CUDA_ARCH_LIST="8.0;8.6;8.9;9.0" - -# PyTorch include/lib for ABI correctness -ENV CFLAGS="-I/opt/conda/lib/python3.11/site-packages/torch/include \ - -I/opt/conda/lib/python3.11/site-packages/torch/include/torch/csrc/api/include \ - -I/opt/conda/lib/python3.11/site-packages/torch/include/TH \ - -I/opt/conda/lib/python3.11/site-packages/torch/include/THC" - -ENV CXXFLAGS="${CFLAGS}" -ENV LDFLAGS="-L/opt/conda/lib/python3.11/site-packages/torch/lib" - -# NVCC compatibility flags for CUDA 12.4 + GCC 11 (Ubuntu 22.04) -ENV NVCCFLAGS="--threads=4 -Xcompiler -Wno-float-conversion" - -# install flash-attention -ARG FLASH_ATTENTION_VERSION=2.5.9.post1 -ARG GPU_ARCHS=native -ARG MAX_JOBS=4 -RUN GPU_ARCHS=${GPU_ARCHS} MAX_JOBS=${MAX_JOBS} pip install --no-cache-dir --no-build-isolation \ - "flash-attn==${FLASH_ATTENTION_VERSION}" --verbose - # install ffmpeg-nvidia adapter RUN mkdir ~/nv && cd ~/nv && \ git clone https://github.com/FFmpeg/nv-codec-headers.git && \ cd nv-codec-headers && make install # compile ffmpeg with cuda +ARG CPUS=10 RUN cd ~/nv && \ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ && \ cd ffmpeg && \ - CFLAGS="-D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE -I/usr/local/cuda/include" \ - LDFLAGS="-L/usr/local/cuda/lib64" \ ./configure \ + --enable-gpl \ --enable-nonfree \ - --enable-nvenc \ - --enable-cuda \ + --enable-shared \ --enable-cuda-nvcc \ + --enable-nvenc \ + --enable-nvdec \ --enable-cuvid \ - --extra-cflags=-I/usr/local/cuda/include \ - --extra-ldflags=-L/usr/local/cuda/lib64 \ - --disable-static \ --enable-gpl \ --enable-gnutls \ - --enable-shared \ --enable-libaom \ --enable-libass \ --enable-libfdk-aac \ @@ -322,18 +77,128 @@ RUN cd ~/nv && \ --enable-libvorbis \ --enable-libx264 \ --enable-libx265 \ + --disable-static \ # --enable-libnpp \ # ERROR: libnpp support is deprecated, version 13.0 and up are not supported \ # --enable-libopus \ # not found : install ? # --enable-libvpx \ + --prefix=/usr/local \ + --extra-cflags="-I/usr/local/cuda/include" \ + --extra-ldflags="-L/usr/local/cuda/lib64" \ + --extra-libs="-lpthread -lm" \ && \ make -j $CPUS && \ - make install + make install && ldconfig + +# ------------------------------------------------------------ +# Setup ComfyUI & Manager +# ------------------------------------------------------------ +FROM pytorch/pytorch:${PYTORCH_VERSION} + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 +ENV PIP_NO_CACHE_DIR=1 + +RUN apt update --assume-yes && \ + apt install --assume-yes \ + git \ + wget \ + build-essential \ + ca-certificates \ + sudo \ + # OpenCV runtime + libgl1-mesa-glx \ + libgl1-mesa-dev \ + libglu1-mesa \ + freeglut3 \ + mesa-utils \ + libglib2.0-0 \ + libsm6 \ + libxext6 \ + libc6 \ + # FFmpeg runtime libs (NVENC-enabled ffmpeg binary copied in) + libass9 \ + libfreetype6 \ + libgnutls30 \ + libmp3lame0 \ + libvorbis0a \ + libx264-163 \ + libx265-199 \ + libfdk-aac2 \ + libxv1 \ + libva2 \ + libva-wayland2 \ + libva-x11-2 \ + libaom3 \ + libva-drm2 \ + libvdpau1 \ + # XCB runtime libraries + libxcb1 \ + libxcb-shape0 \ + libxcb-shm0 \ + libxcb-xfixes0 \ + # audio runtime + libasound2 \ + libasound2-plugins \ + libsndio7.0 \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=build /usr/local /usr/local + +# Version check +RUN python -c "import torch; print('Torch CUDA:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available())" +RUN ldd /usr/local/bin/ffmpeg | grep "not found" && exit 1 || true +RUN ldconfig && ffmpeg -encoders | grep nvenc + +RUN pip install --no-cache-dir \ + ffmpy \ + pillow \ + img2texture \ + PyOpenGL \ + PyOpenGL_accelerate \ + opencv-python \ + opencv-contrib-python \ + diffusers \ + triton \ + torchsde \ + nvidia-ml-py \ + sageattention \ + packaging \ + ninja \ + compel \ + psutil \ + nvitop \ + https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.11/flash_attn-2.8.3%2Bcu131torch2.9-cp311-cp311-linux_x86_64.whl + +# 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 + +# Clones the ComfyUI Manager repository; 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 +# 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 # 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."' +# Clean up +RUN rm -rf /root/.cache/pip + # Sets the working directory to the ComfyUI directory WORKDIR /opt/comfyui COPY . /docker/ @@ -341,6 +206,23 @@ RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml /opt/co ENV PYTHONPATH="\${PYTHONPATH}:\${PWD}" CLI_ARGS="" EXPOSE 7861 +ARG USER_ID +ARG GROUP_ID +RUN chown -R $USER_ID:$GROUP_ID /opt/conda +RUN chown -R $USER_ID:$GROUP_ID /opt/comfyui \ + && chmod -R u+rwx /opt/comfyui +RUN chown -R $USER_ID:$GROUP_ID /opt/comfyui-manager \ + && chmod -R u+rwx /opt/comfyui-manager +RUN mkdir -p /.cache \ + && chown -R $USER_ID:$GROUP_ID /.cache \ + && chmod -R u+rwx /.cache +RUN mkdir -p /.cache/uv \ + && chown -R $USER_ID:$GROUP_ID /.cache/uv \ + && chmod -R u+rwx /.cache/uv +RUN mkdir -p /.config \ + && chown -R $USER_ID:$GROUP_ID /.config \ + && chmod -R u+rwx /.config +USER $USER_ID # 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 diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index aee8a09f8..03c4eda09 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -56,16 +56,17 @@ done # 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..." + echo "Running container as root" 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 "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 +# sudo --set-home --preserve-env=PATH --user \#$USER_ID "$@" - echo "Running container as $USER..." - sudo --set-home --preserve-env=PATH --user \#$USER_ID "$@" + echo "Running container as $USER_ID:$GROUP_ID" + exec "$@" fi diff --git a/services/comfy/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index a0fce2b88..1c16e867d 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -1,10 +1,7 @@ a111: base_path: /opt/comfyui -# base_path: /data - checkpoints: models/Stable-diffusion configs: user/default -# configs: models/configs vae: models/VAE loras: | models/Lora @@ -14,21 +11,11 @@ a111: gligen: models/GLIGEN clip: models/CLIPEncoder embeddings: embeddings - unet: models/unet - upscale_models: | - models/RealESRGAN - models/ESRGAN - models/SwinIR - models/GFPGAN - models/upscale_models + upscale_models: models/upscale_models diffusion_models: models/diffusion_models text_encoders: models/text_encoders clip_vision: models/clip_vision + diffusers: models/diffusers + style_models: models/style_models 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 - # diffusers: config/comfy/diffusers From 5ce4cdd4db9db178db8233c963bb6fb797b427c8 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Thu, 22 Jan 2026 03:36:00 +0100 Subject: [PATCH 15/20] Fix ffmpeg libs --- .gitignore | 1 + services/comfy/Dockerfile | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4eaf90080..5fe42110a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ .idea TODO.md *.env +*.old diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 82c72a478..63dd2f1e3 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -62,7 +62,6 @@ RUN cd ~/nv && \ ./configure \ --enable-gpl \ --enable-nonfree \ - --enable-shared \ --enable-cuda-nvcc \ --enable-nvenc \ --enable-nvdec \ @@ -77,7 +76,11 @@ RUN cd ~/nv && \ --enable-libvorbis \ --enable-libx264 \ --enable-libx265 \ - --disable-static \ + --enable-static \ + --disable-shared \ + --pkg-config-flags="--static" \ +# --disable-static \ +# --enable-shared \ # --enable-libnpp \ # ERROR: libnpp support is deprecated, version 13.0 and up are not supported \ # --enable-libopus \ # not found : install ? # --enable-libvpx \ From 36051c6f38c483e6d29234d6aecdd4718d34cf3b Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Fri, 30 Jan 2026 08:51:57 +0100 Subject: [PATCH 16/20] Update comfyui v0.11.1 --- services/comfy/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 63dd2f1e3..bd3ecbb3f 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,7 +1,7 @@ ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel FROM pytorch/pytorch:${PYTORCH_VERSION} AS build -ARG COMFYUI_VERSION=v0.9.2 +ARG COMFYUI_VERSION=v0.11.1 ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 RUN python --version From 64a5f1576e47da109cfb4ec0f4bec96312f96a0b Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:39:12 +0100 Subject: [PATCH 17/20] Update image (pin versions, reduce lib size), fix requirements pre-scripts --- README.md | 3 - services/comfy/Dockerfile | 307 +++++++++++++++++++++------- services/comfy/entrypoint.sh | 2 +- services/comfy/install/install.sh | 3 +- services/comfy/requirements.txt | 2 +- services/swarmui/install/install.sh | 3 +- 6 files changed, 236 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index c75439bac..8063094a5 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,6 @@ supports: - reforge - 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 Run Stable Diffusion on your machine with a nice UI without any hassle! diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index bd3ecbb3f..06b3bf3b8 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,28 +1,176 @@ -ARG PYTORCH_VERSION=2.9.1-cuda13.0-cudnn9-devel -FROM pytorch/pytorch:${PYTORCH_VERSION} AS build +# syntax=docker/dockerfile:1 -ARG COMFYUI_VERSION=v0.11.1 -ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -RUN python --version +# NOTE: Building this image require's docker version >= 23.0. +# +# For reference: +# - https://docs.docker.com/build/dockerfile/frontend/#stable-channel -RUN apt update && apt install -y \ - build-essential \ - git \ - git-core \ - autoconf \ - automake \ - cmake \ - libtool \ - meson \ - ninja-build \ +ARG BASE_IMAGE=ubuntu:24.04 + +FROM ${BASE_IMAGE} as dev-base + +ENV BASE_VERSION=2404 +ARG PYTHON_VERSION=3.11.10 +ARG PYTORCH_VERSION=2.10.0 +ARG CUDA_VERSION=12.8 +ARG CUDA_PATH=cu128 +ARG COMFYUI_VERSION=0.12.0 + +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 PIP_NO_CACHE_DIR=1 +ENV PYENV_ROOT=/root/.pyenv +ENV PATH=${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH} + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + ccache \ + cmake \ + curl \ + git \ + libjpeg-dev \ + libpng-dev \ + # pyenv / python build deps + libssl-dev \ + zlib1g-dev \ + libbz2-dev \ + libreadline-dev \ + libsqlite3-dev \ + libffi-dev \ + liblzma-dev \ + tk-dev \ + xz-utils \ + llvm \ + && rm -rf /var/lib/apt/lists/* + +# Install pyenv +RUN git clone https://github.com/pyenv/pyenv.git ${PYENV_ROOT} + +# Install Python 3.11 +RUN pyenv install ${PYTHON_VERSION} && \ + pyenv global ${PYTHON_VERSION} && \ + python --version + +# Remove PEP 668 restriction (safe in containers) +RUN rm -f /usr/lib/python*/EXTERNALLY-MANAGED +RUN /usr/sbin/update-ccache-symlinks +RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache +RUN pip install --upgrade pip + +FROM dev-base as python-deps + +COPY requirements.txt requirements-build.txt ./ +# Install Python packages to system Python +RUN pip install --upgrade --ignore-installed pip setuptools wheel && \ + pip install cmake pyyaml numpy ipython -r requirements.txt + +FROM dev-base as submodule-update + +ARG PYTORCH_VERSION +RUN git clone https://github.com/pytorch/pytorch.git /opt/pytorch && \ + cd /opt/pytorch && \ + git fetch origin v${PYTORCH_VERSION} && \ + git checkout FETCH_HEAD +WORKDIR /opt/pytorch +RUN git submodule update --init --recursive + +FROM python-deps as pytorch-installs + +ARG CUDA_PATH +ARG INSTALL_CHANNEL=whl/nightly +# Automatically set by buildx +ARG TARGETPLATFORM + +# INSTALL_CHANNEL whl - release, whl/nightly - nightly, whl/test - test channels +RUN case ${TARGETPLATFORM} in \ + "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchaudio ;; \ + *) pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ torch torchvision torchaudio ;; \ + esac +RUN pip install torchelastic +RUN IS_CUDA=$(python3 -c 'import torch ; print(torch.cuda._is_compiled())'); \ + echo "Is torch compiled with cuda: ${IS_CUDA}"; \ + if test "${IS_CUDA}" != "True" -a ! -z "${CUDA_VERSION}"; then \ + exit 1; \ + fi + +FROM dev-base as official + +ARG PYTORCH_VERSION +ARG TRITON_VERSION +ARG TARGETPLATFORM +ARG CUDA_VERSION +LABEL com.nvidia.volumes.needed="nvidia_driver" +ENV PYENV_ROOT=/root/.pyenv +ENV PATH=${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH} + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + libjpeg-dev \ + libpng-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy pyenv + Python runtime + site-packages +COPY --from=pytorch-installs /root/.pyenv /root/.pyenv +RUN python --version && pip --version + +RUN if test -n "${CUDA_VERSION}" -a "${TARGETPLATFORM}" != "linux/arm64"; then \ + apt-get update -qq && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gcc && \ + rm -rf /var/lib/apt/lists/*; \ + fi +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES compute,utility +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH +ENV PYTORCH_VERSION ${PYTORCH_VERSION} +WORKDIR /workspace + +FROM official as dev +ARG CUDA_VERSION +ARG BUILD_TYPE=dev + +# Install CUDA toolkit +RUN apt-get update && apt-get install -y --no-install-recommends \ + wget gnupg2 ca-certificates && \ + # Add NVIDIA repository + NVARCH=$(uname -m | sed 's/x86_64/x86_64/' | sed 's/aarch64/sbsa/') && \ + wget -qO - https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${BASE_VERSION}/${NVARCH}/3bf863cc.pub | apt-key add - && \ + echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${BASE_VERSION}/${NVARCH} /" > /etc/apt/sources.list.d/cuda.list && \ + # Install CUDA toolkit + CUDA_PKG_VERSION=$(echo ${CUDA_VERSION} | cut -d'.' -f1,2 | tr '.' '-') && \ + apt-get update && apt-get install -y --no-install-recommends \ + cuda-toolkit-${CUDA_PKG_VERSION} && \ + apt-get clean && rm -rf /var/lib/apt/lists/* && \ + # Configure LD + echo "/usr/local/cuda/lib64" >> /etc/ld.so.conf.d/cuda.conf && \ + ldconfig + +# Set CUDA environment (always set, needed even if CUDA already in base) +ENV PATH=/usr/local/cuda/bin:${PATH} +ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH} +ENV CUDA_HOME=/usr/local/cuda + +COPY --from=submodule-update /opt/pytorch /opt/pytorch + +# ------------------------------------------------------------ +# Build ffmpeg +# ------------------------------------------------------------ +FROM dev as ffmpeg + +#RUN cat /etc/os-release +#RUN python --version + +RUN apt update --assume-yes && \ + apt install --assume-yes \ pkg-config \ - texinfo \ - yasm \ nasm \ - wget \ - unzip \ - \ - # FFmpeg / codec headers +# autoconf \ +# automake \ +# libtool \ +# meson \ +# ninja-build \ +# texinfo \ +# yasm \ +# # FFmpeg / codec headers libass-dev \ libfreetype6-dev \ libgnutls28-dev \ @@ -43,8 +191,6 @@ RUN apt update && apt install -y \ libunistring-dev \ zlib1g-dev \ libc6-dev \ - \ - ca-certificates \ && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -79,11 +225,6 @@ RUN cd ~/nv && \ --enable-static \ --disable-shared \ --pkg-config-flags="--static" \ -# --disable-static \ -# --enable-shared \ -# --enable-libnpp \ # ERROR: libnpp support is deprecated, version 13.0 and up are not supported \ -# --enable-libopus \ # not found : install ? -# --enable-libvpx \ --prefix=/usr/local \ --extra-cflags="-I/usr/local/cuda/include" \ --extra-ldflags="-L/usr/local/cuda/lib64" \ @@ -95,56 +236,67 @@ RUN cd ~/nv && \ # ------------------------------------------------------------ # Setup ComfyUI & Manager # ------------------------------------------------------------ -FROM pytorch/pytorch:${PYTORCH_VERSION} +FROM dev as comfy -ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -ENV PIP_NO_CACHE_DIR=1 - -RUN apt update --assume-yes && \ - apt install --assume-yes \ - git \ +RUN apt-get update --assume-yes && \ + apt-get install --assume-yes \ + sudo \ wget \ + unzip \ + cmake \ build-essential \ - ca-certificates \ - sudo \ - # OpenCV runtime - libgl1-mesa-glx \ - libgl1-mesa-dev \ - libglu1-mesa \ - freeglut3 \ - mesa-utils \ - libglib2.0-0 \ - libsm6 \ - libxext6 \ - libc6 \ - # FFmpeg runtime libs (NVENC-enabled ffmpeg binary copied in) - libass9 \ - libfreetype6 \ - libgnutls30 \ - libmp3lame0 \ - libvorbis0a \ - libx264-163 \ - libx265-199 \ - libfdk-aac2 \ +# libssl-dev \ +# libbz2-dev \ +# libffi-dev \ +# libncursesw5-dev \ +# libreadline-dev \ +# libsqlite3-dev \ +# liblzma-dev \ +# # OpenCV runtime +## libgl1-mesa-glx \ +# libgl1 \ +# libglx-mesa0 \ +# libgl1-mesa-dev \ +# libglu1-mesa \ +## freeglut3 \ +# freeglut3-dev \ +# mesa-utils \ +# libglib2.0-0 \ +# libsm6 \ +# libxext6 \ +# libc6 \ +# # FFmpeg runtime libs (NVENC-enabled ffmpeg binary copied in) +# libfreetype6 \ +# libgnutls30 \ +# libva-wayland2 \ +# # XCB runtime libraries +# libxcb1 \ +# libxcb-shape0 \ +# libxcb-shm0 \ +# libxcb-xfixes0 \ +# # audio runtime +## libasound2 \ +# libasound2t64 \ +# libasound2-plugins \ + libsndio7.0 \ libxv1 \ + libass9 \ libva2 \ - libva-wayland2 \ - libva-x11-2 \ - libaom3 \ libva-drm2 \ + libva-x11-2 \ libvdpau1 \ - # XCB runtime libraries - libxcb1 \ - libxcb-shape0 \ - libxcb-shm0 \ - libxcb-xfixes0 \ - # audio runtime - libasound2 \ - libasound2-plugins \ - libsndio7.0 \ - && rm -rf /var/lib/apt/lists/* + libaom3 \ + libfdk-aac2 \ + libmp3lame0 \ + libvorbis0a \ + libvorbisenc2 \ + libx264-164 \ + libx265-199 \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* -COPY --from=build /usr/local /usr/local +COPY --from=ffmpeg /usr/local /usr/local # Version check RUN python -c "import torch; print('Torch CUDA:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available())" @@ -152,13 +304,12 @@ RUN ldd /usr/local/bin/ffmpeg | grep "not found" && exit 1 || true RUN ldconfig && ffmpeg -encoders | grep nvenc RUN pip install --no-cache-dir \ + comfy-env \ ffmpy \ pillow \ img2texture \ PyOpenGL \ PyOpenGL_accelerate \ - opencv-python \ - opencv-contrib-python \ diffusers \ triton \ torchsde \ @@ -169,12 +320,13 @@ RUN pip install --no-cache-dir \ compel \ psutil \ nvitop \ - https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.11/flash_attn-2.8.3%2Bcu131torch2.9-cp311-cp311-linux_x86_64.whl +# https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.11/flash_attn-2.8.3%2Bcu131torch2.9-cp311-cp311-linux_x86_64.whl + https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.8.3%2Bcu128torch2.10-cp311-cp311-linux_x86_64.whl # 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 fetch origin v${COMFYUI_VERSION} && \ git checkout FETCH_HEAD # Clones the ComfyUI Manager repository; ComfyUI Manager is an extension for ComfyUI that enables users to install @@ -190,12 +342,13 @@ RUN git clone --depth=1 https://github.com/Comfy-Org/ComfyUI-Manager.git /opt/co # git checkout FETCH_HEAD # Installs the required Python packages for both ComfyUI and the ComfyUI Manager -RUN pip install \ +RUN pip install --no-cache-dir \ --requirement /opt/comfyui/requirements.txt \ --requirement /opt/comfyui-manager/requirements.txt # Pre-install previously used custom nodes requirements from volume COPY ./install/merged-requirements.txt* /docker/requirements.txt +# TODO fix onnx 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."' @@ -211,7 +364,7 @@ ENV PYTHONPATH="\${PYTHONPATH}:\${PWD}" CLI_ARGS="" EXPOSE 7861 ARG USER_ID ARG GROUP_ID -RUN chown -R $USER_ID:$GROUP_ID /opt/conda +RUN chown -R $USER_ID:$GROUP_ID $PYENV_ROOT RUN chown -R $USER_ID:$GROUP_ID /opt/comfyui \ && chmod -R u+rwx /opt/comfyui RUN chown -R $USER_ID:$GROUP_ID /opt/comfyui-manager \ @@ -235,4 +388,4 @@ 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"] +CMD ["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 03c4eda09..3c01e2fe2 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -45,7 +45,7 @@ do 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" + pip install --no-cache-dir --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt" fi fi done diff --git a/services/comfy/install/install.sh b/services/comfy/install/install.sh index 7a4420d3b..632834b3a 100644 --- a/services/comfy/install/install.sh +++ b/services/comfy/install/install.sh @@ -8,9 +8,10 @@ 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 {} + \ +find ${BUILD_PATH}/reqs -maxdepth 1 -name "*requirements.txt" -exec sh -c 'cat "$1"; echo' _ {} \; \ | grep -v '^#' \ | grep -v '^git' \ + | grep -Ev 'platform_system|platform_machine|sys_platform|google|onnx|opencv-python-headless\[ffmpeg\]' \ | sed 's/==.*//' \ | awk '{print tolower($0)}' \ | sed 's/[[:space:]]//g' \ diff --git a/services/comfy/requirements.txt b/services/comfy/requirements.txt index e9b5d4482..8cc2f17fa 100644 --- a/services/comfy/requirements.txt +++ b/services/comfy/requirements.txt @@ -16,5 +16,5 @@ optree>=0.13.0 psutil spin sympy>=1.13.3 -typing-extensions>=4.13.2 +typing-extensions>=4.15.0 wheel diff --git a/services/swarmui/install/install.sh b/services/swarmui/install/install.sh index 7a4420d3b..234425d51 100644 --- a/services/swarmui/install/install.sh +++ b/services/swarmui/install/install.sh @@ -8,9 +8,10 @@ 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 {} + \ +find ${BUILD_PATH}/reqs -maxdepth 1 -name "*requirements.txt" -exec sh -c 'cat "$1"; echo' _ {} \; \ | grep -v '^#' \ | grep -v '^git' \ + | grep -Ev 'platform_system|platform_machine|sys_platform|google|onnx|opencv-python-headless[ffmpeg]' \ | sed 's/==.*//' \ | awk '{print tolower($0)}' \ | sed 's/[[:space:]]//g' \ From d70698cec00e2ca0e6327446bf472ee4373d4827 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:43:07 +0100 Subject: [PATCH 18/20] Clean --- services/comfy/Dockerfile | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 06b3bf3b8..476a267b1 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -29,7 +29,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ git \ libjpeg-dev \ libpng-dev \ - # pyenv / python build deps libssl-dev \ zlib1g-dev \ libbz2-dev \ @@ -245,39 +244,6 @@ RUN apt-get update --assume-yes && \ unzip \ cmake \ build-essential \ -# libssl-dev \ -# libbz2-dev \ -# libffi-dev \ -# libncursesw5-dev \ -# libreadline-dev \ -# libsqlite3-dev \ -# liblzma-dev \ -# # OpenCV runtime -## libgl1-mesa-glx \ -# libgl1 \ -# libglx-mesa0 \ -# libgl1-mesa-dev \ -# libglu1-mesa \ -## freeglut3 \ -# freeglut3-dev \ -# mesa-utils \ -# libglib2.0-0 \ -# libsm6 \ -# libxext6 \ -# libc6 \ -# # FFmpeg runtime libs (NVENC-enabled ffmpeg binary copied in) -# libfreetype6 \ -# libgnutls30 \ -# libva-wayland2 \ -# # XCB runtime libraries -# libxcb1 \ -# libxcb-shape0 \ -# libxcb-shm0 \ -# libxcb-xfixes0 \ -# # audio runtime -## libasound2 \ -# libasound2t64 \ -# libasound2-plugins \ libsndio7.0 \ libxv1 \ libass9 \ @@ -320,7 +286,6 @@ RUN pip install --no-cache-dir \ compel \ psutil \ nvitop \ -# https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.11/flash_attn-2.8.3%2Bcu131torch2.9-cp311-cp311-linux_x86_64.whl https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.8.3%2Bcu128torch2.10-cp311-cp311-linux_x86_64.whl # Clones the ComfyUI repository and checks out the latest release @@ -348,7 +313,6 @@ RUN pip install --no-cache-dir \ # Pre-install previously used custom nodes requirements from volume COPY ./install/merged-requirements.txt* /docker/requirements.txt -# TODO fix onnx 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."' From 524b504c84a895266bd032a0b342d4213c3aba58 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:14:13 +0100 Subject: [PATCH 19/20] Clean & refactor --- services/comfy/Dockerfile | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 476a267b1..394849388 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -5,6 +5,9 @@ # For reference: # - https://docs.docker.com/build/dockerfile/frontend/#stable-channel +# ------------------------------------------------------------ +# Pytorch +# ------------------------------------------------------------ ARG BASE_IMAGE=ubuntu:24.04 FROM ${BASE_IMAGE} as dev-base @@ -55,6 +58,7 @@ RUN /usr/sbin/update-ccache-symlinks RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache RUN pip install --upgrade pip +# ------------------------------------------------------------ FROM dev-base as python-deps COPY requirements.txt requirements-build.txt ./ @@ -62,6 +66,7 @@ COPY requirements.txt requirements-build.txt ./ RUN pip install --upgrade --ignore-installed pip setuptools wheel && \ pip install cmake pyyaml numpy ipython -r requirements.txt +# ------------------------------------------------------------ FROM dev-base as submodule-update ARG PYTORCH_VERSION @@ -72,6 +77,7 @@ RUN git clone https://github.com/pytorch/pytorch.git /opt/pytorch && \ WORKDIR /opt/pytorch RUN git submodule update --init --recursive +# ------------------------------------------------------------ FROM python-deps as pytorch-installs ARG CUDA_PATH @@ -91,6 +97,7 @@ RUN IS_CUDA=$(python3 -c 'import torch ; print(torch.cuda._is_compiled())'); \ exit 1; \ fi +# ------------------------------------------------------------ FROM dev-base as official ARG PYTORCH_VERSION @@ -123,6 +130,9 @@ ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH ENV PYTORCH_VERSION ${PYTORCH_VERSION} WORKDIR /workspace +# ------------------------------------------------------------ +# CUDA +# ------------------------------------------------------------ FROM official as dev ARG CUDA_VERSION ARG BUILD_TYPE=dev @@ -148,28 +158,18 @@ ENV PATH=/usr/local/cuda/bin:${PATH} ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH} ENV CUDA_HOME=/usr/local/cuda +# Copy pytorch COPY --from=submodule-update /opt/pytorch /opt/pytorch # ------------------------------------------------------------ -# Build ffmpeg +# ffmpeg # ------------------------------------------------------------ FROM dev as ffmpeg -#RUN cat /etc/os-release -#RUN python --version - RUN apt update --assume-yes && \ apt install --assume-yes \ pkg-config \ nasm \ -# autoconf \ -# automake \ -# libtool \ -# meson \ -# ninja-build \ -# texinfo \ -# yasm \ -# # FFmpeg / codec headers libass-dev \ libfreetype6-dev \ libgnutls28-dev \ @@ -233,10 +233,13 @@ RUN cd ~/nv && \ make install && ldconfig # ------------------------------------------------------------ -# Setup ComfyUI & Manager +# ComfyUI & Manager # ------------------------------------------------------------ FROM dev as comfy +# Copy ffmpeg +COPY --from=ffmpeg /usr/local /usr/local + RUN apt-get update --assume-yes && \ apt-get install --assume-yes \ sudo \ @@ -262,9 +265,7 @@ RUN apt-get update --assume-yes && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -COPY --from=ffmpeg /usr/local /usr/local - -# Version check +# Version & libs check RUN python -c "import torch; print('Torch CUDA:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available())" RUN ldd /usr/local/bin/ffmpeg | grep "not found" && exit 1 || true RUN ldconfig && ffmpeg -encoders | grep nvenc From 8ff9f4a26a4eb01bf1837f13211d23d0faf2fce9 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Sat, 7 Mar 2026 01:36:22 +0100 Subject: [PATCH 20/20] Fix torch libs & upscale_models path --- services/comfy/Dockerfile | 61 +++++++++++++++------------ services/comfy/extra_model_paths.yaml | 6 ++- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 394849388..afc23a0c2 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -10,14 +10,15 @@ # ------------------------------------------------------------ ARG BASE_IMAGE=ubuntu:24.04 -FROM ${BASE_IMAGE} as dev-base +FROM ${BASE_IMAGE} AS dev-base ENV BASE_VERSION=2404 ARG PYTHON_VERSION=3.11.10 ARG PYTORCH_VERSION=2.10.0 +ARG TORCHVISION_VERSION=0.25.0 ARG CUDA_VERSION=12.8 ARG CUDA_PATH=cu128 -ARG COMFYUI_VERSION=0.12.0 +ARG COMFYUI_VERSION=0.16.3 ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 PIP_NO_CACHE_DIR=1 ENV PYENV_ROOT=/root/.pyenv @@ -59,7 +60,7 @@ RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache RUN pip install --upgrade pip # ------------------------------------------------------------ -FROM dev-base as python-deps +FROM dev-base AS python-deps COPY requirements.txt requirements-build.txt ./ # Install Python packages to system Python @@ -67,7 +68,7 @@ RUN pip install --upgrade --ignore-installed pip setuptools wheel && \ pip install cmake pyyaml numpy ipython -r requirements.txt # ------------------------------------------------------------ -FROM dev-base as submodule-update +FROM dev-base AS submodule-update ARG PYTORCH_VERSION RUN git clone https://github.com/pytorch/pytorch.git /opt/pytorch && \ @@ -78,17 +79,24 @@ WORKDIR /opt/pytorch RUN git submodule update --init --recursive # ------------------------------------------------------------ -FROM python-deps as pytorch-installs +FROM python-deps AS pytorch-installs ARG CUDA_PATH -ARG INSTALL_CHANNEL=whl/nightly +ARG INSTALL_CHANNEL=whl +#ARG INSTALL_CHANNEL=whl/nightly # Automatically set by buildx ARG TARGETPLATFORM # INSTALL_CHANNEL whl - release, whl/nightly - nightly, whl/test - test channels RUN case ${TARGETPLATFORM} in \ - "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchaudio ;; \ - *) pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ torch torchvision torchaudio ;; \ + "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ \ + torch==${PYTORCH_VERSION}+${CUDA_PATH} \ + torchvision==${TORCHVISION_VERSION}+${CUDA_PATH} \ + torchaudio==${PYTORCH_VERSION}+${CUDA_PATH} ;; \ + *) pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ \ + torch==${PYTORCH_VERSION}+${CUDA_PATH} \ + torchvision==${TORCHVISION_VERSION}+${CUDA_PATH} \ + torchaudio==${PYTORCH_VERSION}+${CUDA_PATH} ;; \ esac RUN pip install torchelastic RUN IS_CUDA=$(python3 -c 'import torch ; print(torch.cuda._is_compiled())'); \ @@ -98,7 +106,7 @@ RUN IS_CUDA=$(python3 -c 'import torch ; print(torch.cuda._is_compiled())'); \ fi # ------------------------------------------------------------ -FROM dev-base as official +FROM dev-base AS official ARG PYTORCH_VERSION ARG TRITON_VERSION @@ -123,17 +131,17 @@ RUN if test -n "${CUDA_VERSION}" -a "${TARGETPLATFORM}" != "linux/arm64"; then \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gcc && \ rm -rf /var/lib/apt/lists/*; \ fi -ENV NVIDIA_VISIBLE_DEVICES all -ENV NVIDIA_DRIVER_CAPABILITIES compute,utility -ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 -ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH -ENV PYTORCH_VERSION ${PYTORCH_VERSION} +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility +ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64 +ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH +ENV PYTORCH_VERSION=${PYTORCH_VERSION} WORKDIR /workspace # ------------------------------------------------------------ # CUDA # ------------------------------------------------------------ -FROM official as dev +FROM official AS dev ARG CUDA_VERSION ARG BUILD_TYPE=dev @@ -164,7 +172,7 @@ COPY --from=submodule-update /opt/pytorch /opt/pytorch # ------------------------------------------------------------ # ffmpeg # ------------------------------------------------------------ -FROM dev as ffmpeg +FROM dev AS ffmpeg RUN apt update --assume-yes && \ apt install --assume-yes \ @@ -235,7 +243,7 @@ RUN cd ~/nv && \ # ------------------------------------------------------------ # ComfyUI & Manager # ------------------------------------------------------------ -FROM dev as comfy +FROM dev AS comfy # Copy ffmpeg COPY --from=ffmpeg /usr/local /usr/local @@ -266,7 +274,7 @@ RUN apt-get update --assume-yes && \ rm -rf /var/lib/apt/lists/* # Version & libs check -RUN python -c "import torch; print('Torch CUDA:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available())" +RUN python -c "import torch; import torchaudio; print('Torch:', torch.__version__); print('Audio:', torchaudio.__version__); print('CUDA:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available())" RUN ldd /usr/local/bin/ffmpeg | grep "not found" && exit 1 || true RUN ldconfig && ffmpeg -encoders | grep nvenc @@ -317,16 +325,8 @@ 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."' -# Clean up +# Clean up & permissions RUN rm -rf /root/.cache/pip - -# 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 PYTHONPATH="\${PYTHONPATH}:\${PWD}" CLI_ARGS="" -EXPOSE 7861 ARG USER_ID ARG GROUP_ID RUN chown -R $USER_ID:$GROUP_ID $PYENV_ROOT @@ -343,6 +343,13 @@ RUN mkdir -p /.cache/uv \ RUN mkdir -p /.config \ && chown -R $USER_ID:$GROUP_ID /.config \ && chmod -R u+rwx /.config + +# 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 PYTHONPATH="\${PYTHONPATH}:\${PWD}" CLI_ARGS="" +EXPOSE 7861 USER $USER_ID # 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/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index 1c16e867d..f001fdbce 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -12,7 +12,11 @@ a111: clip: models/CLIPEncoder embeddings: embeddings unet: models/unet - upscale_models: models/upscale_models + upscale_models: | + models/upscale_models + models/upscale_models/RealESRGAN + models/upscale_models/SwinIR + models/upscale_models/GFPGAN diffusion_models: models/diffusion_models text_encoders: models/text_encoders clip_vision: models/clip_vision