From bdd269896da176d864a199e441f16c67d77238c0 Mon Sep 17 00:00:00 2001 From: AdiosF6F <62105+Adios@users.noreply.github.com> Date: Thu, 18 Dec 2025 02:45:40 +0800 Subject: [PATCH 1/3] fix(comfy): ensure safe initialization of ComfyUI-Manager in custom_nodes This commit modifies the ComfyUI entrypoint script to correctly handle the initialization of ComfyUI-Manager within the persistent `custom_nodes` volume. Changes include: - Added logic to check if `ComfyUI-Manager` (case-insensitive) already exists in the `custom_nodes` directory. - Implemented a robust bash loop for the existence check to avoid issues with `find` on symlinked paths. - If the manager is missing, it is copied from the pre-installed location in the image to the persistent volume. - If the manager exists, the initialization is skipped to prevent overwriting user updates or configurations. This ensures that the pre-installed manager is available on the first run while preserving it across subsequent container restarts and builds. --- services/comfy/entrypoint.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index e9b0fe41a..770156a3e 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -29,6 +29,28 @@ for to_path in "${!MOUNTS[@]}"; do echo "Mounted ${from_path} -> ${to_path}" done +if [ -d "${ROOT}/comfyui-manager" ]; then + manager_exists=false + shopt -s nullglob + for dir in "${ROOT}/custom_nodes"/*; do + dirname=$(basename "$dir") + if [[ "${dirname,,}" == "comfyui-manager" ]]; then + manager_exists=true + break + fi + done + shopt -u nullglob + + if [ "$manager_exists" = false ]; then + echo "Initializing ComfyUI-Manager..." + # Debug: List contents to see why it wasn't found (optional, can be removed later) + ls -la "${ROOT}/custom_nodes" || true + cp -r "${ROOT}/comfyui-manager" "${ROOT}/custom_nodes/comfyui-manager" + else + echo "ComfyUI-Manager detected in custom_nodes, skipping initialization." + fi +fi + if [ -f "/data/config/comfy/startup.sh" ]; then pushd ${ROOT} . /data/config/comfy/startup.sh From 04aaab21246755bb17f72b856642c1304682cb44 Mon Sep 17 00:00:00 2001 From: AdiosF6F <62105+Adios@users.noreply.github.com> Date: Fri, 19 Dec 2025 05:30:01 +0800 Subject: [PATCH 2/3] fix(comfy): enable headless opencv via pip overrides This commit configures ComfyUI-Manager to enforce `opencv-contrib-python-headless` instead of the standard `opencv-python` package. Changes: 1. **entrypoint.sh**: * Dynamically detects if the installed ComfyUI version uses the new System User API (by checking for `get_system_user_directory`). * Creates the appropriate configuration directory (`__manager` for new versions, `default/ComfyUI-Manager` for old versions) in the user's volume. * Copies `pip_overrides.json.template` from the image to `pip_overrides.json` in the user configuration directory. * Displays a prominent notification message during initialization. This approach ensures that even if custom nodes request the standard OpenCV package, the Manager will intercept the request and install the headless version (specifically the `contrib` variant to support extra modules), preventing system library crashes (libGL) across different ComfyUI versions. --- services/comfy/entrypoint.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index 770156a3e..88959e874 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -43,6 +43,30 @@ if [ -d "${ROOT}/comfyui-manager" ]; then if [ "$manager_exists" = false ]; then echo "Initializing ComfyUI-Manager..." + + # Determine Manager Config Directory (New vs Old ComfyUI structure) + MANAGER_CONFIG_DIR="__manager" + if ! grep -q "get_system_user_directory" "${ROOT}/folder_paths.py"; then + MANAGER_CONFIG_DIR="default/ComfyUI-Manager" + fi + + # Ensure User Config Directory exists and copy override file + USER_CONFIG_PATH="/data/config/comfy/user/${MANAGER_CONFIG_DIR}" + mkdir -vp "${USER_CONFIG_PATH}" + cp "${ROOT}/comfyui-manager/pip_overrides.json.template" "${USER_CONFIG_PATH}/pip_overrides.json" + + echo "################################################################################" + echo "# #" + echo "# NOTICE: INITIALIZING COMFYUI-MANAGER WITH HEADLESS OPENCV OVERRIDES #" + echo "# #" + echo "# pip_overrides.json is being copied to your user configuration directory: #" + echo "# ${USER_CONFIG_PATH}/" + echo "# #" + echo "# This forces the installation of opencv-contrib-python-headless instead #" + echo "# of the standard opencv-python to prevent system library crashes (libGL). #" + echo "# #" + echo "################################################################################" + # Debug: List contents to see why it wasn't found (optional, can be removed later) ls -la "${ROOT}/custom_nodes" || true cp -r "${ROOT}/comfyui-manager" "${ROOT}/custom_nodes/comfyui-manager" From 05d402048f18bbe5d01921a01fd4155db0791ff0 Mon Sep 17 00:00:00 2001 From: AdiosF6F <62105+Adios@users.noreply.github.com> Date: Sun, 21 Dec 2025 19:43:37 +0800 Subject: [PATCH 3/3] fix(comfy): install system GL libs to support standard opencv-python The `ultralytics` package (required by ComfyUI-Impact-Subpack) pulls in `opencv-python` as a dependency. In the headless Docker environment, this caused crashes due to missing GL libraries. Attempting to fix this via `pip_overrides.json` in ComfyUI-Manager (forcing `opencv-python-headless` or `dgenerate-ultralytics-headless`) was problematic because `pip_overrides` struggles with recursive dependency overrides. This commit resolves the issue by installing the necessary system libraries (`libgl1`, `libglib2.0-0`) in the Dockerfile. This allows the standard `opencv-python` wheel to function correctly, eliminating the need for complex override logic in the entrypoint script. Changes: - services/comfy/Dockerfile: Install `libgl1` and `libglib2.0-0`. - services/comfy/entrypoint.sh: Remove `pip_overrides.json` injection logic. --- services/comfy/Dockerfile | 3 ++- services/comfy/entrypoint.sh | 24 ------------------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 9f3ded239..956b29415 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -5,7 +5,8 @@ FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 -RUN apt-get update && apt-get install -y git libgoogle-perftools-dev && apt-get clean +# libgl1 and libglib2.0-0 are required for opencv-python +RUN apt-get update && apt-get install -y git libgoogle-perftools-dev libgl1 libglib2.0-0 && apt-get clean ARG PUID=0 ARG PGID=0 diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index 88959e874..770156a3e 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -43,30 +43,6 @@ if [ -d "${ROOT}/comfyui-manager" ]; then if [ "$manager_exists" = false ]; then echo "Initializing ComfyUI-Manager..." - - # Determine Manager Config Directory (New vs Old ComfyUI structure) - MANAGER_CONFIG_DIR="__manager" - if ! grep -q "get_system_user_directory" "${ROOT}/folder_paths.py"; then - MANAGER_CONFIG_DIR="default/ComfyUI-Manager" - fi - - # Ensure User Config Directory exists and copy override file - USER_CONFIG_PATH="/data/config/comfy/user/${MANAGER_CONFIG_DIR}" - mkdir -vp "${USER_CONFIG_PATH}" - cp "${ROOT}/comfyui-manager/pip_overrides.json.template" "${USER_CONFIG_PATH}/pip_overrides.json" - - echo "################################################################################" - echo "# #" - echo "# NOTICE: INITIALIZING COMFYUI-MANAGER WITH HEADLESS OPENCV OVERRIDES #" - echo "# #" - echo "# pip_overrides.json is being copied to your user configuration directory: #" - echo "# ${USER_CONFIG_PATH}/" - echo "# #" - echo "# This forces the installation of opencv-contrib-python-headless instead #" - echo "# of the standard opencv-python to prevent system library crashes (libGL). #" - echo "# #" - echo "################################################################################" - # Debug: List contents to see why it wasn't found (optional, can be removed later) ls -la "${ROOT}/custom_nodes" || true cp -r "${ROOT}/comfyui-manager" "${ROOT}/custom_nodes/comfyui-manager"