Skip to content

Instantly share code, notes, and snippets.

@stzsch
Last active May 7, 2024 15:41
Show Gist options
  • Save stzsch/2abfecdacc2aa0ef94584d2241b59adc to your computer and use it in GitHub Desktop.
Save stzsch/2abfecdacc2aa0ef94584d2241b59adc to your computer and use it in GitHub Desktop.
stable-diffusion-webui
# https://gist.github.com/stzsch/2abfecdacc2aa0ef94584d2241b59adc
FROM alpine AS xformers-downloader
RUN apk add parallel aria2
RUN aria2c -x 5 --dir / --out wheel.whl 'https://files.pythonhosted.org/packages/bb/6b/3f65a46b9d25e7fbcc3385f8b8e69e940b3b547697f74e07ab9c1656640a/xformers-0.0.17.dev466-cp310-cp310-manylinux2014_x86_64.whl'
# Download stable-diffusion repository on alpine/git image
FROM alpine/git AS stable-diffusion-downloader
ENV STABLE_DIFFUSION_COMMIT_HASH=47b6b607fdd31875c9279cd2f4f16b92e4ea958e
WORKDIR /
RUN git clone https://github.com/Stability-AI/stablediffusion.git \
&& cd stablediffusion \
&& git checkout ${STABLE_DIFFUSION_HASH}
# Download taming-transformers repository on alpine/git image
FROM alpine/git AS taming-transformers-downloader
ENV TAMING_TRANSFORMERS_COMMIT_HASH=24268930bf1dce879235a7fddd0b2355b84d7ea6
WORKDIR /
RUN git clone https://github.com/CompVis/taming-transformers.git \
&& cd taming-transformers \
&& git checkout ${TAMING_TRANSFORMERS_HASH}
# Download k-diffusion repository on alpine/git image
FROM alpine/git AS k-diffusion-downloader
ENV K_DIFFUSION_COMMIT_HASH=5b3af030dd83e0297272d861c19477735d0317ec
WORKDIR /
RUN git clone https://github.com/crowsonkb/k-diffusion.git \
&& cd k-diffusion \
&& git checkout ${K_DIFFUSION_HASH}
# Download CodeFormer repository on alpine/git image
FROM alpine/git AS codeformer-downloader
ENV CODEFORMER_COMMIT_HASH=c5b4593074ba6214284d6acd5f1719b6c5d739af
WORKDIR /
RUN git clone https://github.com/sczhou/CodeFormer.git \
&& cd CodeFormer \
&& git checkout ${CODE_FORMER_HASH}
# Download BLIP repository on alpine/git image
FROM alpine/git AS blip-downloader
ENV BLIP_COMMIT_HASH=48211a1594f1321b00f14c9f7a5b4813144b2fb9
WORKDIR /
RUN git clone https://github.com/salesforce/BLIP.git \
&& cd BLIP \
&& git checkout ${BLIP_HASH}
# Download clip-interrogator repository on alpine/git image
FROM alpine/git AS clip-interrogator-downloader
ENV CLIP_INTERROGATOR_COMMIT_HASH=08546eae22d825a23f30669e10025098bb4f9dde
WORKDIR /
RUN git clone https://github.com/pharmapsychotic/clip-interrogator.git \
&& cd clip-interrogator \
&& git checkout ${CLIP_INTERROGATOR_HASH}
# Copy repositories to python:3.10-slim image
FROM python:3.10-slim
SHELL ["/bin/bash", "-ceuxo", "pipefail"]
ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1
RUN apt-get update && apt install -y git fonts-dejavu-core rsync git jq moreutils && apt-get clean
COPY --from=xformers-downloader /wheel.whl /xformers-0.0.17.dev466-cp310-cp310-manylinux2014_x86_64.whl
RUN --mount=type=cache,target=/root/.cache/pip \
pip install triton /xformers-0.0.17.dev466-cp310-cp310-manylinux2014_x86_64.whl
ENV TORCH_COMMAND="pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117"
ENV XFORMERS_PACKAGE="xformers==0.0.16rc425"
ENV GFPGAN_PACKAGE="git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379"
ENV CLIP_PACKAGE="git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1"
ENV OPENCLIP_PACKAGE="git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b"
ENV BITSANDBYTES_PACKAGE="git+https://github.com/TimDettmers/bitsandbytes.git@0f5c3948709ae70cf733cefbd831aaea8a4e38c9"
ENV DIFFUSERS_PACKAGE="git+https://github.com/huggingface/diffusers@f20c8f5a1aba27f5972cad50516f18ba516e4d9e"
RUN --mount=type=cache,target=/root/.cache/pip \
pip install pyngrok \
${GFPGAN_PACKAGE} \
${CLIP_PACKAGE} \
${OPENCLIP_PACKAGE} \
${BITSANDBYTES_PACKAGE} \
${DIFFUSERS_PACKAGE}
RUN --mount=type=cache,target=/root/.cache/pip pip install -U opencv-python-headless
ENV AUTOMATIC1111_COMMIT_HASH=a9fed7c364061ae6efb37f797b6b522cb3cf7aa2
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git \
&& cd stable-diffusion-webui \
&& git checkout ${AUTOMATIC1111_COMMIT_HASH}
WORKDIR /stable-diffusion-webui
RUN mkdir -p repositories
COPY --from=stable-diffusion-downloader /stablediffusion /stable-diffusion-webui/repositories/stable-diffusion-stability-ai
COPY --from=taming-transformers-downloader /taming-transformers /stable-diffusion-webui/repositories/taming-transformers
COPY --from=k-diffusion-downloader /k-diffusion /stable-diffusion-webui/repositories/k-diffusion
COPY --from=codeformer-downloader /CodeFormer /stable-diffusion-webui/repositories/CodeFormer
COPY --from=blip-downloader /BLIP /stable-diffusion-webui/repositories/BLIP
COPY --from=clip-interrogator-downloader /clip-interrogator /stable-diffusion-webui/repositories/clip-interrogator
RUN mkdir /stable-diffusion-webui/interrogate && cp /stable-diffusion-webui/repositories/clip-interrogator/clip_interrogator/data/* /stable-diffusion-webui/interrogate
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r /stable-diffusion-webui/repositories/CodeFormer/requirements.txt
RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0
ENV LIBGL_ALWAYS_INDIRECT=1
WORKDIR /stable-diffusion-webui
RUN python launch.py --skip-torch-cuda-test --exit
WORKDIR /stable-diffusion-webui
RUN mkdir -p /docker
COPY ./entrypoint.sh /docker/
WORKDIR /stable-diffusion-webui
ENV CLI_ARGS=""
EXPOSE 7860
RUN chmod +x /docker/entrypoint.sh
ENTRYPOINT ["/docker/entrypoint.sh"]
CMD python -u webui.py --listen --port 7860 ${CLI_ARGS}
#!/bin/bash
set -Eeuo pipefail
declare -A MOUNTS
MOUNTS["/root/.cache"]="/data/.cache"
# main
MOUNTS["/stable-diffusion-webui/models/Stable-diffusion"]="/data/Stable-diffusion"
MOUNTS["/stable-diffusion-webui/models/VAE"]="/data/VAE"
MOUNTS["/stable-diffusion-webui/models/Codeformer"]="/data/Codeformer"
MOUNTS["/stable-diffusion-webui/models/GFPGAN"]="/data/GFPGAN"
MOUNTS["/stable-diffusion-webui/models/ESRGAN"]="/data/ESRGAN"
MOUNTS["/stable-diffusion-webui/models/BSRGAN"]="/data/BSRGAN"
MOUNTS["/stable-diffusion-webui/models/RealESRGAN"]="/data/RealESRGAN"
MOUNTS["/stable-diffusion-webui/models/SwinIR"]="/data/SwinIR"
MOUNTS["/stable-diffusion-webui/models/ScuNET"]="/data/ScuNET"
MOUNTS["/stable-diffusion-webui/models/LDSR"]="/data/LDSR"
MOUNTS["/stable-diffusion-webui/models/hypernetworks"]="/data/Hypernetworks"
MOUNTS["/stable-diffusion-webui/models/torch_deepdanbooru"]="/data/Deepdanbooru"
MOUNTS["/stable-diffusion-webui/models/BLIP"]="/data/BLIP"
MOUNTS["/stable-diffusion-webui/models/midas"]="/data/MiDaS"
MOUNTS["/stable-diffusion-webui/models/Lora"]="/data/Lora"
MOUNTS["/stable-diffusion-webui/models/dreambooth"]="/data/dreambooth"
MOUNTS["/stable-diffusion-webui/embeddings"]="/data/embeddings"
MOUNTS["/stable-diffusion-webui/config.json"]="/data/config/config.json"
MOUNTS["/stable-diffusion-webui/ui-config.json"]="/data/config/ui-config.json"
# MOUNTS["/stable-diffusion-webui/extensions"]="/data/extensions"
# extra hacks
MOUNTS["/stable-diffusion-webui/repositories/CodeFormer/weights/facelib"]="/data/.cache"
for to_path in "${!MOUNTS[@]}"; do
set -Eeuo pipefail
from_path="${MOUNTS[${to_path}]}"
rm -rf "${to_path}"
if [ ! -f "$from_path" ]; then
mkdir -vp "$from_path"
fi
mkdir -vp "$(dirname "${to_path}")"
ln -sT "${from_path}" "${to_path}"
echo Mounted $(basename "${from_path}")
done
# Find all requirements.txt files recursively
files=$(find /data/extensions -name "requirements.txt")
# Loop through each file and run pip install
for file in $files
do
pip install --default-timeout=1000 -r $file
done
mkdir -p /output/saved /output/txt2img-images/ /output/img2img-images /output/extras-images/ /output/grids/ /output/txt2img-grids/ /output/img2img-grids/
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment