From 896b98c6c1aeeda8b22d4f181d8f3610e6cc7b47 Mon Sep 17 00:00:00 2001 From: Bahadir Ciloglu Date: Sat, 1 Nov 2025 15:43:21 +0300 Subject: [PATCH] Fix Dockerfile and handler - resolve exit code 127 error --- ComfyUI-master/Dockerfile | 40 +++++++++++--------------------- ComfyUI-master/runpod_handler.py | 20 ++++++++++++++++ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/ComfyUI-master/Dockerfile b/ComfyUI-master/Dockerfile index b040eb7ae..696351bd8 100644 --- a/ComfyUI-master/Dockerfile +++ b/ComfyUI-master/Dockerfile @@ -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"] \ No newline at end of file +# Start command +CMD ["python3", "runpod_handler.py"] \ No newline at end of file diff --git a/ComfyUI-master/runpod_handler.py b/ComfyUI-master/runpod_handler.py index c0234c51d..3fa1f6368 100644 --- a/ComfyUI-master/runpod_handler.py +++ b/ComfyUI-master/runpod_handler.py @@ -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()