From 974d0b1f1a09e78eaf477c2f491978dc07b5e73d Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 04:27:18 -0400 Subject: [PATCH] Added Confyui manager to dockerfile, made changes to .sh file to recieve message from main.py, add place holder for venv volume mount --- Dockerfile | 8 +++++ docker-build.sh | 78 +++++++++++++++++++++++++++++++++++++++------- docker-compose.yml | 5 +-- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6793ad0e..c78c0c2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,14 @@ RUN . venv/bin/activate && pip install -r /app/comfyui/requirements.txt # Install PyTorch with CUDA 12.1 support RUN . venv/bin/activate && pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 +# Clone the ComfyUI-manager repository into a temporary directory, move it, and clean up +RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI-Manager && \ + mv /app/temp/* /app/comfyui/custom_nodes/ && \ + rm -rf /app/temp + +# Install ComfyUI-manager dependencies +RUN . venv/bin/activate && pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt + # Expose the backend port EXPOSE 8188 diff --git a/docker-build.sh b/docker-build.sh index 992d5a11..5c20d985 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -7,31 +7,85 @@ then exit 1 fi -# Step 1: Build and start the container without mounting the venv volume -echo "Building and starting the container to initialize the virtual environment..." -COMPOSE_BAKE=true docker-compose up --build -d +# Step 1: Build the container without using cache +echo "Building the container to initialize the virtual environment..." +COMPOSE_BAKE=true docker-compose build --no-cache +if [ $? -eq 0 ]; then + echo "Build completed successfully." +else + echo "Build failed. Exiting." + exit 1 +fi + +# Step 2: Start the container without mounting the venv volume +echo "Starting the container..." +COMPOSE_BAKE=true docker-compose up -d +if [ $? -eq 0 ]; then + echo "Container started successfully." +else + echo "Failed to start the container. Exiting." + exit 1 +fi + +# Step 3: Stream Docker logs to the terminal +container_name="comfyui-red-container" +echo "Streaming Docker logs for container: $container_name..." +docker logs -f "$container_name" & +LOGS_PID=$! # Save the PID of the background process # Wait for the container logs to indicate it's ready (looking for the custom message) -container_name="comfyui-red-container" -while ! docker logs "$container_name" 2>&1 | grep -q "Server started and ready to accept requests"; do - echo "Waiting for the container to be fully started..." +echo "Waiting for the container to be fully started..." +while ! docker logs "$container_name" 2>&1 | grep -q "To see the GUI go to: http://0.0.0.0:8188"; do sleep 20 done -# Step 2: Copy the 'venv' directory from the container to the host -echo "Copying the virtual environment from the container to the host..." -docker cp "$container_name:/app/venv" ./venv +# Stop streaming logs (kill the background process) +kill $LOGS_PID +echo "Container is fully started." -# Step 3: Stop the container +# Step 4: Copy the 'venv' directory from the container to the host +echo "Checking if /app/venv exists in the container..." +if docker exec "$container_name" ls /app/venv; then + echo "Copying the virtual environment from the container to the host..." + if ! docker cp "$container_name:/app/venv" ./venv; then + echo "Failed to copy the virtual environment. Exiting." + exit 1 + else + echo "Virtual environment copied successfully." + fi +else + echo "/app/venv does not exist in the container. Exiting." + exit 1 +fi + +# Step 5: Stop the container echo "Stopping the container..." docker-compose down +if [ $? -eq 0 ]; then + echo "Container stopped successfully." +else + echo "Failed to stop the container. Exiting." + exit 1 +fi -# Step 4: Update the Docker Compose file to mount the venv volume +# Step 6: Update the Docker Compose file to mount the venv volume echo "Updating Docker Compose file to mount the virtual environment..." sed -i '/# Mount the venv directory for persistence/a \ \ \ \ \ \ - ./venv:/app/venv' docker-compose.yml +if [ $? -eq 0 ]; then + echo "Docker Compose file updated successfully." +else + echo "Failed to update Docker Compose file. Exiting." + exit 1 +fi -# Step 5: Restart the container with the venv volume mounted +# Step 7: Restart the container with the venv volume mounted echo "Restarting the container with the virtual environment mounted..." docker-compose up -d +if [ $? -eq 0 ]; then + echo "Container restarted successfully." +else + echo "Failed to restart the container. Exiting." + exit 1 +fi echo "Setup complete! The container is running with the virtual environment persisted at ./venv." \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a55310ed..be888196 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,8 +15,9 @@ services: - ./user:/app/comfyui/user # Comment this line and uncomment the next line if you want to have a workflows directory in the root directory. #- ./workflows:/app/comfyui/user/default/workflows - # Mount the venv directory for persistence - + # Mount the venv directory for persistence(automatically mounted with you run docker-build.sh) + + environment: - DISPLAY=${DISPLAY} # Optional, for X11 display forwarding (if you use it) - NVIDIA_VISIBLE_DEVICES=all # Ensure NVIDIA GPU is available to the container