From d6186ec00aed26b05c8ffc42ae9ae2c2c7cdf136 Mon Sep 17 00:00:00 2001 From: Madiator2011 Date: Thu, 12 Sep 2024 14:07:03 +0200 Subject: [PATCH] Better sync update --- official-templates/better-comfyui/Dockerfile | 21 ++++-- .../better-comfyui/docker-bake.hcl | 23 ++----- .../better-comfyui/pre_start.sh | 66 +++++++++++++++++-- 3 files changed, 78 insertions(+), 32 deletions(-) diff --git a/official-templates/better-comfyui/Dockerfile b/official-templates/better-comfyui/Dockerfile index c830bee..c81ef39 100644 --- a/official-templates/better-comfyui/Dockerfile +++ b/official-templates/better-comfyui/Dockerfile @@ -4,14 +4,21 @@ FROM madiator2011/better-base:cuda12.1 as base ARG PYTHON_VERSION1=3.11 ARG TORCH=torch==2.3.0+cu121 +# Install fpart (which includes fpsync) +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get install -y fpart && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + # Stage 2: ComfyUI Installation FROM base as comfyui-install -# Create virtual environment in /workspace/venv -RUN python -m venv /workspace/venv +# Create virtual environment +RUN mkdir -p /workspace/runpod-venvs && python -m venv /workspace/runpod-venvs/better-comfyui # Set environment variables for the virtual environment -ENV VIRTUAL_ENV="/workspace/venv" +ENV VIRTUAL_ENV="/workspace/runpod-venvs/better-comfyui" ENV PATH="$VIRTUAL_ENV/bin:$PATH" # Activate the virtual environment and install packages @@ -37,7 +44,7 @@ ARG INCLUDE_MODELS=false # Download each model in a separate layer RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \ - wget -q --show-progress https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors -O /comfy-models/v1-5-pruned-emaonly.safetensors; \ + wget -q --show-progress https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly.safetensors -O /comfy-models/v1-5-pruned-emaonly.safetensors; \ fi RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \ @@ -61,13 +68,13 @@ RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \ FROM comfyui-install as final # Move virtual environment from /workspace/venv to /venv -RUN mv /workspace/venv /venv +RUN mv /workspace/runpod-venvs/better-comfyui /venv # Copy models if they were included COPY --from=model-setup /comfy-models /comfy-models # Set environment variables for runtime -ENV VIRTUAL_ENV="/workspace/venv" +ENV VIRTUAL_ENV="/workspace/runpod-venvs/better-comfyui" ENV PATH="$VIRTUAL_ENV/bin:$PATH" # Copy the README.md @@ -85,4 +92,4 @@ RUN chmod +x /pre_start.sh COPY comfyui_extras.ipynb /comfyui_extras.ipynb # CMD -CMD [ "/start.sh" ] \ No newline at end of file +CMD [ "/start.sh" ] diff --git a/official-templates/better-comfyui/docker-bake.hcl b/official-templates/better-comfyui/docker-bake.hcl index fca01f2..4bfcb53 100644 --- a/official-templates/better-comfyui/docker-bake.hcl +++ b/official-templates/better-comfyui/docker-bake.hcl @@ -1,5 +1,5 @@ group "default" { - targets = ["full-version", "light-version", "testing"] + targets = ["full-version", "light-version", "dev"] } target "base" { @@ -21,11 +21,6 @@ target "full-version" { args = { INCLUDE_MODELS = "true" } - contexts = { - scripts = "../../container-template" - proxy = "../../container-template/proxy" - logo = "../../container-template" - } tags = ["madiator2011/better-comfyui:full"] } @@ -34,23 +29,13 @@ target "light-version" { args = { INCLUDE_MODELS = "false" } - contexts = { - scripts = "../../container-template" - proxy = "../../container-template/proxy" - logo = "../../container-template" - } tags = ["madiator2011/better-comfyui:light"] } -target "testing" { +target "dev" { inherits = ["base"] args = { INCLUDE_MODELS = "false" } - contexts = { - scripts = "../../container-template" - proxy = "../../container-template/proxy" - logo = "../../container-template" - } - tags = ["madiator2011/better-comfyui:testing"] -} + tags = ["madiator2011/better-comfyui:dev"] +} \ No newline at end of file diff --git a/official-templates/better-comfyui/pre_start.sh b/official-templates/better-comfyui/pre_start.sh index 20662a6..a065808 100644 --- a/official-templates/better-comfyui/pre_start.sh +++ b/official-templates/better-comfyui/pre_start.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Set a default TERM if it's not set +if [ -z "$TERM" ]; then + export TERM=xterm-256color +fi + # Exit immediately if a command exits with a non-zero status set -e @@ -38,11 +43,60 @@ fi print_feedback "Starting ComfyUI setup..." print_feedback "Syncing virtual environment..." -rsync_with_progress /venv/ /workspace/venv/ +VIRTUAL_ENV="/workspace/runpod-venvs/better-comfyui" +SOURCE_VENV="/venv" +NUM_CORES=$(nproc) + +if [ ! -d "$VIRTUAL_ENV" ]; then + clear + echo -e "\e[1;33m" + cat << "EOF" + _____________________________________ +| | +| !!! ATTENTION - FIRST TIME SYNC !!!| +| | +| This process will take ~10 minutes | +|_____________________________________| + +EOF + echo -e "\e[0m" + + mkdir -p "$VIRTUAL_ENV" + + # Start background process to show progress + ( + while true; do + for s in / - \\ \|; do + printf "\r\033[1;31m[%s] \033[1;37mSYNC IN PROGRESS - PLEASE WAIT\033[0m" "$s" + sleep 0.5 + done + done + ) & + PROGRESS_PID=$! + + # Perform the sync + rsync -aHx --info=progress2 --stats --exclude='*.pyc' --exclude='__pycache__' "$SOURCE_VENV/" "$VIRTUAL_ENV/" + + # Stop the progress indicator + kill $PROGRESS_PID + wait $PROGRESS_PID 2>/dev/null + + clear + echo -e "\e[1;32m" + cat << "EOF" + _____________________________________ +| | +| SYNC COMPLETED SUCCESS | +|_____________________________________| + +EOF + echo -e "\e[0m" +else + print_feedback "Subsequent sync: Updating venv without overwriting existing files..." + rsync -aHx --info=progress2 --stats --exclude='*.pyc' --exclude='__pycache__' --ignore-existing --update "$SOURCE_VENV/" "$VIRTUAL_ENV/" +fi print_feedback "Activating virtual environment..." -export VIRTUAL_ENV="/workspace/venv" -export PATH="$VIRTUAL_ENV/bin:$PATH" source "$VIRTUAL_ENV/bin/activate" export PYTHONUNBUFFERED=1 @@ -61,7 +115,7 @@ print_feedback "ComfyUI will be available at http://0.0.0.0:3000" # Check if CUSTOM_ARGS is set and not empty if [ -n "$CUSTOM_ARGS" ]; then - exec python main.py --listen --port 3000 $CUSTOM_ARGS 2>&1 | tee -a $LOG_FILE + exec python main.py --listen --port 3000 --enable-cors-header $CUSTOM_ARGS 2>&1 | tee -a $LOG_FILE else - exec python main.py --listen --port 3000 2>&1 | tee -a $LOG_FILE -fi \ No newline at end of file + exec python main.py --listen --port 3000 --enable-cors-header 2>&1 | tee -a $LOG_FILE +fi