|
| 1 | +FROM alpine/git:2.36.2 AS download |
| 2 | + |
| 3 | +COPY clone.sh /clone.sh |
| 4 | + |
| 5 | +RUN rm -rf "/usr/local/share/boost" |
| 6 | +RUN rm -rf "$AGENT_TOOLSDIRECTORY" |
| 7 | + |
| 8 | +RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ |
| 9 | + && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif |
| 10 | + |
| 11 | +RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9 |
| 12 | +RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c |
| 13 | +RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 |
| 14 | +RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f |
| 15 | +RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 |
| 16 | + |
| 17 | + |
| 18 | +FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime |
| 19 | +#FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime |
| 20 | + |
| 21 | +ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 |
| 22 | + |
| 23 | +RUN --mount=type=cache,target=/var/cache/apt \ |
| 24 | + apt-get update && \ |
| 25 | + # we need those |
| 26 | + apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ |
| 27 | + # extensions needs those |
| 28 | + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential libgoogle-perftools-dev && \ |
| 29 | + apt-get clean |
| 30 | + |
| 31 | +ARG PUID=0 |
| 32 | +ARG PGID=0 |
| 33 | +ARG USER_HOME=/root |
| 34 | +# set build args as container environment variables for entrypoint reference |
| 35 | +ENV PUID=$PUID |
| 36 | +ENV PGID=$PGID |
| 37 | +ENV USER_HOME=$USER_HOME |
| 38 | + |
| 39 | +# if user home does not exist, create it |
| 40 | +RUN mkdir -p "$USER_HOME" |
| 41 | + |
| 42 | +# home already exists, chown it |
| 43 | +RUN chown -R "${PUID}:${PGID}" "$USER_HOME" |
| 44 | + |
| 45 | +# Only groupadd if we're non root |
| 46 | +RUN if [ "$PGID" -ne "0" ]; then \ |
| 47 | + echo non root group detected; \ |
| 48 | + groupadd \ |
| 49 | + --gid "$PGID" \ |
| 50 | + stablediffusion ;\ |
| 51 | + else \ |
| 52 | + echo "root group detected" ; \ |
| 53 | + fi |
| 54 | + |
| 55 | +# Only useradd if we're non root |
| 56 | +RUN if [ "$PUID" -ne "0" ]; then \ |
| 57 | + echo non root user detected; \ |
| 58 | + useradd \ |
| 59 | + --gid="$PGID" \ |
| 60 | + --no-user-group \ |
| 61 | + -M \ |
| 62 | + --home "$USER_HOME" \ |
| 63 | + stablediffusion ; \ |
| 64 | + else \ |
| 65 | + echo "root group detected" ; \ |
| 66 | + fi |
| 67 | + |
| 68 | +WORKDIR / |
| 69 | +ENV ROOT=/stable-diffusion-webui |
| 70 | + |
| 71 | +RUN --mount=type=cache,target=/root/.cache/sd \ |
| 72 | + git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ${ROOT} && \ |
| 73 | + cd stable-diffusion-webui && \ |
| 74 | + git reset --hard v1.10.1 && \ |
| 75 | + pip install -r requirements_versions.txt |
| 76 | + |
| 77 | +RUN pip install --upgrade typing-extensions |
| 78 | + |
| 79 | + |
| 80 | +RUN if [ -d "/opt/conda/lib/python3.10" ]; then \ |
| 81 | + echo Python 3.10 detected; \ |
| 82 | + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py ;\ |
| 83 | + elif [ -d "/opt/conda/lib/python3.11" ]; then \ |
| 84 | + echo Python 3.11 detected; \ |
| 85 | + sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.11/site-packages/gradio/routes.py ;\ |
| 86 | + fi && \ |
| 87 | + # mv ${ROOT}/style.css ${ROOT}/user.css && \ |
| 88 | + # one of the ugliest hacks I ever wrote \ |
| 89 | + # updated from 3.10.to 3.11 |
| 90 | + git config --global --add safe.directory '*' |
| 91 | + |
| 92 | +# drop permissions (if build targets non root) |
| 93 | +#USER $PUID:$PGID |
| 94 | + |
| 95 | + |
| 96 | +COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ |
| 97 | +RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate |
| 98 | + |
| 99 | +RUN --mount=type=cache,target=/root/.cache/repos \ |
| 100 | + pip install pyngrok xformers==0.0.26.post1 \ |
| 101 | + git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ |
| 102 | + git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ |
| 103 | + git+https://github.com/mlfoundations/ [email protected] |
| 104 | + |
| 105 | +# there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc |
| 106 | +# maybe move this up to the dependencies list. |
| 107 | +ENV LD_PRELOAD=libtcmalloc.so |
| 108 | + |
| 109 | +COPY . /docker |
| 110 | +RUN chown -R "$PUID:$PGID" "${ROOT}" |
| 111 | +RUN chown -R "$PUID:$PGID" /docker |
| 112 | + |
| 113 | +WORKDIR ${ROOT} |
| 114 | +ENV NVIDIA_VISIBLE_DEVICES=all |
| 115 | +ENV CLI_ARGS="" |
| 116 | +EXPOSE 7860 |
| 117 | +ENTRYPOINT ["/docker/entrypoint.sh"] |
| 118 | +CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} |
0 commit comments