diff --git a/docker-compose.yml b/docker-compose.yml index 617545d..1864239 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,17 +15,20 @@ x-base_service: &base_service device_ids: ['0'] capabilities: [compute, utility, gpu] -x-auto_service: &auto_service +x-defaults: &defaults <<: *base_service - container_name: auto - build: ./services/AUTOMATIC1111 - image: sd-auto:78 ports: - "${WEBUI_PORT:-7860}:7860" volumes: - &v1 ./data:/data - &v2 ./output:/output +x-auto_service: &auto_service + <<: *defaults + container_name: auto + build: ./services/AUTOMATIC1111 + image: sd-auto:78 + name: webui-docker services: @@ -45,8 +48,6 @@ services: <<: *auto_service profiles: ["auto-cpu"] deploy: {} - ports: - - "${WEBUI_PORT:-7860}:7860" environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api @@ -57,8 +58,9 @@ services: - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --no-half-vae --api auto-rocm: - <<: *base_service + <<: *auto_service profiles: ["auto-rocm"] + container_name: auto-rocm build: context: ./services/AUTOMATIC1111 dockerfile: ROCM.dockerfile @@ -77,9 +79,9 @@ services: image: sd-comfy:7 volumes: - ./data/models:/opt/comfyui/models + - ./data/models/configs:/opt/comfyui/user/default/ - ./data/config/comfy/custom_nodes:/opt/comfyui/custom_nodes - ./output/comfy:/opt/comfyui/output - - ./data/models/configs:/opt/comfyui/user/default/ ports: - "${COMFYUI_PORT:-7861}:7861" environment: @@ -107,10 +109,15 @@ services: - "${SWARMUI_PORT:-7801}:7801" volumes: - ./data/swarmui:/SwarmUI/Data -# - "backend:/app/dlbackend" - ./data/models:/SwarmUI/Models - ./data/embeddings:/SwarmUI/Models/Embeddings +# comfyui + - ./data/config/comfy/custom_nodes:/SwarmUI/dlbackend/ComfyUI/custom_nodes* +# TODO fix permissions + - ./data/models/configs:/SwarmUI/dlbackend/ComfyUI/user/default/ +# output - ./output/swarmui:/SwarmUI/Output + - ./output/swarmui/comfy:/SwarmUI/dlbackend/ComfyUI/output reforge: &reforge <<: *base_service diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index 5143c1b..d007e95 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -31,8 +31,8 @@ rsync --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ declare -A MOUNTS -#MOUNTS["/root/.cache"]="/data/.cache" -MOUNTS["${USER_HOME}/.cache"]="/data/.cache" +MOUNTS["/root/.cache"]="/data/.cache" +#MOUNTS["${USER_HOME}/.cache"]="/data/.cache" MOUNTS["${ROOT}/models"]="/data/models" MOUNTS["${ROOT}/embeddings"]="/data/embeddings" @@ -60,11 +60,11 @@ done echo "Installing extension dependencies (if any)" -chown -R $PUID:$PGID ~/.cache/ -chmod 766 ~/.cache/ - -chown -R $PUID:$PGID /output -chmod 766 /output +#chown -R $PUID:$PGID ~/.cache/ +#chmod 766 ~/.cache/ +# +#chown -R $PUID:$PGID /output +#chmod 766 /output shopt -s nullglob # For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy diff --git a/services/comfy/Dockerfile b/services/comfy/Dockerfile index 89ce958..783c5d1 100644 --- a/services/comfy/Dockerfile +++ b/services/comfy/Dockerfile @@ -1,5 +1,5 @@ # Defines the versions of ComfyUI, ComfyUI Manager, and PyTorch to use -ARG COMFYUI_VERSION=v0.3.44 +ARG COMFYUI_VERSION=v0.3.50 ARG COMFYUI_MANAGER_VERSION=3.33.8 ARG PYTORCH_VERSION=2.7.1-cuda12.8-cudnn9-runtime diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile index 9d8fc9f..b328c65 100644 --- a/services/swarmui/Dockerfile +++ b/services/swarmui/Dockerfile @@ -1,10 +1,13 @@ ARG SWARMUI_VERSION=0.9.6-Beta +ARG COMFYUI_VERSION=v0.3.50 +ARG COMFYUI_MANAGER_VERSION=3.33.8 ARG DOTNET_VERSION=8.0-bookworm-slim +ARG SWARM_PATH="/SwarmUI" +#ENV SWARM_PATH=/opt/swarmui FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build +ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 -ENV SWARM_PATH="/SwarmUI" -#ENV SWARM_PATH=/opt/swarmui RUN --mount=type=cache,target=/var/cache/apt \ apt-get update && \ @@ -22,9 +25,9 @@ RUN dotnet build src/SwarmUI.csproj --configuration Release -o ./bin # RUN FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim +ARG SWARM_PATH ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 -ENV SWARM_PATH="/SwarmUI" -#ENV SWARM_PATH=/opt/swarmui + ARG SWARMUI_USER_ID=1000 ARG SWARMUI_GROUP_ID=1000 @@ -55,13 +58,31 @@ RUN --mount=type=cache,target=/var/cache/apt \ libglib2.0-0 \ libgl1 +RUN git clone --depth=1 https://github.com/comfyanonymous/ComfyUI.git /opt/comfyui && \ + cd /opt/comfyui && \ + git fetch origin ${COMFYUI_VERSION} && \ + git checkout FETCH_HEAD + +RUN git clone --depth=1 https://github.com/Comfy-Org/ComfyUI-Manager.git /opt/comfyui-manager && \ + cd /opt/comfyui-manager && \ + git fetch origin ${COMFYUI_MANAGER_VERSION} && \ + git checkout FETCH_HEAD + WORKDIR ${SWARM_PATH} +ENV COMFYUI_PATH="/SwarmUI/dlbackend/ComfyUI" +ENV CUSTOM_NODES_PATH="/SwarmUI/dlbackend/ComfyUI/custom_nodes" -USER swarmui - +COPY comfy-install-linux.sh ${SWARM_PATH}/launchtools/ RUN chmod +x ${SWARM_PATH}/launchtools/comfy-install-linux.sh && \ ${SWARM_PATH}/launchtools/comfy-install-linux.sh ${GPU_TYPE} +RUN chown -R swarmui:swarmui ${COMFYUI_PATH}/venv +RUN chown -R swarmui:swarmui ${COMFYUI_PATH} +RUN git config --global --add safe.directory ${COMFYUI_PATH} + +ENV PATH="${COMFYUI_PATH}/venv/bin:$PATH" +ENV PYTHONPATH="${CUSTOM_NODES_PATH}:${PYTHONPATH}" +USER swarmui EXPOSE 7801 COPY entrypoint.sh / diff --git a/services/swarmui/comfy-install-linux.sh b/services/swarmui/comfy-install-linux.sh new file mode 100644 index 0000000..fde2708 --- /dev/null +++ b/services/swarmui/comfy-install-linux.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +# Check if GPU type is provided +if [ $# -eq 0 ]; then + >&2 echo "Error: GPU type not specified. Please use 'amd' or 'nv' as an argument." + exit 1 +fi + +GPU_TYPE=$1 + +# Validate GPU type +if [ "$GPU_TYPE" != "amd" ] && [ "$GPU_TYPE" != "nv" ]; then + >&2 echo "Error: Invalid GPU type. Please use 'amd' or 'nv'." + exit 1 +fi + +mkdir dlbackend + +# Creates the symlink for the ComfyUI directory +echo "Creating symlink for ComfyUI..." +rm --force ${CUSTOM_NODES_PATH}/ComfyUI-Manager +ln -s \ + /opt/comfyui \ + ${COMFYUI_PATH} + +echo "Creating symlink for ComfyUI Manager..." +rm --force ${CUSTOM_NODES_PATH}/ComfyUI-Manager +ln -s \ + /opt/comfyui-manager \ + ${CUSTOM_NODES_PATH}/ComfyUI-Manager + +#cd ComfyUI +cd ${COMFYUI_PATH} + +# Try to find a good python executable, and dodge unsupported python versions +for pyvers in python3.11 python3.10 python3.12 python3 python +do + python=`which $pyvers` + if [ "$python" != "" ]; then + break + fi +done +if [ "$python" == "" ]; then + >&2 echo "ERROR: cannot find python3" + >&2 echo "Please follow the install instructions in the readme!" + exit 1 +fi + +# Validate venv +venv=`$python -m venv 2>&1` +case $venv in + *usage*) + : + ;; + *) + >&2 echo "ERROR: python venv is not installed" + >&2 echo "Please follow the install instructions in the readme!" + >&2 echo "If on Ubuntu/Debian, you may need: sudo apt install python3-venv" + exit 1 + ;; +esac + +# Make and activate the venv. "python3" in the venv is now the python executable. +if [ -z "${SWARM_NO_VENV}" ]; then + echo "Making venv..." + $python -s -m venv venv + source venv/bin/activate + python=python3 + python3 -m ensurepip --upgrade +else + echo "swarm_no_venv set, will not create venv" +fi + +# Install PyTorch based on GPU type +if [ "$GPU_TYPE" == "nv" ]; then + echo "install nvidia torch..." + $python -s -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu128 +elif [ "$GPU_TYPE" == "amd" ]; then + echo "install amd torch..." + $python -s -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.3 +fi + +echo "install general requirements..." +$python -s -m pip install --no-cache-dir \ + triton \ + sageattention \ + opencv-python \ + diffusers \ + psutil + +# Installs the required Python packages for both ComfyUI and the ComfyUI Manager +$python -s -m pip install --no-cache-dir \ + --requirement ${COMFYUI_PATH}/requirements.txt \ + --requirement ${CUSTOM_NODES_PATH}/ComfyUI-Manager/requirements.txt + +echo "Installation completed for $GPU_TYPE GPU." diff --git a/services/swarmui/entrypoint.sh b/services/swarmui/entrypoint.sh index 34e001b..168881c 100644 --- a/services/swarmui/entrypoint.sh +++ b/services/swarmui/entrypoint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +#set -x # Ensure correct local path. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$SCRIPT_DIR" @@ -10,6 +10,32 @@ export PATH="$SCRIPT_DIR/.dotnet:~/.dotnet:$PATH" # Default env configuration, gets overwritten by the C# code's settings handler export ASPNETCORE_ENVIRONMENT="Production" export ASPNETCORE_URLS="http://*:7801" + +# TODO fix permissions +#chown -R swarmui:swarmui ${COMFYUI_PATH}/user/default/ +chmod -R 755 ${COMFYUI_PATH}/user/default/ +chmod -R 755 /opt/comfyui/user/default/ + +echo "Using Python at: $(which python)" +echo "Python version: $(python --version)" + +# The custom nodes that were installed using the ComfyUI Manager may have requirements of their own, which are not installed when the container is +# started for the first time; this loops over all custom nodes and installs the requirements of each custom node +echo "Installing requirements for custom nodes..." +for CUSTOM_NODE_DIRECTORY in ${CUSTOM_NODES_PATH}/*; +do + if [ "$CUSTOM_NODE_DIRECTORY" != "${CUSTOM_NODES_PATH}/ComfyUI-Manager" ]; + then + if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ]; + then + CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/} + CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ } + echo "Installing requirements for $CUSTOM_NODE_NAME..." + python3 -s -m pip install --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt" + fi + fi +done + # Actual runner. cd "$HOME" dotnet ./bin/SwarmUI.dll "$@"