From da95729d900b7e8e62423361d6ac3d40c2716dfc Mon Sep 17 00:00:00 2001 From: "Armando C. Santisbon" Date: Sun, 11 Sep 2022 09:47:54 -0500 Subject: [PATCH] Refactor docker build and move docker assets to their own folder --- Dockerfile | 50 ---------------- README-Mac-Docker.md | 5 +- docker-build/Dockerfile | 63 +++++++++++++++++++++ entrypoint.sh => docker-build/entrypoint.sh | 0 4 files changed, 66 insertions(+), 52 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker-build/Dockerfile rename entrypoint.sh => docker-build/entrypoint.sh (100%) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 7258b4a620..0000000000 --- a/Dockerfile +++ /dev/null @@ -1,50 +0,0 @@ -FROM arm64v8/debian -MAINTAINER Armando C. Santisbon - -ARG gsd -ENV GITHUB_STABLE_DIFFUSION $gsd - -ARG sdreq="requirements-linux-arm64.txt" -ENV SD_REQ $sdreq - -WORKDIR / -COPY entrypoint.sh anaconda.sh . -SHELL ["/bin/bash", "-c"] - -RUN apt update && apt upgrade -y \ - && apt install -y \ - git \ - pip \ - python3 \ - wget \ - # install Anaconda or Miniconda - && bash anaconda.sh -b -u -p /anaconda && /anaconda/bin/conda init bash && source ~/.bashrc \ - && git clone $GITHUB_STABLE_DIFFUSION && cd stable-diffusion \ - # When path exists, pip3 will (w)ipe. - && PIP_EXISTS_ACTION="w" \ - # restrict the Conda environment to only use ARM packages. M1/M2 is ARM-based. You could also conda install nomkl. - && CONDA_SUBDIR="osx-arm64" \ - # Create the environment, activate it, install requirements. - && conda create -y --name ldm && conda activate ldm \ - && pip3 install -r $SD_REQ \ - - # Only need to do this once (we'll do it after we add face restoration and upscaling): - # && python3 scripts/preload_models.py \ - - && mkdir models/ldm/stable-diffusion-v1 \ - # [Optional] Face Restoration and Upscaling - && apt install -y libgl1-mesa-glx libglib2.0-0 \ - # by default expected in a sibling directory to stable-diffusion - && cd .. && git clone https://github.com/TencentARC/GFPGAN.git && cd GFPGAN \ - && pip3 install basicsr facexlib \ - && pip3 install -r requirements.txt \ - && python3 setup.py develop \ - # to enhance the background (non-face) regions and do upscaling - && pip3 install realesrgan \ - # pre-trained model needed for face restoration - && wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models \ - && cd ../stable-diffusion \ - # if we don't preload models it will download model files from the Internet the first time you run dream.py with GFPGAN and Real-ESRGAN turned on. - && python3 scripts/preload_models.py - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/README-Mac-Docker.md b/README-Mac-Docker.md index be2e837c54..b2f9a93a8d 100644 --- a/README-Mac-Docker.md +++ b/README-Mac-Docker.md @@ -51,7 +51,8 @@ GITHUB_STABLE_DIFFUSION="https://github.com/santisbon/stable-diffusion.git" cd ~ git clone $GITHUB_STABLE_DIFFUSION -cd stable-diffusion + +cd stable-diffusion/docker-build chmod +x entrypoint.sh # download the Miniconda installer. We'll need it at build time. wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O anaconda.sh && chmod +x anaconda.sh @@ -137,7 +138,7 @@ wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pt cd ../stable-diffusion ``` -Only need to do this once. If we don't preload models it will download model files from the Internet when you run ```dream.py```. +Only need to do this once. If we don't preload models it will download model files from the Internet when you run ```dream.py```. Used by the core functionality and by GFPGAN/Real-ESRGAN. ```Shell python3 scripts/preload_models.py ``` diff --git a/docker-build/Dockerfile b/docker-build/Dockerfile new file mode 100644 index 0000000000..3f4a8a0160 --- /dev/null +++ b/docker-build/Dockerfile @@ -0,0 +1,63 @@ +FROM arm64v8/debian + +ARG gsd +ENV GITHUB_STABLE_DIFFUSION $gsd +ARG sdreq="requirements-linux-arm64.txt" +ENV SD_REQ $sdreq + +WORKDIR / + +COPY entrypoint.sh anaconda.sh . +SHELL ["/bin/bash", "-c"] + +# Update and apt +RUN apt update && apt upgrade -y \ + && apt install -y \ + git \ + pip \ + python3 \ + wget + +# install Anaconda or Miniconda +RUN bash anaconda.sh -b -u -p /anaconda && /anaconda/bin/conda init bash + +# SD repo +RUN git clone $GITHUB_STABLE_DIFFUSION + +WORKDIR /stable-diffusion + +# SD env +RUN PIP_EXISTS_ACTION="w" \ + # restrict the Conda environment to only use ARM packages. M1/M2 is ARM-based. You could also conda install nomkl. + && CONDA_SUBDIR="osx-arm64" \ + # Create the environment, activate it, install requirements. + && source ~/.bashrc && conda create -y --name ldm && conda activate ldm \ + && pip3 install -r $SD_REQ \ + && mkdir models/ldm/stable-diffusion-v1 + +# Face restoration prerequisites +RUN apt install -y libgl1-mesa-glx libglib2.0-0 + # by default expected in a sibling directory to stable-diffusion + +WORKDIR / + +# Face restoreation repo +RUN git clone https://github.com/TencentARC/GFPGAN.git + +WORKDIR /GFPGAN + +# Face restoration env +RUN pip3 install basicsr facexlib \ + && pip3 install -r requirements.txt \ + && python3 setup.py develop \ + # to enhance the background (non-face) regions and do upscaling + && pip3 install realesrgan \ + # pre-trained model needed for face restoration + && wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models + +WORKDIR /stable-diffusion + +# Preload models +RUN python3 scripts/preload_models.py + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/docker-build/entrypoint.sh similarity index 100% rename from entrypoint.sh rename to docker-build/entrypoint.sh