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

View File

@ -10,6 +10,8 @@ import time
import logging
import tempfile
import requests
import subprocess
import threading
from typing import Dict, Any, Optional
import runpod
@ -24,7 +26,9 @@ class ComfyUIServerlessHandler:
def __init__(self):
self.comfyui_url = "http://127.0.0.1:8000"
self.client_id = "runpod_serverless_worker"
self.comfyui_process = None
self.setup_paths()
self.start_comfyui()
def setup_paths(self):
"""Setup required paths for serverless operation"""
@ -32,6 +36,22 @@ class ComfyUIServerlessHandler:
os.makedirs("/tmp/outputs", 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:
"""Wait for ComfyUI to be ready"""
start_time = time.time()