From a3c083dad3e5cf9e10f093876a65edc39b1ea656 Mon Sep 17 00:00:00 2001 From: Mikan <72257910+Mikan-DS@users.noreply.github.com> Date: Tue, 6 Oct 2026 08:20:50 +0400 Subject: [PATCH] try to add comfy --- comfyui/Dockerfile | 10 ++ comfyui/entrypoint.sh | 76 +++++++++++ compose.yaml | 50 ++++++-- ssh/gpuctl | 287 +++++++++++++++++++++++++++++------------- 4 files changed, 327 insertions(+), 96 deletions(-) create mode 100644 comfyui/Dockerfile create mode 100644 comfyui/entrypoint.sh diff --git a/comfyui/Dockerfile b/comfyui/Dockerfile new file mode 100644 index 0000000..88d9dcd --- /dev/null +++ b/comfyui/Dockerfile @@ -0,0 +1,10 @@ +FROM ghcr.io/lecode-official/comfyui-docker:latest + +RUN cd /opt/comfyui-manager \ + && /opt/conda/bin/python -m pip install --no-cache-dir . + +COPY entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/comfyui/entrypoint.sh b/comfyui/entrypoint.sh new file mode 100644 index 0000000..17853ee --- /dev/null +++ b/comfyui/entrypoint.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +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 + +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 + +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 [ -z "$USER_ID" ] || [ -z "$GROUP_ID" ]; +then + echo "Running container as $USER..." + exec /opt/conda/bin/python main.py \ + --port 8188 \ + --listen 0.0.0.0 \ + --disable-auto-launch \ + --enable-manager \ + "$@" +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 "Running as comfyui-user..." + sudo --set-home --preserve-env=PATH --user \#$USER_ID \ + /opt/conda/bin/python main.py \ + --port 8188 \ + --listen 0.0.0.0 \ + --disable-auto-launch \ + --enable-manager \ + "$@" +fi \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index 8a5594c..fea7619 100644 --- a/compose.yaml +++ b/compose.yaml @@ -41,6 +41,7 @@ services: gpu-test: profiles: - test + build: context: ./gpu @@ -66,13 +67,48 @@ services: volumes: - ${LLAMA_MODELS_HOST:-./gpu/llama_models}:/models - command: - - --host - - 0.0.0.0 - - --port - - "8080" - - --model - - /models/model.gguf + command: > + --host 0.0.0.0 + --port 8080 + --model /models/${LLAMA_MODEL:-model.gguf} + ${LLAMA_EXTRA_ARGS:-} + + networks: + - gpu-node + + restart: "no" + + comfyui: + profiles: + - comfy + + build: + context: ./comfyui + image: gpu-node-comfyui:local + + container_name: gpu-node-comfyui + + init: true + + gpus: all + + ports: + - "8188:8188" + + volumes: + - ${COMFY_BASE_HOST:-./gpu/comfy}/models:/opt/comfyui/models + - ${COMFY_BASE_HOST:-./gpu/comfy}/input:/opt/comfyui/input + - ${COMFY_BASE_HOST:-./gpu/comfy}/output:/opt/comfyui/output + - ${COMFY_BASE_HOST:-./gpu/comfy}/user:/opt/comfyui/user + - ${COMFY_BASE_HOST:-./gpu/comfy}/custom_nodes:/opt/comfyui/custom_nodes + + environment: + USE_UV: "true" + WANTED_UID: "1000" + WANTED_GID: "1000" + SECURITY_LEVEL: "normal" + COMFY_CMDLINE_EXTRA: ${COMFY_EXTRA_ARGS:-} + networks: - gpu-node diff --git a/ssh/gpuctl b/ssh/gpuctl index 9525f1d..edbb3e9 100644 --- a/ssh/gpuctl +++ b/ssh/gpuctl @@ -4,135 +4,244 @@ set -eu PROJECT_DIR="/project" + get_host_project_dir() { docker inspect gpu-node-ssh \ --format '{{range .Mounts}}{{if eq .Destination "/project"}}{{.Source}}{{end}}{{end}}' } + +show_status() { + docker ps \ + --filter "name=gpu-node-" \ + --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' +} + + +start_llama() { + MODEL="${1:-model.gguf}" + shift || true + + cd "$PROJECT_DIR" + + HOST_PROJECT_DIR="$(get_host_project_dir)" + + if [ -z "$HOST_PROJECT_DIR" ]; then + echo "ERROR: cannot determine host project directory" + exit 1 + fi + + EXTRA_ARGS="$*" + + echo "Starting llama..." + echo "Model: $MODEL" + echo "Models: $HOST_PROJECT_DIR/gpu/llama_models" + + if [ -n "$EXTRA_ARGS" ]; then + echo "Extra args: $EXTRA_ARGS" + fi + + LLAMA_MODELS_HOST="$HOST_PROJECT_DIR/gpu/llama_models" \ + LLAMA_MODEL="$MODEL" \ + LLAMA_EXTRA_ARGS="$EXTRA_ARGS" \ + docker compose \ + --profile llama \ + up -d \ + --force-recreate \ + llama + + echo + docker ps \ + --filter "name=gpu-node-llama" \ + --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' +} + + +start_comfy() { + cd "$PROJECT_DIR" + + HOST_PROJECT_DIR="$(get_host_project_dir)" + + if [ -z "$HOST_PROJECT_DIR" ]; then + echo "ERROR: cannot determine host project directory" + exit 1 + fi + + EXTRA_ARGS="$*" + + echo "Starting ComfyUI..." + echo "Directory: $HOST_PROJECT_DIR/gpu/comfy" + + if [ -n "$EXTRA_ARGS" ]; then + echo "Extra args: $EXTRA_ARGS" + fi + + COMFY_BASE_HOST="$HOST_PROJECT_DIR/gpu/comfy" \ + COMFY_RUN_HOST="$HOST_PROJECT_DIR/gpu/comfy/run" \ + COMFY_EXTRA_ARGS="$EXTRA_ARGS" \ + docker compose \ + --profile comfy \ + up -d \ + --force-recreate \ + comfyui + + echo + docker ps \ + --filter "name=gpu-node-comfyui" \ + --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' +} + + +stop_service() { + SERVICE="$1" + + case "$SERVICE" in + llama) + docker stop gpu-node-llama 2>/dev/null || true + ;; + + comfy) + docker stop gpu-node-comfyui 2>/dev/null || true + ;; + + tailscale) + docker stop gpu-node-tailscale 2>/dev/null || true + ;; + + ssh) + docker stop gpu-node-ssh 2>/dev/null || true + ;; + + *) + echo "Unknown service: $SERVICE" + exit 1 + ;; + esac +} + + +restart_service() { + SERVICE="$1" + + case "$SERVICE" in + llama) + docker restart gpu-node-llama + ;; + + comfy) + docker restart gpu-node-comfyui + ;; + + tailscale) + docker restart gpu-node-tailscale + ;; + + ssh) + docker restart gpu-node-ssh + ;; + + *) + echo "Unknown service: $SERVICE" + exit 1 + ;; + esac +} + + +logs_service() { + SERVICE="$1" + + case "$SERVICE" in + llama) + docker logs -f gpu-node-llama + ;; + + comfy) + docker logs -f gpu-node-comfyui + ;; + + tailscale) + docker logs -f gpu-node-tailscale + ;; + + ssh) + docker logs -f gpu-node-ssh + ;; + + *) + echo "Unknown service: $SERVICE" + exit 1 + ;; + esac +} + + case "${1:-}" in status) - docker ps \ - --filter "name=gpu-node-" \ - --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' + show_status ;; start) case "${2:-}" in llama) - cd "$PROJECT_DIR" - - HOST_PROJECT_DIR="$(get_host_project_dir)" - - if [ -z "$HOST_PROJECT_DIR" ]; then - echo "ERROR: cannot determine host project directory" - exit 1 - fi - - echo "Starting llama..." - echo "Models: $HOST_PROJECT_DIR/gpu/llama_models" - - LLAMA_MODELS_HOST="$HOST_PROJECT_DIR/gpu/llama_models" \ - docker compose --profile llama up -d llama - - echo - docker ps \ - --filter "name=gpu-node-llama" \ - --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' + shift 2 + start_llama "$@" ;; comfy) - cd "$PROJECT_DIR" - - HOST_PROJECT_DIR="$(get_host_project_dir)" - - if [ -z "$HOST_PROJECT_DIR" ]; then - echo "ERROR: cannot determine host project directory" - exit 1 - fi - - echo "Starting ComfyUI..." - echo "Models: $HOST_PROJECT_DIR/gpu/comfy_models" - - COMFY_MODELS_HOST="$HOST_PROJECT_DIR/gpu/comfy_models" \ - docker compose --profile comfy up -d comfyui - - echo - docker ps \ - --filter "name=gpu-node-comfyui" \ - --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' + shift 2 + start_comfy "$@" ;; *) - echo "Usage: gpuctl start {llama|comfy}" + echo "Usage:" + echo " gpuctl start llama [model.gguf] [extra args...]" + echo " gpuctl start comfy [extra args...]" exit 1 ;; esac ;; stop) - case "${2:-}" in + if [ -z "${2:-}" ]; then + echo "Usage: gpuctl stop " + exit 1 + fi - llama) - docker stop gpu-node-llama - ;; - - comfy) - docker stop gpu-node-comfyui - ;; - - *) - echo "Usage: gpuctl stop {llama|comfy}" - exit 1 - ;; - esac + stop_service "$2" ;; restart) - case "${2:-}" in + if [ -z "${2:-}" ]; then + echo "Usage: gpuctl restart " + exit 1 + fi - llama) - docker restart gpu-node-llama - ;; - - comfy) - docker restart gpu-node-comfyui - ;; - - *) - echo "Usage: gpuctl restart {llama|comfy}" - exit 1 - ;; - esac + restart_service "$2" ;; logs) - case "${2:-}" in + if [ -z "${2:-}" ]; then + echo "Usage: gpuctl logs " + exit 1 + fi - llama) - docker logs --tail 100 gpu-node-llama - ;; - - comfy) - docker logs --tail 100 gpu-node-comfyui - ;; - - *) - echo "Usage: gpuctl logs {llama|comfy}" - exit 1 - ;; - esac + logs_service "$2" ;; *) + echo "GPU node controller" + echo echo "Usage:" echo " gpuctl status" - echo " gpuctl start {llama|comfy}" - echo " gpuctl stop {llama|comfy}" - echo " gpuctl restart {llama|comfy}" - echo " gpuctl logs {llama|comfy}" + echo " gpuctl start llama [model.gguf] [extra args...]" + echo " gpuctl start comfy [extra args...]" + echo " gpuctl stop " + echo " gpuctl restart " + echo " gpuctl logs " exit 1 ;; -esac +esac \ No newline at end of file