From 68afd2b96845d54b4cb1d7396e891fc06ccb84d0 Mon Sep 17 00:00:00 2001 From: fapoverflow <50244958+fapoverflow@users.noreply.github.com> Date: Thu, 31 Jul 2025 02:12:04 +0200 Subject: [PATCH] Add swarmui --- data/.gitignore | 8 +-- docker-compose.yml | 52 +++++++++++------ services/convert2safetensors/entrypoint.sh | 1 - services/swarmui/Dockerfile | 68 ++++++++++++++++++++++ services/swarmui/entrypoint.sh | 20 +++++++ 5 files changed, 124 insertions(+), 25 deletions(-) create mode 100644 services/swarmui/Dockerfile create mode 100644 services/swarmui/entrypoint.sh diff --git a/data/.gitignore b/data/.gitignore index 1241499..a68d087 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,6 +1,2 @@ -/.cache -/config -/embeddings -/models -/states -/convert +/* +!/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index 2fc68e3..3456818 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,7 @@ x-base_service: &base_service - volumes: - - &v1 ./data:/data - - &v2 ./output:/output stop_signal: SIGKILL tty: true + restart: unless-stopped deploy: resources: # limits: @@ -17,6 +15,17 @@ x-base_service: &base_service device_ids: ['0'] capabilities: [compute, utility, gpu] +x-auto_service: &auto_service + <<: *base_service + container_name: auto + build: ./services/AUTOMATIC1111 + image: sd-auto:78 + ports: + - "${WEBUI_PORT:-7860}:7860" + volumes: + - &v1 ./data:/data + - &v2 ./output:/output + name: webui-docker services: @@ -26,18 +35,14 @@ services: volumes: - *v1 - auto: &automatic - <<: *base_service + auto: + <<: *auto_service profiles: ["auto"] - build: ./services/AUTOMATIC1111 - image: sd-auto:78 - ports: - - "${WEBUI_PORT:-7860}:7860" environment: - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api auto-cpu: - <<: *automatic + <<: *auto_service profiles: ["auto-cpu"] deploy: {} ports: @@ -45,10 +50,17 @@ services: environment: - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api + auto-full: + <<: *auto_service + profiles: [ "full" ] + environment: + - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --no-half-vae --api + comfy: &comfy <<: *base_service profiles: ["comfy"] - build: ./services/comfy/ + container_name: comfy + build: ./services/comfy image: sd-comfy:7 volumes: - ./data/models:/opt/comfyui/models @@ -72,15 +84,19 @@ services: environment: - CLI_ARGS=--cpu - auto-full: + swarmui: <<: *base_service - profiles: [ "full" ] - build: ./services/AUTOMATIC1111 - image: sd-auto:78 - environment: - - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api + profiles: ["swarmui"] + container_name: swarmui + build: ./services/swarmui + image: sd-swarmui ports: - - "${WEBUI_PORT:-7860}:7860" + - "${SWARMUI_PORT:-7801}:7801" + volumes: + - ./data/swarmui:/SwarmUI/Data +# - "backend:/app/dlbackend" + - ./data/models:/SwarmUI/Models + - ./output/swarmui:/SwarmUI/Output convertor: <<: *base_service diff --git a/services/convert2safetensors/entrypoint.sh b/services/convert2safetensors/entrypoint.sh index 3500eb5..091bb63 100644 --- a/services/convert2safetensors/entrypoint.sh +++ b/services/convert2safetensors/entrypoint.sh @@ -2,5 +2,4 @@ set -ex echo "Running container as $USER" -echo "Running container as $USER..." python convert_2_safetensors.py --source ./models/input --dest ./models/output --allow-pickle diff --git a/services/swarmui/Dockerfile b/services/swarmui/Dockerfile new file mode 100644 index 0000000..9d8fc9f --- /dev/null +++ b/services/swarmui/Dockerfile @@ -0,0 +1,68 @@ +ARG SWARMUI_VERSION=0.9.6-Beta +ARG DOTNET_VERSION=8.0-bookworm-slim + +FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build +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 && \ + apt-get install -y git + +WORKDIR ${SWARM_PATH} + +# Clones the SwarmUI repository and checks out the latest release +RUN git clone --depth=1 https://github.com/mcmonkeyprojects/SwarmUI.git ${SWARM_PATH} && \ + cd ${SWARM_PATH} && \ + git fetch origin ${SWARMUI_VERSION} && \ + git checkout FETCH_HEAD + +RUN dotnet build src/SwarmUI.csproj --configuration Release -o ./bin + +# RUN +FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim +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 + +ARG GPU_TYPE="nv" +ENV NVIDIA_VISIBLE_DEVICES=all +ENV CLI_ARGS="" + +RUN addgroup --gid $SWARMUI_GROUP_ID swarmui && \ + adduser --uid $SWARMUI_USER_ID --gid $SWARMUI_GROUP_ID --gecos "" --disabled-password swarmui + +COPY --from=build ${SWARM_PATH} "${SWARM_PATH}/" + +RUN mkdir -p "${SWARM_PATH}/Data" && \ + chown -R swarmui:swarmui ${SWARM_PATH} +ENV HOME=${SWARM_PATH} + +RUN --mount=type=cache,target=/var/cache/apt \ + apt update --assume-yes && \ + apt install -y \ + git \ + wget \ + build-essential \ + python3.11 \ + python3.11-venv \ + python3.11-dev \ + python3-pip \ + ffmpeg \ + libglib2.0-0 \ + libgl1 + +WORKDIR ${SWARM_PATH} + +USER swarmui + +RUN chmod +x ${SWARM_PATH}/launchtools/comfy-install-linux.sh && \ + ${SWARM_PATH}/launchtools/comfy-install-linux.sh ${GPU_TYPE} + +EXPOSE 7801 + +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh", "--launch_mode", "none", "--host", "0.0.0.0"] diff --git a/services/swarmui/entrypoint.sh b/services/swarmui/entrypoint.sh new file mode 100644 index 0000000..34e001b --- /dev/null +++ b/services/swarmui/entrypoint.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Ensure correct local path. +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPT_DIR" + +# Add dotnet non-admin-install to path +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" +# Actual runner. +cd "$HOME" +dotnet ./bin/SwarmUI.dll "$@" + +# Exit code 42 means restart, anything else = don't. +if [ $? == 42 ]; then + . /entrypoint.sh "$@" +fi