#!/bin/bash set -e # ============================================================================ # ImageLab RunPod startup # ---------------------------------------------------------------------------- # All model-downloading is owned by imagelab_v3_extension (it reads # IMAGELAB_AUTO_DOWNLOAD + CIVITAI_TOKEN at server start). This script just # brings up ComfyUI + the custom nodes the web app's graph references, then # launches the server with sensible flags for the detected GPU. # ============================================================================ COMFYUI_DIR="/workspace/ComfyUI" CUSTOM_NODES_DIR="$COMFYUI_DIR/custom_nodes" # Colors RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m' log_info() { echo -e "${GREEN}[INFO]${NC} $1"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } log_error() { echo -e "${RED}[ERROR]${NC} $1"; } log_step() { echo -e "${BLUE}[STEP]${NC} $1"; } # ---------------------------------------------------------------------------- # Custom nodes # ---------------------------------------------------------------------------- # Everything the web app's graph references plus a small set of QoL nodes. # Keep this list tight — every entry slows boot. # # * imagelab_v3_extension → /imagelab/* API: hashing, downloads, CivitAI # * ComfyUI-Inpaint-CropAndStitch → InpaintCropImproved / InpaintStitchImproved # * ComfyUI-BRIA_AI-RMBG → BRIA_RMBG_ModelLoader_Zho + BRIA_RMBG_Zho # * ComfyUI-WD14-Tagger → kept available (old AutoTag path; harmless if unused) # * ComfyUI_UltimateSDUpscale → UltimateSDUpscale node (the Ultimate SD Upscale pass) # * comfyui_controlnet_aux → AIO_Preprocessor (the ControlNet pass; in the list below) # * ComfyUI-Manager → in-UI node manager (very useful on a fresh pod) # * rgthree-comfy / custom-scripts → QoL UI nodes the user is likely to want # ---------------------------------------------------------------------------- CUSTOM_NODES=( # — required by the web app's graph — "https://gitea.dev.blueoceanswim.com/donny/imagelab_v3_extension.git" "https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch.git" "https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG.git" "https://github.com/pythongosssss/ComfyUI-WD14-Tagger.git" "https://github.com/ssitu/ComfyUI_UltimateSDUpscale.git" # — QoL / general-purpose carried over from the old image — "https://github.com/ltdrdata/ComfyUI-Manager.git" "https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git" "https://github.com/chrisgoringe/cg-use-everywhere.git" "https://github.com/rgthree/rgthree-comfy.git" "https://github.com/cubiq/ComfyUI_essentials.git" "https://github.com/cubiq/ComfyUI_IPAdapter_plus.git" "https://github.com/Fannovel16/comfyui_controlnet_aux.git" "https://github.com/ltdrdata/ComfyUI-Impact-Pack.git" "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git" "https://github.com/WASasquatch/was-node-suite-comfyui.git" "https://github.com/comfyanonymous/ComfyUI_experiments.git" "https://github.com/JPS-GER/ComfyUI_JPS-Nodes.git" "https://github.com/jamesWalker55/comfyui-various.git" "https://github.com/Acly/comfyui-tooling-nodes.git" ) # ---------------------------------------------------------------------------- # ComfyUI # ---------------------------------------------------------------------------- setup_comfyui() { log_step "Setting up ComfyUI" if [ -d "$COMFYUI_DIR/.git" ]; then log_info "ComfyUI exists — pulling latest" git -C "$COMFYUI_DIR" pull --ff-only || log_warn "Failed to pull ComfyUI updates" else log_info "Cloning ComfyUI" git clone --depth 1 https://github.com/comfyanonymous/ComfyUI.git "$COMFYUI_DIR" fi log_info "Installing ComfyUI requirements (skipping pre-installed torch)" cd "$COMFYUI_DIR" grep -v -E "^torch==|^torch\[|^torch$|^torchvision|^torchaudio" requirements.txt > /tmp/comfy_req.txt pip install -r /tmp/comfy_req.txt 2>&1 | tail -10 rm -f /tmp/comfy_req.txt } # ---------------------------------------------------------------------------- # Custom nodes # ---------------------------------------------------------------------------- install_custom_nodes() { log_step "Installing custom nodes" mkdir -p "$CUSTOM_NODES_DIR" for repo in "${CUSTOM_NODES[@]}"; do name=$(basename "$repo" .git) path="$CUSTOM_NODES_DIR/$name" if [ -d "$path/.git" ]; then log_info "Updating $name" git -C "$path" pull --ff-only 2>/dev/null || log_warn "Failed to update $name" else log_info "Cloning $name" git -C "$CUSTOM_NODES_DIR" clone --depth 1 "$repo" 2>/dev/null || log_warn "Failed to clone $name" fi done log_step "Installing node requirements" for path in "$CUSTOM_NODES_DIR"/*/; do name=$(basename "$path") if [ -f "$path/requirements.txt" ]; then log_info " $name" pip install -q -r "$path/requirements.txt" 2>&1 | grep -v "already satisfied" || true fi done # Some nodes have an install.py — run it if present. for path in "$CUSTOM_NODES_DIR"/*/; do if [ -f "$path/install.py" ]; then log_info " install.py for $(basename "$path")" ( cd "$path" && python install.py 2>&1 | tail -3 ) || true fi done } # ---------------------------------------------------------------------------- # BRIA RMBG model (the BRIA_RMBG_* nodes look for it under their own dir) # ---------------------------------------------------------------------------- download_bria_model() { BRIA_DIR="$CUSTOM_NODES_DIR/ComfyUI-BRIA_AI-RMBG/RMBG-1.4" if [ -f "$BRIA_DIR/model.pth" ]; then log_info "BRIA RMBG-1.4 already present" return fi log_step "Downloading BRIA RMBG-1.4" python3 - <&1 | tail -3 \ && touch /tmp/.sageattention_installed \ && log_info "SageAttention installed" \ || log_warn "SageAttention install failed" ) & } # ---------------------------------------------------------------------------- # ComfyUI launch — GPU-aware default args # ---------------------------------------------------------------------------- start_comfyui() { log_step "Starting ComfyUI" cd "$COMFYUI_DIR" if [ -z "$COMFYUI_ARGS" ]; then VRAM_MB=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | head -1) VRAM_GB=$(( ${VRAM_MB:-0} / 1024 )) GPU_NAME=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1) log_info "GPU: ${GPU_NAME:-unknown} (${VRAM_GB} GB)" # Common args: bind all ifaces, TAESD live previews (what the web app # reads as binary WS frames), CORS open so the browser can talk to us. BASE_ARGS="--listen 0.0.0.0 --port 8188 --preview-method taesd --preview-size 768 --enable-cors-header" if [ "$VRAM_GB" -ge 180 ]; then log_info "Blackwell-class GPU — bf16" COMFYUI_ARGS="$BASE_ARGS --bf16-vae --bf16-unet" elif [ "$VRAM_GB" -ge 80 ]; then log_info "Hopper-class GPU — bf16" COMFYUI_ARGS="$BASE_ARGS --bf16-vae --bf16-unet" elif [ "$VRAM_GB" -ge 40 ]; then log_info "Ampere-class GPU — fp16" COMFYUI_ARGS="$BASE_ARGS --fp16-vae --fp16-unet" elif [ "$VRAM_GB" -ge 20 ]; then log_info "Consumer GPU — fp16" COMFYUI_ARGS="$BASE_ARGS --fp16-vae --fp16-unet" else log_info "Low-VRAM GPU — --lowvram" COMFYUI_ARGS="$BASE_ARGS --lowvram" fi if [ -f /tmp/.sageattention_installed ] && [ "${SAGE_ATTENTION:-true}" != "false" ]; then log_info "Enabling --use-sage-attention" COMFYUI_ARGS="$COMFYUI_ARGS --use-sage-attention" fi fi log_info "Args: $COMFYUI_ARGS" log_info "ComfyUI on http://0.0.0.0:8188" exec python main.py $COMFYUI_ARGS } # ---------------------------------------------------------------------------- # main # ---------------------------------------------------------------------------- log_info "==========================================" log_info "ImageLab RunPod" log_info "==========================================" log_info "CIVITAI_TOKEN=$( [ -n "$CIVITAI_TOKEN" ] && echo set || echo unset )" log_info "IMAGELAB_AUTO_DOWNLOAD=$( [ -n "$IMAGELAB_AUTO_DOWNLOAD" ] && echo set || echo unset )" log_info "SAGE_ATTENTION=${SAGE_ATTENTION:-true}" log_info "==========================================" setup_comfyui install_custom_nodes install_sage_attention # background download_bria_model & BRIA_PID=$! download_hf_models & HF_PID=$! download_feature_models & FEAT_PID=$! wait $BRIA_PID $HF_PID $FEAT_PID || true start_comfyui