From ed02c136f053bc61ba417c74d0085407ba113fd6 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Sun, 24 Nov 2024 21:50:04 -0700 Subject: [PATCH] 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. --- services/comfy/entrypoint.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index e2fee4a..2f31fa1 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -26,27 +26,27 @@ 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##*/} ----" - cd $NODE && git pull; - [ "${NODE##*/}" = "krita-ai-diffusion" ] && git submodule update --recursive; cd .. + set +e + cd "$NODE" && git pull; cd ..; + set -e done fi if [ "${USE_KRITA}" = "true" ]; then - [ ! -e "${CUSTOM_NODES}/krita-ai-diffusion" ] && cp -a "${ROOT}/krita-ai-diffusion" "${CUSTOM_NODES}"/ - 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 [ -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" ] && mv "${ROOT}/ComfyUI-GGUF" "${CUSTOM_NODES}"/ + [ ! -e "${CUSTOM_NODES}/ComfyUI-GGUF" ] && cp -a "${ROOT}/ComfyUI-GGUF" "${CUSTOM_NODES}"/ fi if [ "${USE_XFLUX}" = "true" ]; then - [ ! -e "${CUSTOM_NODES}/x-flux-comfyui" ] && mv "${ROOT}/x-flux-comfyui" "${CUSTOM_NODES}"/ + [ ! -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())' \ @@ -59,20 +59,20 @@ if [ "${USE_XFLUX}" = "true" ]; then [ ! -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" ] && mv "${ROOT}/comfyui_controlnet_aux" "${CUSTOM_NODES}"/ + [ ! -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" ] && mv "${ROOT}/ComfyUI_IPAdapter_plus" "${CUSTOM_NODES}"/ + [ ! -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" ] && mv "${ROOT}/comfyui-inpaint-nodes" "${CUSTOM_NODES}"/ + [ ! -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" ] && mv "${ROOT}/comfyui-tooling-nodes" "${CUSTOM_NODES}"/ + [ ! -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