Fix Dockerfile and handler - resolve exit code 127 error

This commit is contained in:
Bahadir Ciloglu 2025-11-01 15:43:21 +03:00
parent 2c77183f25
commit 896b98c6c1
2 changed files with 34 additions and 26 deletions

View File

@ -18,6 +18,12 @@ RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \ libgl1-mesa-glx \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy ComfyUI source code
COPY . /workspace/ComfyUI
# Set ComfyUI as working directory
WORKDIR /workspace/ComfyUI
# Install Python dependencies # Install Python dependencies
RUN pip install --no-cache-dir \ RUN pip install --no-cache-dir \
runpod \ runpod \
@ -33,27 +39,13 @@ RUN pip install --no-cache-dir \
diffusers \ diffusers \
opencv-python \ opencv-python \
scipy \ scipy \
scikit-image scikit-image \
# Copy ComfyUI source code
COPY . /workspace/ComfyUI
# Set ComfyUI as working directory
WORKDIR /workspace/ComfyUI
# Install ComfyUI requirements
RUN pip install --no-cache-dir -r requirements.txt
# Install additional dependencies for new features
RUN pip install --no-cache-dir \
safetensors \ safetensors \
transformers[torch] \
accelerate \
bitsandbytes \ bitsandbytes \
optimum optimum
# Copy environment example (users should provide their own .env) # Install ComfyUI requirements if exists
COPY .env.example /workspace/.env.example RUN if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; fi
# Create necessary directories # Create necessary directories
RUN mkdir -p /workspace/ComfyUI/models/checkpoints \ RUN mkdir -p /workspace/ComfyUI/models/checkpoints \
@ -74,16 +66,12 @@ ENV COMFYUI_SERVERLESS=true
ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
# Create startup script # Set environment variables
RUN echo '#!/bin/bash\n\ ENV PYTHONPATH="/workspace/ComfyUI:${PYTHONPATH}"
cd /workspace/ComfyUI\n\ ENV COMFYUI_SERVERLESS=true
python main.py --listen 0.0.0.0 --port 8000 --dont-print-server --disable-auto-launch &\n\
sleep 10\n\
cd /workspace/ComfyUI\n\
python runpod_handler.py' > /workspace/start.sh && chmod +x /workspace/start.sh
# Expose port # Expose port
EXPOSE 8000 EXPOSE 8000
# Set the command # Start command
CMD ["/workspace/start.sh"] CMD ["python3", "runpod_handler.py"]

View File

@ -10,6 +10,8 @@ import time
import logging import logging
import tempfile import tempfile
import requests import requests
import subprocess
import threading
from typing import Dict, Any, Optional from typing import Dict, Any, Optional
import runpod import runpod
@ -24,7 +26,9 @@ class ComfyUIServerlessHandler:
def __init__(self): def __init__(self):
self.comfyui_url = "http://127.0.0.1:8000" self.comfyui_url = "http://127.0.0.1:8000"
self.client_id = "runpod_serverless_worker" self.client_id = "runpod_serverless_worker"
self.comfyui_process = None
self.setup_paths() self.setup_paths()
self.start_comfyui()
def setup_paths(self): def setup_paths(self):
"""Setup required paths for serverless operation""" """Setup required paths for serverless operation"""
@ -32,6 +36,22 @@ class ComfyUIServerlessHandler:
os.makedirs("/tmp/outputs", exist_ok=True) os.makedirs("/tmp/outputs", exist_ok=True)
os.makedirs("/tmp/comfyui", exist_ok=True) os.makedirs("/tmp/comfyui", exist_ok=True)
def start_comfyui(self):
"""Start ComfyUI server in background"""
try:
logger.info("Starting ComfyUI server...")
self.comfyui_process = subprocess.Popen([
"python3", "main.py",
"--listen", "0.0.0.0",
"--port", "8000",
"--dont-print-server",
"--disable-auto-launch"
], cwd="/workspace/ComfyUI")
logger.info("ComfyUI server started")
except Exception as e:
logger.error(f"Failed to start ComfyUI: {str(e)}")
raise
def wait_for_comfyui(self, timeout: int = 120) -> bool: def wait_for_comfyui(self, timeout: int = 120) -> bool:
"""Wait for ComfyUI to be ready""" """Wait for ComfyUI to be ready"""
start_time = time.time() start_time = time.time()