From 73b2e3332681db4336d3e051ed925947ce8a3c6e Mon Sep 17 00:00:00 2001 From: Brian Gebel Date: Mon, 28 Apr 2025 10:42:47 -0700 Subject: [PATCH 1/3] adding stuff --- .env.example | 4 ++++ TASK.md | 7 +++++++ docker-compose.v2.yml | 28 +++++++++++++++++++++++++++ docker-compose.yml | 4 ++++ services/comfy/Dockerfile | 9 ++++++++- services/comfy/extra_model_paths.yaml | 9 +++++---- 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .env.example create mode 100644 TASK.md create mode 100644 docker-compose.v2.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c7dec06 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +PUID=1000 +PGID=1000 + +DEVICE_DRIVER=nvidia \ No newline at end of file diff --git a/TASK.md b/TASK.md new file mode 100644 index 0000000..c99c4a3 --- /dev/null +++ b/TASK.md @@ -0,0 +1,7 @@ +- [] Update docker-compose to be a more readable +- [] Add support for swarm +- [] Pin / configurable versions +- [] rocm / zluda support +- [] persistant vol for custom extensions +- [] generally better workflow vol mappings +- [] auto custom node loader for comfyui \ No newline at end of file diff --git a/docker-compose.v2.yml b/docker-compose.v2.yml new file mode 100644 index 0000000..408e1cc --- /dev/null +++ b/docker-compose.v2.yml @@ -0,0 +1,28 @@ +services: + + comfyui: + build: ./services/ComfyUI/ + image: comfyui + # user: ${PUID:-1000}:${PGID:-1000} + # environment: + # - PUID=${PUID:-1000} + # - PGID=${PGID:-1000} + # - CLI_ARGS= + volumes: + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + - ./data:/data + - ./output:/output + ports: + - "7860:7860" + stop_signal: SIGKILL + tty: true + deploy: + resources: + reservations: + devices: + - driver: ${DEVICE_DRIVER:-nvidia} + device_ids: ['0'] + capabilities: [compute, utility] + restart: unless-stopped + diff --git a/docker-compose.yml b/docker-compose.yml index 970b612..0836b78 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,8 @@ x-base_service: &base_service + user: ${PUID:-1000}:${PGID:-1000} + environment: + - PUID=${PUID:-1000} + - PGID=${PGID:-1000} ports: - "${WEBUI_PORT:-7860}:7860" volumes: diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 4460499..a98fa7d 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -4,11 +4,18 @@ ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 RUN apt-get update && apt-get install -y git && apt-get clean +# Set USER here? https://stackoverflow.com/questions/24549746/switching-users-inside-docker-image-to-a-non-root-user +# USER ${uid}:${gid} + +# RUN --mount=type=cache,target=/root/.cache/pip \ +# put Cache somehwere else or don't define target? +# PIP_CACHE_DIR pip cache dir + 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 v0.3.30 && \ + git checkout v0.3.19 && \ pip install -r requirements.txt WORKDIR ${ROOT} diff --git a/services/comfy/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index eb374eb..042c994 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -19,7 +19,8 @@ a111: 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 + # style_models: data/config/comfy/style_models + # t2i_adapter: data/config/comfy/t2i_adapter + # clip_vision: data/config/comfy/clip_vision + # diffusers: data/config/comfy/diffusers + # download_model_base: data/models From 85645ae66cb9c742d18e4bce96e373501032451d Mon Sep 17 00:00:00 2001 From: Brian Gebel Date: Mon, 28 Apr 2025 13:05:02 -0700 Subject: [PATCH 2/3] working --- services/comfy/Dockerfile | 36 +++++++++++++-------------- services/comfy/entrypoint.sh | 8 +++--- services/comfy/extra_model_paths.yaml | 1 + 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index a98fa7d..73862c3 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,28 +1,26 @@ FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime -ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 +ENV DEBIAN_FRONTEND=noninteractive +ENV PIP_PREFER_BINARY=1 +ENV APPLICATION_ROOT=/stable-diffusion +ENV NVIDIA_VISIBLE_DEVICES=all +ENV PYTHONPATH="${PYTHONPATH}:${PWD}" +ENV CLI_ARGS="" -RUN apt-get update && apt-get install -y git && apt-get clean +RUN apt-get update && \ + apt-get install -y git && \ + apt-get clean && \ + git clone --branch v0.3.19 --depth 1 https://github.com/comfyanonymous/ComfyUI.git ${APPLICATION_ROOT} -# Set USER here? https://stackoverflow.com/questions/24549746/switching-users-inside-docker-image-to-a-non-root-user -# USER ${uid}:${gid} +WORKDIR ${APPLICATION_ROOT} -# RUN --mount=type=cache,target=/root/.cache/pip \ -# put Cache somehwere else or don't define target? -# PIP_CACHE_DIR pip cache dir +COPY . . -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 v0.3.19 && \ - pip install -r requirements.txt + pip install -r requirements.txt && \ + chmod u+x ./entrypoint.sh -WORKDIR ${ROOT} -COPY . /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} \ No newline at end of file + +ENTRYPOINT ["./entrypoint.sh"] +CMD python -u main.py --listen --port 7860 ${CLI_ARGS} diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index b4299a7..f7497dd 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -6,9 +6,9 @@ mkdir -vp /data/config/comfy/custom_nodes declare -A MOUNTS -MOUNTS["/root/.cache"]="/data/.cache" -MOUNTS["${ROOT}/input"]="/data/config/comfy/input" -MOUNTS["${ROOT}/output"]="/output/comfy" +# MOUNTS["/root/.cache"]="/data/.cache" # Determine why the original author decided to do this. +MOUNTS["${APPLICATION_ROOT}/input"]="/data/config/comfy/input" +MOUNTS["${APPLICATION_ROOT}/output"]="/output/comfy" for to_path in "${!MOUNTS[@]}"; do set -Eeuo pipefail @@ -23,7 +23,7 @@ for to_path in "${!MOUNTS[@]}"; do done if [ -f "/data/config/comfy/startup.sh" ]; then - pushd ${ROOT} + pushd ${APPLICATION_ROOT} . /data/config/comfy/startup.sh popd fi diff --git a/services/comfy/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index 042c994..d56f207 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -16,6 +16,7 @@ a111: clip: models/CLIPEncoder embeddings: embeddings + # This isn't a real value as far as I can tell? custom_nodes: config/comfy/custom_nodes # TODO: I am unsure about these, need more testing From c2a700fa51fc1169fe378e79172b705279c3872f Mon Sep 17 00:00:00 2001 From: Brian Gebel Date: Mon, 28 Apr 2025 14:47:23 -0700 Subject: [PATCH 3/3] revamp --- .gitignore | 4 ++++ data/.gitignore | 4 ---- data/.gitkeep | 0 services/comfy/Dockerfile | 7 +++++-- services/comfy/entrypoint.sh | 28 ++++++++++++--------------- services/comfy/extra_model_paths.yaml | 7 +++++-- 6 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 data/.gitignore create mode 100644 data/.gitkeep diff --git a/.gitignore b/.gitignore index 2a011a1..9ba66df 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ # VSCode specific *.code-workspace /.vscode + +# Service data +/data/* +!/data/.gitkeep \ No newline at end of file diff --git a/data/.gitignore b/data/.gitignore deleted file mode 100644 index 946349a..0000000 --- a/data/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.cache -/config -/embeddings -/models diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 73862c3..a58f25a 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -7,13 +7,16 @@ ENV NVIDIA_VISIBLE_DEVICES=all ENV PYTHONPATH="${PYTHONPATH}:${PWD}" ENV CLI_ARGS="" +WORKDIR ${APPLICATION_ROOT} + +# Explore how we can use the CLI to do this instead +# https://docs.comfy.org/installation/system_requirements +# https://docs.comfy.org/comfy-cli/getting-started RUN apt-get update && \ apt-get install -y git && \ apt-get clean && \ git clone --branch v0.3.19 --depth 1 https://github.com/comfyanonymous/ComfyUI.git ${APPLICATION_ROOT} -WORKDIR ${APPLICATION_ROOT} - COPY . . RUN --mount=type=cache,target=/root/.cache/pip \ diff --git a/services/comfy/entrypoint.sh b/services/comfy/entrypoint.sh index f7497dd..f47df95 100755 --- a/services/comfy/entrypoint.sh +++ b/services/comfy/entrypoint.sh @@ -2,25 +2,21 @@ set -Eeuo pipefail -mkdir -vp /data/config/comfy/custom_nodes +BASE_DIRECTORY="/data/config/comfy" +OUTPUT_DIRECTORY="/data/output" -declare -A MOUNTS +mkdir -vp ${BASE_DIRECTORY} +mkdir -vp ${BASE_DIRECTORY}/temp +mkdir -vp ${BASE_DIRECTORY}/user +mkdir -vp ${BASE_DIRECTORY}/custom_nodes +mkdir -vp ${OUTPUT_DIRECTORY} -# MOUNTS["/root/.cache"]="/data/.cache" # Determine why the original author decided to do this. -MOUNTS["${APPLICATION_ROOT}/input"]="/data/config/comfy/input" -MOUNTS["${APPLICATION_ROOT}/output"]="/output/comfy" +# --base-directory BASE_DIRECTORY +# Set the ComfyUI base directory for models, +# custom_nodes, input, output, temp, and user directories. +CLI_ARGS+="${CLI_ARGS} --base-directory ${BASE_DIRECTORY} --output-directory ${OUTPUT_DIRECTORY}" -for to_path in "${!MOUNTS[@]}"; do - set -Eeuo pipefail - from_path="${MOUNTS[${to_path}]}" - rm -rf "${to_path}" - if [ ! -f "$from_path" ]; then - mkdir -vp "$from_path" - fi - mkdir -vp "$(dirname "${to_path}")" - ln -sT "${from_path}" "${to_path}" - echo Mounted $(basename "${from_path}") -done +echo ${CLI_ARGS} if [ -f "/data/config/comfy/startup.sh" ]; then pushd ${APPLICATION_ROOT} diff --git a/services/comfy/extra_model_paths.yaml b/services/comfy/extra_model_paths.yaml index d56f207..5ce0e3a 100644 --- a/services/comfy/extra_model_paths.yaml +++ b/services/comfy/extra_model_paths.yaml @@ -1,3 +1,4 @@ +# https://github.com/comfyanonymous/ComfyUI/blob/master/extra_model_paths.yaml.example a111: base_path: /data @@ -16,8 +17,10 @@ a111: clip: models/CLIPEncoder embeddings: embeddings - # This isn't a real value as far as I can tell? - custom_nodes: config/comfy/custom_nodes +comfyui: + base_path: /data + + # custom_nodes: config/comfy/custom_nodes # TODO: I am unsure about these, need more testing # style_models: data/config/comfy/style_models