From 5f62de5e3e8d29e9e043ba1abf5bbe3e62a1be5e Mon Sep 17 00:00:00 2001 From: mauwii Date: Fri, 25 Nov 2022 04:40:27 +0100 Subject: [PATCH 01/10] update dockerfile --- .dockerignore | 14 ++++- .github/workflows/build-container.yml | 19 +++--- docker-build/Dockerfile | 83 ++++++++------------------- docker-build/build.sh | 52 +++++------------ docker-build/entrypoint.sh | 8 --- docker-build/models.yaml | 8 --- 6 files changed, 55 insertions(+), 129 deletions(-) delete mode 100755 docker-build/entrypoint.sh delete mode 100644 docker-build/models.yaml diff --git a/.dockerignore b/.dockerignore index 8a0ebc50696..0c264042c94 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,13 @@ * -!environment*.yml -!docker-build +!backend +!configs +!docker-build/entrypoint.sh +!environments-and-requirements +!frontend +!installer +!ldm +!main.py +!scripts +!server +!static +!setup.py diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index ec4a105a9e2..107eb5960bb 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -6,6 +6,7 @@ on: branches: - 'main' - 'development' + - 'update-dockerfile' jobs: docker: @@ -15,13 +16,11 @@ jobs: arch: - x86_64 - aarch64 - include: - - arch: x86_64 - conda-env-file: environment-lin-cuda.yml - - arch: aarch64 - conda-env-file: environment-lin-aarch64.yml + pip-requirements: + - requirements-lin-amd.txt + - requirements-lin-cuda.txt runs-on: ubuntu-latest - name: ${{ matrix.arch }} + name: ${{ matrix.pip-requirements }} ${{ matrix.arch }} steps: - name: prepare docker-tag env: @@ -40,9 +39,5 @@ jobs: file: docker-build/Dockerfile platforms: Linux/${{ matrix.arch }} push: false - tags: ${{ env.dockertag }}:${{ matrix.arch }} - build-args: | - conda_env_file=${{ matrix.conda-env-file }} - conda_version=py39_4.12.0-Linux-${{ matrix.arch }} - invokeai_git=${{ github.repository }} - invokeai_branch=${{ github.ref_name }} + tags: ${{ env.dockertag }}:${{ matrix.pip-requirements }}-${{ matrix.arch }} + build-args: pip_requirements=${{ matrix.pip-requirements }} diff --git a/docker-build/Dockerfile b/docker-build/Dockerfile index 0c47683bbd7..aedee8311c6 100644 --- a/docker-build/Dockerfile +++ b/docker-build/Dockerfile @@ -1,30 +1,8 @@ -FROM ubuntu AS get_miniconda - -SHELL ["/bin/bash", "-c"] - -# install wget -RUN apt-get update \ - && apt-get install -y \ - wget \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# download and install miniconda -ARG conda_version=py39_4.12.0-Linux-x86_64 -ARG conda_prefix=/opt/conda -RUN wget --progress=dot:giga -O /miniconda.sh \ - https://repo.anaconda.com/miniconda/Miniconda3-${conda_version}.sh \ - && bash /miniconda.sh -b -p ${conda_prefix} \ - && rm -f /miniconda.sh - FROM ubuntu AS invokeai # use bash SHELL [ "/bin/bash", "-c" ] -# clean bashrc -RUN echo "" > ~/.bashrc - # Install necesarry packages RUN apt-get update \ && apt-get install -y \ @@ -39,41 +17,26 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# clone repository, create models.yaml and create symlinks -ARG invokeai_git=invoke-ai/InvokeAI -ARG invokeai_branch=main -ARG project_name=invokeai -ARG conda_env_file=environment-lin-cuda.yml -RUN git clone -b ${invokeai_branch} https://github.com/${invokeai_git}.git "/${project_name}" \ - && ln -sf \ - "/${project_name}/environments-and-requirements/${conda_env_file}" \ - "/${project_name}/environment.yml" \ - && ln -sf \ - /data/outputs/ \ - "/${project_name}/outputs" - -# set workdir and copy models.yaml -WORKDIR "/${project_name}" -COPY docker-build/models.yaml configs/models.yaml - -# install conda env and preload models -ARG conda_prefix=/opt/conda -COPY --from=get_miniconda "${conda_prefix}" "${conda_prefix}" -RUN source "${conda_prefix}/etc/profile.d/conda.sh" \ - && conda init bash \ - && source ~/.bashrc \ - && conda env create \ - --name "${project_name}" \ - && rm -Rf ~/.cache \ - && conda clean -afy \ - && echo "conda activate ${project_name}" >> ~/.bashrc - -RUN source ~/.bashrc \ - && python scripts/preload_models.py \ - --no-interactive - -# Copy entrypoint and set env -ENV CONDA_PREFIX="${conda_prefix}" -ENV PROJECT_NAME="${project_name}" -COPY docker-build/entrypoint.sh / -ENTRYPOINT [ "/entrypoint.sh" ] +ARG PIP_REQUIREMENTS=requirements-lin-cuda.txt +ARG PROJECT_NAME=invokeai +ARG INVOKEAI_ROOT=/data +ENV INVOKEAI_ROOT=${INVOKEAI_ROOT} + +# set workdir and copy sources +WORKDIR /${PROJECT_NAME} +COPY . . + +# install requirements +RUN cp \ + ./environments-and-requirements/${PIP_REQUIREMENTS} \ + ${PIP_REQUIREMENTS} \ + && pip install -r ${PIP_REQUIREMENTS} +RUN pip install --no-cache-dir -e . + +# RUN source ~/.bashrc \ +# && python scripts/preload_models.py \ +# --no-interactive + +# copy and set Entrypoint +ENTRYPOINT [ "python3" ] +CMD [ "scripts/invoke.py", "--web", "--host", "0.0.0.0" ] diff --git a/docker-build/build.sh b/docker-build/build.sh index c7b94d7c0ec..803aadb87e0 100755 --- a/docker-build/build.sh +++ b/docker-build/build.sh @@ -6,12 +6,7 @@ set -e source ./docker-build/env.sh || echo "please run from repository root" || exit 1 -invokeai_conda_version=${INVOKEAI_CONDA_VERSION:-py39_4.12.0-${platform/\//-}} -invokeai_conda_prefix=${INVOKEAI_CONDA_PREFIX:-\/opt\/conda} -invokeai_conda_env_file=${INVOKEAI_CONDA_ENV_FILE:-environment-lin-cuda.yml} -invokeai_git=${INVOKEAI_GIT:-invoke-ai/InvokeAI} -invokeai_branch=${INVOKEAI_BRANCH:-main} -huggingface_token=${HUGGINGFACE_TOKEN?} +pip_requirements=${PIP_REQUIREMENTS:-requirements-lin-cuda.txt} # print the settings echo "You are using these values:" @@ -19,10 +14,6 @@ echo -e "project_name:\t\t ${project_name}" echo -e "volumename:\t\t ${volumename}" echo -e "arch:\t\t\t ${arch}" echo -e "platform:\t\t ${platform}" -echo -e "invokeai_conda_version:\t ${invokeai_conda_version}" -echo -e "invokeai_conda_prefix:\t ${invokeai_conda_prefix}" -echo -e "invokeai_conda_env_file: ${invokeai_conda_env_file}" -echo -e "invokeai_git:\t\t ${invokeai_git}" echo -e "invokeai_tag:\t\t ${invokeai_tag}\n" _runAlpine() { @@ -35,39 +26,15 @@ _runAlpine() { alpine "$@" } -_copyCheckpoints() { - echo "creating subfolders for models and outputs" - _runAlpine mkdir models - _runAlpine mkdir outputs - echo "downloading v1-5-pruned-emaonly.ckpt" - _runAlpine wget \ - --header="Authorization: Bearer ${huggingface_token}" \ - -O models/v1-5-pruned-emaonly.ckpt \ - https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt - echo "done" -} - _checkVolumeContent() { _runAlpine ls -lhA /data/models } -_getModelMd5s() { - _runAlpine \ - alpine sh -c "md5sum /data/models/*.ckpt" -} - if [[ -n "$(docker volume ls -f name="${volumename}" -q)" ]]; then echo "Volume already exists" - if [[ -z "$(_checkVolumeContent)" ]]; then - echo "looks empty, copying checkpoint" - _copyCheckpoints - fi - echo "Models in ${volumename}:" - _checkVolumeContent else echo -n "createing docker volume " docker volume create "${volumename}" - _copyCheckpoints fi # Build Container @@ -75,10 +42,17 @@ docker build \ --platform="${platform}" \ --tag "${invokeai_tag}" \ --build-arg project_name="${project_name}" \ - --build-arg conda_version="${invokeai_conda_version}" \ - --build-arg conda_prefix="${invokeai_conda_prefix}" \ - --build-arg conda_env_file="${invokeai_conda_env_file}" \ - --build-arg invokeai_git="${invokeai_git}" \ - --build-arg invokeai_branch="${invokeai_branch}" \ + --build-arg pip_requirements="${pip_requirements}" \ --file ./docker-build/Dockerfile \ . + +docker run \ + --rm \ + --platform "$platform" \ + --name "$project_name" \ + --hostname "$project_name" \ + --mount source="$volumename",target=/data \ + --mount type=bind,source="$HOME/.huggingface",target=/root/.huggingface \ + --env HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN} \ + "${invokeai_tag}" \ + scripts/configure_invokeai.py --yes diff --git a/docker-build/entrypoint.sh b/docker-build/entrypoint.sh deleted file mode 100755 index 7c0ca12f888..00000000000 --- a/docker-build/entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -source "${CONDA_PREFIX}/etc/profile.d/conda.sh" -conda activate "${PROJECT_NAME}" - -python scripts/invoke.py \ - ${@:---web --host=0.0.0.0} diff --git a/docker-build/models.yaml b/docker-build/models.yaml deleted file mode 100644 index 06155c6478c..00000000000 --- a/docker-build/models.yaml +++ /dev/null @@ -1,8 +0,0 @@ -stable-diffusion-1.5: - description: The newest Stable Diffusion version 1.5 weight file (4.27 GB) - weights: /data/models/v1-5-pruned-emaonly.ckpt - config: ./configs/stable-diffusion/v1-inference.yaml - width: 512 - height: 512 - vae: ./models/ldm/stable-diffusion-v1/vae-ft-mse-840000-ema-pruned.ckpt - default: true From 39dcf5677acc5da3c5662e9c70356b7cd860b5b9 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sat, 26 Nov 2022 19:38:32 +0100 Subject: [PATCH 02/10] remove not existing file from .dockerignore --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 0c264042c94..60195f608ac 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ * !backend !configs -!docker-build/entrypoint.sh !environments-and-requirements !frontend !installer From fd86d076ac0180249a42aa640f88f0c865378b61 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 04:19:32 +0100 Subject: [PATCH 03/10] remove bloat and unecesary step also use --no-cache-dir for pip install image is now close to 2GB --- docker-build/Dockerfile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docker-build/Dockerfile b/docker-build/Dockerfile index aedee8311c6..6e4cb05f916 100644 --- a/docker-build/Dockerfile +++ b/docker-build/Dockerfile @@ -30,13 +30,10 @@ COPY . . RUN cp \ ./environments-and-requirements/${PIP_REQUIREMENTS} \ ${PIP_REQUIREMENTS} \ - && pip install -r ${PIP_REQUIREMENTS} -RUN pip install --no-cache-dir -e . + && pip install \ + --no-cache-dir \ + -r ${PIP_REQUIREMENTS} -# RUN source ~/.bashrc \ -# && python scripts/preload_models.py \ -# --no-interactive - -# copy and set Entrypoint +# set Entrypoint and default CMD ENTRYPOINT [ "python3" ] CMD [ "scripts/invoke.py", "--web", "--host", "0.0.0.0" ] From 1244647b0e9159e9f5c23ce8d7b25b2b101ff0b3 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 04:20:15 +0100 Subject: [PATCH 04/10] make Dockerfile a variable --- docker-build/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-build/build.sh b/docker-build/build.sh index 803aadb87e0..3f25b183367 100755 --- a/docker-build/build.sh +++ b/docker-build/build.sh @@ -7,9 +7,11 @@ set -e source ./docker-build/env.sh || echo "please run from repository root" || exit 1 pip_requirements=${PIP_REQUIREMENTS:-requirements-lin-cuda.txt} +dockerfile=${INVOKE_DOCKERFILE:-docker-build/Dockerfile} # print the settings echo "You are using these values:" +echo -e "Dockerfile:\t\t ${dockerfile}" echo -e "project_name:\t\t ${project_name}" echo -e "volumename:\t\t ${volumename}" echo -e "arch:\t\t\t ${arch}" @@ -43,7 +45,7 @@ docker build \ --tag "${invokeai_tag}" \ --build-arg project_name="${project_name}" \ --build-arg pip_requirements="${pip_requirements}" \ - --file ./docker-build/Dockerfile \ + --file "${dockerfile}" \ . docker run \ From fdda44aaee55e264d5e3cb605b6d0e84d6ce8911 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 04:33:11 +0100 Subject: [PATCH 05/10] set base image to `ubuntu:22.10` --- docker-build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-build/Dockerfile b/docker-build/Dockerfile index 6e4cb05f916..6436600e116 100644 --- a/docker-build/Dockerfile +++ b/docker-build/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu AS invokeai +FROM ubuntu:22.10 # use bash SHELL [ "/bin/bash", "-c" ] From 11b579f7ef40e947dcea41bf329d1b9493a8b0ea Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 04:49:17 +0100 Subject: [PATCH 06/10] add build-essential --- docker-build/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-build/Dockerfile b/docker-build/Dockerfile index 6436600e116..f722045742c 100644 --- a/docker-build/Dockerfile +++ b/docker-build/Dockerfile @@ -7,6 +7,7 @@ SHELL [ "/bin/bash", "-c" ] RUN apt-get update \ && apt-get install -y \ --no-install-recommends \ + build-essential \ gcc \ git \ libgl1-mesa-glx \ From cc0729590ef988c2047b5134c8fd44a61fe1e634 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 06:32:31 +0100 Subject: [PATCH 07/10] link outputs folder for persistence --- docker-build/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-build/Dockerfile b/docker-build/Dockerfile index f722045742c..567ad46276d 100644 --- a/docker-build/Dockerfile +++ b/docker-build/Dockerfile @@ -27,13 +27,14 @@ ENV INVOKEAI_ROOT=${INVOKEAI_ROOT} WORKDIR /${PROJECT_NAME} COPY . . -# install requirements +# install requirements and link outputs folder RUN cp \ ./environments-and-requirements/${PIP_REQUIREMENTS} \ ${PIP_REQUIREMENTS} \ && pip install \ --no-cache-dir \ - -r ${PIP_REQUIREMENTS} + -r ${PIP_REQUIREMENTS} \ + && ln -sf /data/outputs /${PROJECT_NAME}/outputs # set Entrypoint and default CMD ENTRYPOINT [ "python3" ] From 191ca8940ed6be8a9728108faaf0d54d7809ad56 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 07:35:39 +0100 Subject: [PATCH 08/10] update tag variable --- docker-build/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-build/env.sh b/docker-build/env.sh index 36b718d362b..d612afb7fa3 100644 --- a/docker-build/env.sh +++ b/docker-build/env.sh @@ -4,7 +4,7 @@ project_name=${PROJECT_NAME:-invokeai} volumename=${VOLUMENAME:-${project_name}_data} arch=${ARCH:-x86_64} platform=${PLATFORM:-Linux/${arch}} -invokeai_tag=${INVOKEAI_TAG:-${project_name}-${arch}} +invokeai_tag=${INVOKEAI_TAG:-${project_name}:${arch}} export project_name export volumename From 85b8a5c7cbfb57dbc35e67c65219ed1870669691 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sun, 27 Nov 2022 07:36:04 +0100 Subject: [PATCH 09/10] update docs --- docs/installation/INSTALL_DOCKER.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/installation/INSTALL_DOCKER.md b/docs/installation/INSTALL_DOCKER.md index 9f168ac2a1a..81bf1d819c5 100644 --- a/docs/installation/INSTALL_DOCKER.md +++ b/docs/installation/INSTALL_DOCKER.md @@ -72,14 +72,19 @@ created in the last step. Some Suggestions of variables you may want to change besides the Token: -| Environment-Variable | Default value | Description | -| ------------------------- | ----------------------------- | ---------------------------------------------------------------------------- | -| `HUGGINGFACE_TOKEN` | No default, but **required**! | This is the only **required** variable, without you can't get the checkpoint | -| `ARCH` | x86_64 | if you are using a ARM based CPU | -| `INVOKEAI_TAG` | invokeai-x86_64 | the Container Repository / Tag which will be used | -| `INVOKEAI_CONDA_ENV_FILE` | environment-lin-cuda.yml | since environment.yml wouldn't work with aarch | -| `INVOKEAI_GIT` | invoke-ai/InvokeAI | the repository to use | -| `INVOKEAI_BRANCH` | main | the branch to checkout | +
+ +| Environment-Variable | Default value | Description | +| -------------------- | ----------------------------- | -------------------------------------------------------------------------------------------- | +| `HUGGINGFACE_TOKEN` | No default, but **required**! | This is the only **required** variable, without it you can't download the huggingface models | +| `PROJECT_NAME` | `invokeai` | affects the project folder, tag- and volume name | +| `VOLUMENAME` | `${PROJECT_NAME}_data` | affects the project folder, tag- and volume name | +| `ARCH` | `x86_64` | can be changed to f.e. aarch64 if you are using a ARM based CPU | +| `INVOKEAI_TAG` | `${PROJECT_NAME}:${ARCH}` | the Container Repository / Tag which will be used | +| `PIP_REQUIREMENTS` | `requirements-lin-cuda.txt` | the requirements file to use (from `environments-and-requirements`) | +| `INVOKE_DOCKERFILE` | `docker-build/Dockerfile` | the Dockerfile which should be built, handy for development | + +
#### Build the Image @@ -109,12 +114,12 @@ also do so. !!! example "" ```bash - ./docker-build/run.sh --from_file tests/validate_pr_prompt.txt + ./docker-build/run.sh scripts/invoke.py ``` - The output folder is located on the volume which is also used to store the model. + This would start the CLI instead of the default command that starts the webserver. - Find out more about available CLI-Parameters at [features/CLI.md](../features/CLI.md/#arguments) + Find out more about available CLI-Parameters at [features/CLI.md](../../features/CLI/#arguments) --- From 2739d097efa6d9f76f16dd844310eeaf63a515c9 Mon Sep 17 00:00:00 2001 From: mauwii Date: Mon, 28 Nov 2022 02:05:20 +0100 Subject: [PATCH 10/10] fix not customizeable build args, add reqs output --- docker-build/build.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docker-build/build.sh b/docker-build/build.sh index 3f25b183367..e09ce884735 100755 --- a/docker-build/build.sh +++ b/docker-build/build.sh @@ -12,6 +12,7 @@ dockerfile=${INVOKE_DOCKERFILE:-docker-build/Dockerfile} # print the settings echo "You are using these values:" echo -e "Dockerfile:\t\t ${dockerfile}" +echo -e "requirements:\t\t ${pip_requirements}" echo -e "project_name:\t\t ${project_name}" echo -e "volumename:\t\t ${volumename}" echo -e "arch:\t\t\t ${arch}" @@ -42,19 +43,19 @@ fi # Build Container docker build \ --platform="${platform}" \ - --tag "${invokeai_tag}" \ - --build-arg project_name="${project_name}" \ - --build-arg pip_requirements="${pip_requirements}" \ - --file "${dockerfile}" \ + --tag="${invokeai_tag}" \ + --build-arg="PROJECT_NAME=${project_name}" \ + --build-arg="PIP_REQUIREMENTS=${pip_requirements}" \ + --file="${dockerfile}" \ . docker run \ --rm \ - --platform "$platform" \ - --name "$project_name" \ - --hostname "$project_name" \ - --mount source="$volumename",target=/data \ - --mount type=bind,source="$HOME/.huggingface",target=/root/.huggingface \ - --env HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN} \ + --platform="$platform" \ + --name="$project_name" \ + --hostname="$project_name" \ + --mount="source=$volumename,target=/data" \ + --mount="type=bind,source=$HOME/.huggingface,target=/root/.huggingface" \ + --env="HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN}" \ "${invokeai_tag}" \ scripts/configure_invokeai.py --yes