Skip to content

Instantly share code, notes, and snippets.

@ryanontheinside
Last active April 5, 2025 15:46
Show Gist options
  • Save ryanontheinside/de11904826ee863c6e3ea2f3dc2ae90c to your computer and use it in GitHub Desktop.
Save ryanontheinside/de11904826ee863c6e3ea2f3dc2ae90c to your computer and use it in GitHub Desktop.
Deploying ComfyUI on RunPod
#this script corresponds to this tutorial video: https://www.youtube.com/watch?v=5hCGDcfPy8Y
#You only need to run this script once. However, when you start a new runpod server, you will need to initialize conda in the shell.
#1. run the following command to intialize conda in the shell
#/workspace/miniconda3/bin/conda init bash
#2. run the following command to activate the conda environment
#conda activate comfyui
#3. run the following command to start comfyui
#python main.py --listen
#!/bin/bash
#ComfyUI single environment setup
echo "
========================================
πŸš€ Starting ComfyUI setup...
========================================
"
# Create base directories
echo "
----------------------------------------
πŸ“ Creating base directories...
----------------------------------------"
mkdir -p /workspace/ComfyUI
mkdir -p /workspace/miniconda3
# Download and install Miniconda
echo "
----------------------------------------
πŸ“₯ Downloading and installing Miniconda...
----------------------------------------"
if [ ! -f "/workspace/miniconda3/bin/conda" ]; then
cd /workspace/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -p /workspace/miniconda3 -f
else
echo "Miniconda already installed, skipping..."
fi
# Initialize conda in the shell
echo "
----------------------------------------
🐍 Initializing conda...
----------------------------------------"
eval "$(/workspace/miniconda3/bin/conda shell.bash hook)"
# Clone ComfyUI
echo "
----------------------------------------
πŸ“₯ Cloning ComfyUI repository...
----------------------------------------"
if [ ! -d "/workspace/ComfyUI/.git" ]; then
git clone https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
else
echo "ComfyUI already exists in /workspace/ComfyUI, skipping clone..."
fi
# Clone ComfyUI-Manager
echo "
----------------------------------------
πŸ“₯ Installing ComfyUI-Manager...
----------------------------------------"
if [ ! -d "/workspace/ComfyUI/custom_nodes/ComfyUI-Manager/.git" ]; then
git clone https://github.com/ltdrdata/ComfyUI-Manager.git /workspace/ComfyUI/custom_nodes/ComfyUI-Manager
else
echo "ComfyUI-Manager already exists, skipping clone..."
fi
# Clone RyanOnTheInside nodes
echo "
----------------------------------------
πŸ“₯ Installing ComfyUI RyanOnTheInside nodes...
----------------------------------------"
if [ ! -d "/workspace/ComfyUI/custom_nodes/ComfyUI_RyanOnTheInside/.git" ]; then
git clone https://github.com/ryanontheinside/ComfyUI_RyanOnTheInside.git /workspace/ComfyUI/custom_nodes/ComfyUI_RyanOnTheInside
else
echo "ComfyUI RyanOnTheInside nodes already exist, skipping clone..."
fi
# Create conda environment
echo "
----------------------------------------
🌟 Creating conda environment...
----------------------------------------"
if ! conda info --envs | grep -q "comfyui"; then
conda create -n comfyui python=3.11 -y
else
echo "comfyui environment already exists, skipping creation..."
fi
# Setup comfyui environment
echo "
----------------------------------------
πŸ”§ Setting up comfyui environment...
----------------------------------------"
echo "πŸ”„ Activating comfyui environment..."
set -x # Enable debug mode to see each command
conda activate comfyui
RESULT=$?
echo "Activation exit code: $RESULT"
if [ "$CONDA_DEFAULT_ENV" != "comfyui" ]; then
echo "❌ Failed to activate comfyui environment! Current env: $CONDA_DEFAULT_ENV"
exit 1
fi
echo "βœ… Successfully activated comfyui environment"
# Install requirements
cd /workspace/ComfyUI
echo "πŸ“¦ Installing ComfyUI requirements..."
pip install -r requirements.txt
cd custom_nodes/ComfyUI-Manager
echo "πŸ“¦ Installing ComfyUI-Manager requirements..."
pip install -r requirements.txt
if [ -f "/workspace/ComfyUI/custom_nodes/ComfyUI_RyanOnTheInside/requirements.txt" ]; then
echo "πŸ“¦ Installing RyanOnTheInside nodes requirements..."
cd /workspace/ComfyUI/custom_nodes/ComfyUI_RyanOnTheInside
pip install -r requirements.txt
fi
# Return to base environment
echo "πŸ”„ Deactivating comfyui environment..."
conda deactivate
echo "βœ… Successfully deactivated comfyui environment"
set +x # Disable debug mode
echo "
========================================
✨ Setup complete! ✨
========================================
"
@sinsunsan
Copy link

sinsunsan commented Feb 20, 2025

Very nice to share you setup https://www.youtube.com/watch?v=5hCGDcfPy8Y

I was confused after your script run, because conda was not activated, so I asked ChatGPT

And also created a second script only to run comfyUI once it is setup.

I created 2 .sh files, ones with yours to setup
And a second one to run without having to figure out the command, probably, I will also automatise so anytime I run the pod, it is run as well

source /workspace/miniconda3/bin/activate
conda activate comfyui
cd /workspace/ComfyUI
python [main.py](javascript:void(0);) --listen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment