From a219b6c25157166ad8f005c8d3181d49f686de83 Mon Sep 17 00:00:00 2001 From: Cloud Axes Date: Tue, 9 May 2023 20:53:35 +0900 Subject: [PATCH] Add shell script (services/AUTOMATIC1111/download_automatic_extensions.sh) that downloads Automatic1111 extensions with specific hashes specified in a text file (services/AUTOMATIC1111/automatic1111_extensions.txt). The Dockerfile now also downloads the extensions in order to install their pip requirements. --- services/AUTOMATIC1111/Dockerfile | 15 ++++++- .../automatic1111_extensions.txt | 7 +++ .../download_automatic1111_extensions.sh | 43 +++++++++++++++++++ services/AUTOMATIC1111/entrypoint.sh | 3 ++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 services/AUTOMATIC1111/automatic1111_extensions.txt create mode 100644 services/AUTOMATIC1111/download_automatic1111_extensions.sh diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 580dea1..8a78991 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -21,7 +21,7 @@ RUN apk add --no-cache aria2 RUN aria2c -x 5 --dir / --out wheel.whl 'https://github.com/AbdBarho/stable-diffusion-webui-docker/releases/download/5.0.3/xformers-0.0.20.dev528-cp310-cp310-manylinux2014_x86_64-pytorch2.whl' -FROM python:3.10.9-slim +FROM python:3.10.9 ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 @@ -76,6 +76,19 @@ RUN --mount=type=cache,target=/root/.cache/pip pip install -U opencv-python-hea COPY . /docker +# Download extensions, install python pip dependencies, then throw extensions away +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/.automatic_extensions_cache \ + apt-get update && apt-get install libgl1 -y && \ + chmod +x /docker/download_automatic1111_extensions.sh && \ + /docker/download_automatic1111_extensions.sh /docker/automatic1111_extensions.txt /.automatic_extensions_cache && \ + cd /.automatic_extensions_cache && \ + for extension_name in */; do \ + if [ -e $extension_name/requirements.txt ]; then \ + pip install -r $extension_name/requirements.txt; \ + fi ; \ + done ; + RUN \ python3 /docker/info.py ${ROOT}/modules/ui.py && \ mv ${ROOT}/style.css ${ROOT}/user.css && \ diff --git a/services/AUTOMATIC1111/automatic1111_extensions.txt b/services/AUTOMATIC1111/automatic1111_extensions.txt new file mode 100644 index 0000000..1a992f5 --- /dev/null +++ b/services/AUTOMATIC1111/automatic1111_extensions.txt @@ -0,0 +1,7 @@ +https://github.com/yfszzx/stable-diffusion-webui-images-browser.git a42c7a30181636a05815e62426d5eff4d3340529 +https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git 40edb89974d55d496722a1ef6de95494a6f1f7fe +https://github.com/adieyal/sd-dynamic-prompts a53adac96e0872b19e08a4f691ff680c5896aa13 +https://github.com/nonnonstop/sd-webui-3d-open-pose-editor f2d5aac51d891bc5f266b1549f3cf4495fc52160 +https://github.com/kohya-ss/sd-webui-additional-networks 75141070b71cb46c1d3e7a44286740fe6818bccd +https://github.com/Mikubill/sd-webui-controlnet 791b451c4ea36570cc67f385bd1a961b956be6be + diff --git a/services/AUTOMATIC1111/download_automatic1111_extensions.sh b/services/AUTOMATIC1111/download_automatic1111_extensions.sh new file mode 100644 index 0000000..8d2aa91 --- /dev/null +++ b/services/AUTOMATIC1111/download_automatic1111_extensions.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# download_automatic1111_extensions.sh ensures that Automatic1111 extensions +# are installed in a given directory and set at a particular git commit +# +# The first argument is a file containing a list of git repository URLs of +# extensions andcorresponding hashes, one repo/hash pair per line. Comments +# are allowed in this file, following a hash. +# +# The second argument is the extensions directory where the extensions will +# be installed. +# +# If the repositories are already installed and the correct +# commit is checked out, this script does not require internet access, and +# should be fairly quick. +echo "Running download_automatic1111_extensions.sh, reading from repo/hash file " $1 ", putting extensions into " $2 +mkdir -p $2 # Create the destination directory if it doesn't exist already. +command | while read -r line; do { # read each line of repo/hash pairs. + line_stripped_of_comments=$(echo $line | sed -e 's/\#.*//g') # strip everything after hash. + if [[ $line_stripped_of_comments = *[![:space:]]* ]]; then # check if there's a non-comment, non-whitespace on this line + git_repo_url=$(echo $line | awk '{print $1;}') + commit_hash=$(echo $line | awk '{print $2;}') + pushd $2 > /dev/null + extension_name=$(echo $git_repo_url | sed -e 's/.*\///' -e 's/\.git.*//') + echo "Reading $git_repo_url, and putting hash $commit_hash into $2/$extension_name" + if [ ! -d "$extension_name" ]; then + echo "$extension_name doesn't exist yet, cloning it" + git clone "$git_repo_url" "$extension_name" + else + echo "$extension_name already present on disk" + fi + cd "$extension_name" + if [ $(git rev-parse --verify HEAD) != $commit_hash ]; then + echo "$extension_name is not at the right commit, checking out $commit_hash" + git fetch --all + git reset --hard $commit_hash + else + echo "$extension_name is already at the right commit, $commit_hash" + fi + popd > /dev/null + fi +}; done < $1 +echo "Finished running download_automatic1111_extensions.sh" diff --git a/services/AUTOMATIC1111/entrypoint.sh b/services/AUTOMATIC1111/entrypoint.sh index 54e709c..261b7a2 100755 --- a/services/AUTOMATIC1111/entrypoint.sh +++ b/services/AUTOMATIC1111/entrypoint.sh @@ -2,6 +2,9 @@ set -Eeuo pipefail +#Download extensions +/docker/download_automatic1111_extensions.sh /docker/automatic1111_extensions.txt /data/config/auto/extensions/ + # TODO: move all mkdir -p ? mkdir -p /data/config/auto/scripts/ # mount scripts individually