Skip to content

Instantly share code, notes, and snippets.

@arthurmchr
Created April 10, 2025 08:11
Show Gist options
  • Save arthurmchr/32c48905224cb0a6d39889acba4127b1 to your computer and use it in GitHub Desktop.
Save arthurmchr/32c48905224cb0a6d39889acba4127b1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e # Exit immediately if a command exits with non-zero status
# Configuration
WORKSPACE="/workspace"
COMFYUI_DIR="${WORKSPACE}/ComfyUI"
VENV_DIR="${WORKSPACE}/venv/comfyui"
COMFYUI_REPO="https://github.com/comfyanonymous/ComfyUI.git"
MANAGER_REPO="https://github.com/ltdrdata/ComfyUI-Manager.git"
MANAGER_DIR="${COMFYUI_DIR}/custom_nodes/ComfyUI-Manager"
# Create necessary directories
mkdir -p "${WORKSPACE}/venv"
# Function for colored output
info() { echo -e "\033[0;36m[INFO]\033[0m $1"; }
success() { echo -e "\033[0;32m[SUCCESS]\033[0m $1"; }
error() { echo -e "\033[0;31m[ERROR]\033[0m $1"; }
# Create virtual environment if it doesn't exist
if [ ! -d "${VENV_DIR}" ]; then
info "Creating virtual environment for ComfyUI..."
python3 -m venv "${VENV_DIR}"
success "Virtual environment created at ${VENV_DIR}"
else
info "Using existing virtual environment at ${VENV_DIR}"
fi
# Function to handle repositories
handle_repo() {
local repo_url=$1
local target_dir=$2
local repo_name=$(basename "${repo_url}" .git)
if [ ! -d "${target_dir}/.git" ]; then
info "Cloning ${repo_name}..."
git clone "${repo_url}" "${target_dir}"
success "${repo_name} cloned successfully"
else
info "Updating existing ${repo_name}..."
(cd "${target_dir}" && git pull)
success "${repo_name} updated successfully"
fi
}
# Clone/update repositories (can be done before activating the environment)
handle_repo "${COMFYUI_REPO}" "${COMFYUI_DIR}" &
COMFYUI_PID=$!
handle_repo "${MANAGER_REPO}" "${MANAGER_DIR}" &
MANAGER_PID=$!
# Wait for git operations to complete
wait $COMFYUI_PID
wait $MANAGER_PID
# Activate the virtual environment
info "Activating virtual environment..."
source "${VENV_DIR}/bin/activate"
if [[ "${VIRTUAL_ENV}" != *"comfyui"* ]]; then
error "Failed to activate virtual environment!"
exit 1
fi
success "Virtual environment activated"
# Install dependencies
info "Upgrading pip..."
pip install --upgrade pip --quiet
info "Installing ComfyUI dependencies..."
(cd "${COMFYUI_DIR}" && pip install -r requirements.txt)
success "ComfyUI dependencies installed"
info "Installing ComfyUI-Manager dependencies..."
(cd "${MANAGER_DIR}" && pip install -r requirements.txt)
success "ComfyUI-Manager dependencies installed"
# Deactivate virtual environment
info "Deactivating virtual environment..."
deactivate
success "Setup completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment