Dockerfile 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. FROM alpine/git:2.36.2 as download
  2. COPY clone.sh /clone.sh
  3. RUN . /clone.sh taming-transformers https://github.com/CompVis/taming-transformers.git 24268930bf1dce879235a7fddd0b2355b84d7ea6 \
  4. && rm -rf data assets **/*.ipynb
  5. RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git 47b6b607fdd31875c9279cd2f4f16b92e4ea958e \
  6. && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif
  7. RUN . /clone.sh CodeFormer https://github.com/sczhou/CodeFormer.git c5b4593074ba6214284d6acd5f1719b6c5d739af \
  8. && rm -rf assets inputs
  9. RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9
  10. RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git 5b3af030dd83e0297272d861c19477735d0317ec
  11. RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2486589f24165c8e3b303f84e9dbbea318df83e8
  12. FROM alpine:3.17 as xformers
  13. RUN apk add --no-cache aria2
  14. RUN aria2c -x 5 --dir / --out wheel.whl 'https://github.com/AbdBarho/stable-diffusion-webui-docker/releases/download/6.0.0/xformers-0.0.21.dev544-cp310-cp310-manylinux2014_x86_64-pytorch201.whl'
  15. FROM python:3.10.9-slim
  16. ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1
  17. RUN --mount=type=cache,target=/var/cache/apt \
  18. apt-get update && \
  19. # we need those
  20. apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \
  21. # extensions needs those
  22. ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev
  23. RUN --mount=type=cache,target=/cache --mount=type=cache,target=/root/.cache/pip \
  24. aria2c -x 5 --dir /cache --out torch-2.0.1-cp310-cp310-linux_x86_64.whl -c \
  25. https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-linux_x86_64.whl && \
  26. pip install /cache/torch-2.0.1-cp310-cp310-linux_x86_64.whl torchvision --index-url https://download.pytorch.org/whl/cu118
  27. RUN --mount=type=cache,target=/root/.cache/pip \
  28. git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \
  29. cd stable-diffusion-webui && \
  30. git reset --hard 20ae71faa8ef035c31aa3a410b707d792c8203a3 && \
  31. pip install -r requirements_versions.txt
  32. RUN --mount=type=cache,target=/root/.cache/pip \
  33. --mount=type=bind,from=xformers,source=/wheel.whl,target=/xformers-0.0.21.dev544-cp310-cp310-manylinux2014_x86_64.whl \
  34. pip install /xformers-0.0.21.dev544-cp310-cp310-manylinux2014_x86_64.whl
  35. ENV ROOT=/stable-diffusion-webui
  36. COPY --from=download /repositories/ ${ROOT}/repositories/
  37. RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/data/* ${ROOT}/interrogate
  38. RUN --mount=type=cache,target=/root/.cache/pip \
  39. pip install -r ${ROOT}/repositories/CodeFormer/requirements.txt
  40. RUN --mount=type=cache,target=/root/.cache/pip \
  41. pip install pyngrok \
  42. git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \
  43. git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \
  44. git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b
  45. # Note: don't update the sha of previous versions because the install will take forever
  46. # instead, update the repo state in a later step
  47. # TODO: either remove if fixed in A1111 (unlikely) or move to the top with other apt stuff
  48. RUN apt-get -y install libgoogle-perftools-dev && apt-get clean
  49. ENV LD_PRELOAD=libtcmalloc.so
  50. ARG SHA=20ae71faa8ef035c31aa3a410b707d792c8203a3
  51. RUN --mount=type=cache,target=/root/.cache/pip \
  52. cd stable-diffusion-webui && \
  53. git fetch && \
  54. git reset --hard ${SHA} && \
  55. pip install -r requirements_versions.txt
  56. COPY . /docker
  57. RUN \
  58. python3 /docker/info.py ${ROOT}/modules/ui.py && \
  59. mv ${ROOT}/style.css ${ROOT}/user.css && \
  60. # one of the ugliest hacks I ever wrote \
  61. sed -i 's/in_app_dir = .*/in_app_dir = True/g' /usr/local/lib/python3.10/site-packages/gradio/routes.py && \
  62. git config --global --add safe.directory '*'
  63. WORKDIR ${ROOT}
  64. ENV NVIDIA_VISIBLE_DEVICES=all
  65. ENV CLI_ARGS=""
  66. EXPOSE 7860
  67. ENTRYPOINT ["/docker/entrypoint.sh"]
  68. CMD python -u webui.py --listen --port 7860 ${CLI_ARGS}