From d1d8ee71fc5ce3639d5463927909849b719ba2ab Mon Sep 17 00:00:00 2001 From: "Wilson E. Alvarez" Date: Mon, 30 Oct 2023 16:53:02 -0400 Subject: [PATCH 1/2] Simplify docker compose setup --- docker/README.md | 4 ++-- docker/build.sh | 11 ----------- docker/docker-compose.yml | 37 +++++++++++++++++++++---------------- docker/run.sh | 27 +++++++++++++++++++++------ 4 files changed, 44 insertions(+), 35 deletions(-) delete mode 100755 docker/build.sh diff --git a/docker/README.md b/docker/README.md index 4291ece25f..567ce6832d 100644 --- a/docker/README.md +++ b/docker/README.md @@ -23,7 +23,7 @@ This is done via Docker Desktop preferences 1. Make a copy of `env.sample` and name it `.env` (`cp env.sample .env` (Mac/Linux) or `copy example.env .env` (Windows)). Make changes as necessary. Set `INVOKEAI_ROOT` to an absolute path to: a. the desired location of the InvokeAI runtime directory, or b. an existing, v3.0.0 compatible runtime directory. -1. `docker compose up` +1. Execute `run.sh` The image will be built automatically if needed. @@ -39,7 +39,7 @@ The Docker daemon on the system must be already set up to use the GPU. In case o ## Customize -Check the `.env.sample` file. It contains some environment variables for running in Docker. Copy it, name it `.env`, and fill it in with your own values. Next time you run `docker compose up`, your custom values will be used. +Check the `.env.sample` file. It contains some environment variables for running in Docker. Copy it, name it `.env`, and fill it in with your own values. Next time you run `run.sh`, your custom values will be used. You can also set these values in `docker-compose.yml` directly, but `.env` will help avoid conflicts when code is updated. diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 3b3875c15c..0000000000 --- a/docker/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -e - -build_args="" - -[[ -f ".env" ]] && build_args=$(awk '$1 ~ /\=[^$]/ {print "--build-arg " $0 " "}' .env) - -echo "docker compose build args:" -echo $build_args - -docker compose build $build_args diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f7e92d6bf5..a5f324f746 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,23 +2,8 @@ version: '3.8' -services: - invokeai: +x-invokeai: &invokeai image: "local/invokeai:latest" - # edit below to run on a container runtime other than nvidia-container-runtime. - # not yet tested with rocm/AMD GPUs - # Comment out the "deploy" section to run on CPU only - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] - # For AMD support, comment out the deploy section above and uncomment the devices section below: - #devices: - # - /dev/kfd:/dev/kfd - # - /dev/dri:/dev/dri build: context: .. dockerfile: docker/Dockerfile @@ -50,3 +35,23 @@ services: # - | # invokeai-model-install --yes --default-only --config_file ${INVOKEAI_ROOT}/config_custom.yaml # invokeai-nodes-web --host 0.0.0.0 + +services: + invokeai-cpu: + <<: *invokeai + + invokeai-nvidia: + <<: *invokeai + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] + + invokeai-rocm: + <<: *invokeai + devices: + - /dev/kfd:/dev/kfd + - /dev/dri:/dev/dri diff --git a/docker/run.sh b/docker/run.sh index 4b595b06df..950b653a53 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,11 +1,26 @@ #!/usr/bin/env bash set -e -# This script is provided for backwards compatibility with the old docker setup. -# it doesn't do much aside from wrapping the usual docker compose CLI. +run() { + local scriptdir=$(dirname "${BASH_SOURCE[0]}") + cd "$scriptdir" || exit 1 -SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") -cd "$SCRIPTDIR" || exit 1 + local build_args="" + local service_name="invokeai-cpu" -docker compose up -d -docker compose logs -f + [[ -f ".env" ]] && + build_args=$(awk '$1 ~ /=[^$]/ {print "--build-arg " $0 " "}' .env) && + service_name="invokeai-$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)" + + printf "%s\n" "docker compose build args:" + printf "%s\n" "$build_args" + + docker compose build $build_args + unset build_args + + printf "%s\n" "starting service $service_name" + docker compose up -d $service_name + docker compose logs -f +} + +run From 296060db6389c6417b65e7a9a62cd91096c588ac Mon Sep 17 00:00:00 2001 From: "Wilson E. Alvarez" Date: Thu, 7 Dec 2023 11:17:11 -0500 Subject: [PATCH 2/2] Add cpu and rocm profiles. Let invokeai-nvidia service be the default. --- docker/docker-compose.yml | 10 +++++++--- docker/run.sh | 10 ++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index a5f324f746..b6a965d120 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -37,9 +37,6 @@ x-invokeai: &invokeai # invokeai-nodes-web --host 0.0.0.0 services: - invokeai-cpu: - <<: *invokeai - invokeai-nvidia: <<: *invokeai deploy: @@ -50,8 +47,15 @@ services: count: 1 capabilities: [gpu] + invokeai-cpu: + <<: *invokeai + profiles: + - cpu + invokeai-rocm: <<: *invokeai devices: - /dev/kfd:/dev/kfd - /dev/dri:/dev/dri + profiles: + - rocm diff --git a/docker/run.sh b/docker/run.sh index 950b653a53..4fe1bf4237 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -6,11 +6,13 @@ run() { cd "$scriptdir" || exit 1 local build_args="" - local service_name="invokeai-cpu" + local profile="" [[ -f ".env" ]] && - build_args=$(awk '$1 ~ /=[^$]/ {print "--build-arg " $0 " "}' .env) && - service_name="invokeai-$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)" + build_args=$(awk '$1 ~ /=[^$]/ && $0 !~ /^#/ {print "--build-arg " $0 " "}' .env) && + profile="$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)" + + local service_name="invokeai-$profile" printf "%s\n" "docker compose build args:" printf "%s\n" "$build_args" @@ -19,7 +21,7 @@ run() { unset build_args printf "%s\n" "starting service $service_name" - docker compose up -d $service_name + docker compose --profile "$profile" up -d "$service_name" docker compose logs -f }