Compare commits

9 Commits

Author SHA1 Message Date
lainedfles
1fccee32b0 Merge a282e3cf5b into 802d0bcd68 2024-11-25 04:53:47 +00:00
Self Denial
a282e3cf5b fix: Correct directory change command in entrypoint.sh
This commit fixes an issue in the `entrypoint.sh` script where the directory was not being changed back to its original location after running the model download script for Krita. The `cd ..` command has been replaced with `cd -`, which correctly returns to the previous working directory, ensuring that subsequent commands in the script are executed from the expected path. This change prevents potential errors and ensures the script behaves as intended.
2024-11-24 21:53:35 -07:00
Self Denial
ed02c136f0 refactor: Improve error handling and consistency in entrypoint script
This commit refactors the `entrypoint.sh` script to enhance error handling and ensure consistent use of quotes around variables. Specifically:

1. **Error Handling**: Added `set +e` before `git pull` commands within the loop for updating custom nodes, allowing the script to continue processing other nodes even if one fails. This is followed by `set -e` to revert to strict error handling.

2. **Consistent Quoting**: Ensured that all variables are quoted consistently throughout the script to prevent issues with spaces or special characters in file paths.

3. **Command Placement**: Moved the model download command for Krita after checking and creating symbolic links, ensuring that models are downloaded into the correct directory structure.

4. **Use of `cp -a` Instead of `mv`**: Changed the use of `mv` to `cp -a` when copying custom nodes to preserve file attributes and avoid accidental deletion of source files.

These changes improve the robustness and reliability of the script, making it more resilient to errors and ensuring that all operations are performed correctly.
2024-11-24 21:50:04 -07:00
Self Denial
ba5ecaa941 fix: Ensure correct directory after creating symbolic link in entrypoint.sh
This commit addresses an issue where the script did not change back to the original directory after creating a symbolic link. By adding `&& cd ..` at the end of the `ln -sfT /data/models/upscale_models upscale_models` command, we ensure that the working directory remains consistent and expected for subsequent operations in the script. This fix prevents potential errors or unexpected behavior due to an incorrect current working directory.
2024-11-24 19:05:54 -07:00
Self Denial
1ba0fa8546 feat: Enhance ComfyUI Dockerfile with additional features and configurations
This commit significantly enhances the `Dockerfile` for the ComfyUI service by introducing several new features and configurations. Here's a detailed breakdown of the changes:

1. **Base Image Update**:
   - Updated the base image from `pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime` to `pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime`. This ensures compatibility with newer versions of PyTorch and CUDA, providing better performance and support for recent hardware.

2. **Environment Variables**:
   - Introduced several new environment variables (`USE_UID`, `USE_GID`, `USE_USER`, `USE_GROUP`) to allow customization of the user and group IDs within the container.
   - Added flags (`USE_EDGE`, `USE_GGUF`, `USE_XFLUX`, `USE_CNAUX`, `USE_KRITA`, `USE_IPAPLUS`, `USE_INPAINT`, `USE_TOOLING`) to enable or disable optional features and integrations.

3. **User/Group Management**:
   - Added logic to create a user and group with specified IDs (`USE_UID` and `USE_GID`). This is useful for running the container in environments where specific user permissions are required.
   - Set default values for these variables, ensuring that the Dockerfile remains functional without explicit configuration.

4. **Optional Feature Integration**:
   - Included conditional logic to clone and install additional repositories based on the flags set (`USE_GGUF`, `USE_XFLUX`, `USE_CNAUX`, `USE_KRITA`, `USE_IPAPLUS`, `USE_INPAINT`, `USE_TOOLING`). This allows users to customize their ComfyUI installation by enabling only the features they need.
   - Ensured that dependencies for these optional features are installed correctly, including handling specific cases like separating ONNX Runtime installations to restore CUDA support.

5. **Python Version Update**:
   - Changed the Python command from `python` to `python3` in the CMD instruction to explicitly specify the use of Python 3, which is a best practice for clarity and compatibility.

6. **File Permissions and Ownership**:
   - Used `--chown=${USE_UID}:${USE_GID}` when copying files into the container to ensure that the correct user owns these files, preventing permission issues during execution.

7. **General Improvements**:
   - Improved readability and maintainability of the Dockerfile by organizing the steps logically and adding comments where necessary.
   - Ensured that all commands are idempotent, meaning they can be run multiple times without causing unintended side effects.

- `USE_UID`: Specifies the user ID for the non-root user within the container. Default is set to value 0.
- `USE_GID`: Specifies the group ID for the non-root user within the container. Default is set to value like 0.
- `USE_USER`: Specifies the username for the non-root user within the container. Default is set to `root`.
- `USE_GROUP`: Specifies the group name for the non-root user within the container. Default is set to `root`.
- `USE_EDGE`: If set to `true`, clones and installs the latest development version of ComfyUI from the main branch.
- `USE_GGUF`: If set to `true`, clones and installs the ComfyUI-GGUF extension for GPU acceleration.
- `USE_XFLUX`: If set to `true`, clones and installs the x-flux-comfyui extension for additional functionalities.
- `USE_CNAUX`: If set to `true`, clones and installs the comfyui_controlnet_aux extension for control net auxiliary features.
- `USE_KRITA`: If set to `true`, clones and installs multiple extensions (comfyui_controlnet_aux, ComfyUI_IPAdapter_plus, comfyui-inpaint-nodes, comfyui-tooling-nodes) that are useful when integrating with Krita.
- `USE_IPAPLUS`: If set to `true`, clones and installs the ComfyUI_IPAdapter_plus extension for IP Adapter functionalities.
- `USE_INPAINT`: If set to `true`, clones and installs the comfyui-inpaint-nodes extension for inpainting capabilities.
- `USE_TOOLING`: If set to `true`, clones and installs the comfyui-tooling-nodes extension for additional tooling features.

These ARGs provide flexibility in configuring the Docker container, allowing users to tailor the ComfyUI installation to their specific needs.
2024-11-24 18:29:16 -07:00
Self Denial
eceac3ce5f feat: Add custom node management and additional configuration options in entrypoint.sh
This commit introduces several enhancements to the `entrypoint.sh` script for the Comfy service:

1. **Custom Node Management**: Added logic to update custom nodes located in `/data/config/comfy/custom_nodes/`. If the `UPDATE_CUSTOM_NODES` environment variable is set to `true`, it will pull the latest changes from each node's Git repository and update submodules recursively for specific nodes like `krita-ai-diffusion`.

2. **Environment Variable Usage**: Introduced a new environment variable `CACHE` which should be used instead of hardcoding `/root/.cache`. This makes the script more flexible and configurable.

3. **Krita Integration**: Added support for Krita integration with ComfyUI, including downloading models if `KRITA_DOWNLOAD_MODELS` is set to `true`, managing upscale models, and setting up symbolic links for model directories.

4. **GGUF, XFLUX, CNAUX, IPAPLUS, INPAINT, TOOLING Support**: Included logic to handle additional custom nodes (`ComfyUI-GGUF`, `x-flux-comfyui`, `comfyui_controlnet_aux`, `ComfyUI_IPAdapter_plus`, `comfyui-inpaint-nodes`, `comfyui-tooling-nodes`) based on their respective environment variables (`USE_GGUF`, `USE_XFLUX`, `USE_CNAUX`, `USE_IPAPLUS`, `USE_INPAINT`, `USE_TOOLING`). These nodes are moved to the custom nodes directory if they don't already exist.

5. **Model Management**: Added functionality to download and manage specific models required by certain integrations, such as CLIP Vision and IP Adapters for XFLUX.

These changes enhance the script's flexibility, making it easier to integrate additional features and manage dependencies dynamically based on environment configurations.
2024-11-24 16:34:53 -07:00
Self Denial
2de99033e8 feat: Add new model paths to extra_model_paths.yaml
This commit introduces several new model paths to the `extra_model_paths.yaml` file under the `a111` section. The added paths include `unet`, `clip_vision`, `xlabs`, `inpaint`, and `ipadapter`. These additions enhance the configuration by providing more options for different models, which can be utilized in various functionalities within the service.
2024-11-24 16:32:41 -07:00
Self Denial
e68863099d chore: Add .env to .gitignore and create initial .env file
This commit introduces a new `.env` file for environment variable management and updates the `.gitignore` file to ensure that this sensitive configuration file is not tracked by version control. This change helps maintain security by preventing accidental exposure of environment-specific settings in the repository.
2024-11-24 16:18:20 -07:00
Self Denial
edcd949867 chore: Add .env file support to docker-compose
This commit introduces the use of an `.env` file for environment variable management across all defined services in the `docker-compose.yml`. By adding `env_file: .env`, each service will now load environment variables from a local `.env` file, enhancing configuration flexibility and security. This change ensures that sensitive information or common settings can be centralized and easily managed without hardcoding them into the Docker Compose file.
2024-11-24 16:12:33 -07:00
6 changed files with 158 additions and 13 deletions

0
.env Normal file
View File

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
/.devcontainer
/docker-compose.override.yml
/.env
# VSCode specific
*.code-workspace

View File

@@ -6,6 +6,7 @@ x-base_service: &base_service
- &v2 ./output:/output
stop_signal: SIGKILL
tty: true
env_file: .env
deploy:
resources:
reservations:
@@ -30,6 +31,7 @@ services:
image: sd-auto:78
environment:
- CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api
env_file: .env
auto-cpu:
<<: *automatic
@@ -37,6 +39,7 @@ services:
deploy: {}
environment:
- CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api
env_file: .env
comfy: &comfy
<<: *base_service
@@ -45,6 +48,7 @@ services:
image: sd-comfy:7
environment:
- CLI_ARGS=
env_file: .env
comfy-cpu:
@@ -53,3 +57,4 @@ services:
deploy: {}
environment:
- CLI_ARGS=--cpu
env_file: .env

View File

@@ -1,22 +1,108 @@
FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime
FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1
# Limited system user UID
ARG USE_UID=0
# Limited system user GID
ARG USE_GID=0
# System user name
ARG USE_USER=root
# System group name
ARG USE_GROUP=root
# Latest tag or bleeding edge commit
ARG USE_EDGE=false
# ComfyUI-GGUF
ARG USE_GGUF=false
# x-flux-comfyui
ARG USE_XFLUX=false
# comfyui_controlnet_aux
ARG USE_CNAUX=false
# krita-ai-diffusion
ARG USE_KRITA=false
# ComfyUI_IPAdapter_plus
ARG USE_IPAPLUS=false
# comfyui-inpaint-nodes
ARG USE_INPAINT=false
# comfyui-tooling-nodes
ARG USE_TOOLING=false
RUN apt-get update && apt-get install -y git && apt-get clean
ENV USE_CNAUX=$USE_CNAUX USE_IPAPLUS=$USE_IPAPLUS
ENV USE_INPAINT=$USE_INPAINT USE_TOOLING=$USE_TOOLING
ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 USE_EDGE=$USE_EDGE
ENV USE_GGUF=$USE_GGUF USE_XFLUX=$USE_XFLUX ROOT=/stable-diffusion
ENV CACHE=/home/$USE_USER/.cache USE_KRITA=$USE_KRITA
ENV ROOT=/stable-diffusion
RUN --mount=type=cache,target=/root/.cache/pip \
RUN mkdir -p ${ROOT} ${CACHE}/pip /home/${USE_USER}
# User/Group
RUN if [ ${USE_GID} -ne 0 ]; then \
groupadd -r ${USE_GROUP} -g ${USE_GID}; \
fi; \
if [ ${USE_GID} -ne 0 ]; then \
useradd --no-log-init -m -r -g ${USE_GROUP} ${USE_USER} -u ${USE_UID}; \
fi; \
chown -R ${USE_UID}:${USE_GID} ${ROOT} ${CACHE} /home/${USE_USER}
RUN apt-get update && apt-get install -y git python3-pip
RUN if [ "${USE_XFLUX}" = "true" ] || [ "${USE_KRITA}" = "true" ] || [ "${USE_CNAUX}" = "true" ]; then \
apt-get install -y libgl1-mesa-glx python3-opencv; \
fi
RUN apt-get clean
USER ${USE_USER}:${USE_GROUP}
ENV PATH="${PATH}:/home/${USE_USER}/.local/bin"
RUN --mount=type=cache,uid=${USE_UID},gid=${USE_GID},target=${CACHE} pip --cache-dir=${CACHE}/pip install -U pip
RUN --mount=type=cache,uid=${USE_UID},gid=${USE_GID},target=${CACHE} \
git clone https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \
cd ${ROOT} && \
git checkout master && \
git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \
pip install -r requirements.txt
bash -c 'VERSION=$(git describe --tags --abbrev=0) && \
if [ "${USE_EDGE}" = "true" ]; then VERSION=$(git describe --abbrev=7); fi && \
git reset --hard ${VERSION}' && \
pip --cache-dir=${CACHE}/pip install -r requirements.txt && \
if [ "${USE_KRITA}" = "true" ]; then \
git clone https://github.com/Acly/krita-ai-diffusion.git && \
cd krita-ai-diffusion && git checkout main && \
git submodule update --init && \
pip --cache-dir=${CACHE}/pip install aiohttp tqdm && cd ..; \
fi; \
if [ "${USE_GGUF}" = "true" ]; then \
git clone https://github.com/city96/ComfyUI-GGUF.git && \
cd ComfyUI-GGUF && git checkout main && \
pip --cache-dir=${CACHE}/pip install -r requirements.txt && cd ..; \
fi; \
if [ "${USE_XFLUX}" = "true" ]; then \
git clone https://github.com/XLabs-AI/x-flux-comfyui.git && \
cd x-flux-comfyui && git checkout main && \
pip --cache-dir=${CACHE}/pip install -r requirements.txt && cd ..; \
fi; \
if [ "${USE_CNAUX}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then \
git clone https://github.com/Fannovel16/comfyui_controlnet_aux.git && \
cd comfyui_controlnet_aux && git checkout main && \
pip --cache-dir=${CACHE}/pip install -r requirements.txt && \
# This extra step to separate onnxruntime installation is required to restore onnx cuda support \
pip --cache-dir=${CACHE}/pip install onnxruntime && pip --cache-dir=${CACHE}/pip install onnxruntime-gpu && cd ..; \
fi; \
if [ "${USE_IPAPLUS}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then \
git clone https://github.com/cubiq/ComfyUI_IPAdapter_plus.git && \
cd ComfyUI_IPAdapter_plus && git checkout main && cd ..; \
fi; \
if [ "${USE_INPAINT}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then \
git clone https://github.com/Acly/comfyui-inpaint-nodes.git && \
cd comfyui-inpaint-nodes && git checkout main && \
pip --cache-dir=${CACHE}/pip install opencv-python && cd ..; \
fi; \
if [ "${USE_TOOLING}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then \
git clone https://github.com/Acly/comfyui-tooling-nodes.git && \
cd comfyui-tooling-nodes && git checkout main && cd ..; \
fi
WORKDIR ${ROOT}
COPY . /docker/
COPY --chown=${USE_UID}:${USE_GID} . /docker/
RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml ${ROOT}
ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS=""
EXPOSE 7860
ENTRYPOINT ["/docker/entrypoint.sh"]
CMD python -u main.py --listen --port 7860 ${CLI_ARGS}
CMD python3 -u main.py --listen --port 7860 ${CLI_ARGS}

View File

@@ -2,11 +2,12 @@
set -Eeuo pipefail
mkdir -vp /data/config/comfy/custom_nodes
CUSTOM_NODES="/data/config/comfy/custom_nodes"
mkdir -vp "${CUSTOM_NODES}"
declare -A MOUNTS
MOUNTS["/root/.cache"]="/data/.cache"
MOUNTS["${CACHE}"]="/data/.cache"
MOUNTS["${ROOT}/input"]="/data/config/comfy/input"
MOUNTS["${ROOT}/output"]="/output/comfy"
@@ -22,8 +23,56 @@ for to_path in "${!MOUNTS[@]}"; do
echo Mounted $(basename "${from_path}")
done
if [ "${UPDATE_CUSTOM_NODES:-false}" = "true" ]; then
find /data/config/comfy/custom_nodes/ -mindepth 1 -maxdepth 1 -type d | while read NODE
do echo "---- ${NODE##*/} ----"
set +e
cd "$NODE" && git pull; cd ..;
set -e
done
fi
if [ "${USE_KRITA}" = "true" ]; then
[ -d "${ROOT}/models/upscale_models" ] && rm -rf "${ROOT}/models/upscale_models"
if [ ! -L "${ROOT}/models/upscale_models" ]; then
cd "${ROOT}/models"
ln -sfT /data/models/upscale_models upscale_models && cd ..
fi
if [ "${KRITA_DOWNLOAD_MODELS:-false}" = "true" ]; then
cd "${ROOT}/krita-ai-diffusion/scripts" && python3 download_models.py --verbose --retry-attempts 10 --continue-on-error --recommended /data && cd -
fi
fi
if [ "${USE_GGUF}" = "true" ]; then
[ ! -e "${CUSTOM_NODES}/ComfyUI-GGUF" ] && cp -a "${ROOT}/ComfyUI-GGUF" "${CUSTOM_NODES}"/
fi
if [ "${USE_XFLUX}" = "true" ]; then
[ ! -e "${CUSTOM_NODES}/x-flux-comfyui" ] && cp -a "${ROOT}/x-flux-comfyui" "${CUSTOM_NODES}"/
[ ! -e "/data/models/clip_vision" ] && mkdir -p /data/models/clip_vision
[ ! -e "/data/models/clip_vision/model.safetensors" ] && cd /data/models/clip_vision && \
python3 -c 'import sys; from urllib.request import urlopen; from pathlib import Path; Path(sys.argv[2]).write_bytes(urlopen(sys.argv[1]).read())' \
"https://huggingface.co/openai/clip-vit-large-patch14/resolve/main/model.safetensors" "model.safetensors"
[ ! -e "/data/models/xlabs" ] && mkdir -p /data/models/xlabs/{ipadapters,loras,controlnets}
[ ! -e "/data/models/xlabs/ipadapters/flux-ip-adapter.safetensors" ] && cd /data/models/xlabs/ipadapters && \
python3 -c 'import sys; from urllib.request import urlopen; from pathlib import Path; Path(sys.argv[2]).write_bytes(urlopen(sys.argv[1]).read())' \
"https://huggingface.co/XLabs-AI/flux-ip-adapter/resolve/main/ip_adapter.safetensors" "flux-ip-adapter.safetensors"
[ -d "${ROOT}/models/xlabs" ] && rm -rf "${ROOT}/models/xlabs"
[ ! -e "${ROOT}/models/xlabs" ] && cd "${ROOT}/models" && ln -sT /data/models/xlabs xlabs && cd ..
fi
if [ "${USE_CNAUX}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then
[ ! -e "${CUSTOM_NODES}/comfyui_controlnet_aux" ] && cp -a "${ROOT}/comfyui_controlnet_aux" "${CUSTOM_NODES}"/
fi
if [ "${USE_IPAPLUS}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then
[ ! -e "${CUSTOM_NODES}/ComfyUI_IPAdapter_plus" ] && cp -a "${ROOT}/ComfyUI_IPAdapter_plus" "${CUSTOM_NODES}"/
fi
if [ "${USE_INPAINT}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then
[ ! -e "${CUSTOM_NODES}/comfyui-inpaint-nodes" ] && cp -a "${ROOT}/comfyui-inpaint-nodes" "${CUSTOM_NODES}"/
fi
if [ "${USE_TOOLING}" = "true" ] || [ "${USE_KRITA}" = "true" ]; then
[ ! -e "${CUSTOM_NODES}/comfyui-tooling-nodes" ] && cp -a "${ROOT}/comfyui-tooling-nodes" "${CUSTOM_NODES}"/
fi
if [ -f "/data/config/comfy/startup.sh" ]; then
pushd ${ROOT}
pushd "${ROOT}"
. /data/config/comfy/startup.sh
popd
fi

View File

@@ -15,11 +15,15 @@ a111:
gligen: models/GLIGEN
clip: models/CLIPEncoder
embeddings: embeddings
unet: models/unet
clip_vision: models/clip_vision
xlabs: models/xlabs
inpaint: models/inpaint
ipadapter: models/ipadapter
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