Skip to content

Commit

Permalink
Prepare for new default CUDA version and add DockerHub images
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Aug 2, 2024
1 parent d22f94f commit fd06c3f
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 423 deletions.
82 changes: 54 additions & 28 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
build:
# Undeclared release tag finds latest from GitHub tags
- {latest: "true", tag: "v1.9.4", python: "3.10", pytorch: "2.3.0"}
- {latest: "false", tag: "v1.10.0", python: "3.10", pytorch: "2.3.1"}
steps:
-
name: Free Space
Expand All @@ -33,27 +33,34 @@ jobs:
-
name: Env Setter
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
REPO=${GITHUB_REPOSITORY,,}
echo "REPO_NAMESPACE=${REPO%%/*}" >> ${GITHUB_ENV}
echo "REPO_NAME=${REPO#*/}" >> ${GITHUB_ENV}
-
name: Checkout
uses: actions/checkout@v3
-
name: Permissions fixes
run: |
reponame="$(basename ${GITHUB_REPOSITORY})"
target="${HOME}/work/${reponame}/${reponame}/build/COPY*"
target="${HOME}/work/${{ env.REPO_NAME }}/${{ env.REPO_NAME }}/build/COPY*"
chmod -R ug+rwX ${target}
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
img_path_ghcr="ghcr.io/${{ env.REPO_NAMESPACE }}/${{ env.REPO_NAME }}"
if [[ -z '${{ matrix.build.tag }}' ]]; then
WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | jq -r '.[0].name')"
else
Expand All @@ -66,9 +73,9 @@ jobs:
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}, ${img_path}:${base_tag}, ${img_path}:latest-cpu, ${img_path}:latest-cpu-jupyter"
TAGS="${img_path_ghcr}:${base_tag}-${WEBUI_TAG}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest-cpu"
else
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}"
TAGS="${img_path_ghcr}:${base_tag}-${WEBUI_TAG}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
Expand All @@ -93,8 +100,7 @@ jobs:
matrix:
build:
# Undeclared release tag finds latest from GitHub tags
- {latest: "true", tag: "v1.9.4", python: "3.10", pytorch: "2.3.0", cuda: "11.8.0-base"}
- {latest: "false", tag: "v1.9.4", python: "3.10", pytorch: "2.3.0", cuda: "12.1.1-base"}
- {latest: "false", tag: "v1.10.0", python: "3.10", pytorch: "2.3.1", cuda: "12.1.1-base"}

steps:
-
Expand All @@ -111,28 +117,35 @@ jobs:
-
name: Env Setter
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
REPO=${GITHUB_REPOSITORY,,}
echo "REPO_NAMESPACE=${REPO%%/*}" >> ${GITHUB_ENV}
echo "REPO_NAME=${REPO#*/}" >> ${GITHUB_ENV}
-
name: Checkout
uses: actions/checkout@v3
-
name: Permissions fixes
run: |
reponame="$(basename ${GITHUB_REPOSITORY})"
target="${HOME}/work/${reponame}/${reponame}/build/COPY*"
target="${HOME}/work/${{ env.REPO_NAME }}/${{ env.REPO_NAME }}/build/COPY*"
chmod -R ug+rwX ${target}
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
img_path_ghcr="ghcr.io/${{ env.REPO_NAMESPACE }}/${{ env.REPO_NAME }}"
img_path_dhub="${{ vars.DOCKERHUB_USER }}/${{ env.REPO_NAME }}-cuda"
if [[ -z '${{ matrix.build.tag }}' ]]; then
WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | jq -r '.[0].name')"
else
Expand All @@ -145,9 +158,12 @@ jobs:
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}, ${img_path}:${base_tag}, ${img_path}:latest, ${img_path}:latest-jupyter, ${img_path}:latest-cuda"
# GHCR.io Tags
TAGS="${img_path_ghcr}:${base_tag}-${WEBUI_TAG}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest, ${img_path_ghcr}:latest-cuda"
# Docker.io Tags
TAGS="${TAGS}, ${img_path_dhub}:${base_tag}-${WEBUI_TAG}, ${img_path_dhub}:${base_tag}, ${img_path_dhub}:latest"
else
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}"
TAGS="${img_path_ghcr}:${base_tag}-${WEBUI_TAG}, ${img_path_dhub}:${base_tag}-${WEBUI_TAG}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
Expand All @@ -170,7 +186,7 @@ jobs:
fail-fast: false
matrix:
build:
- {latest: "true", tag: "v1.9.4", python: "3.10", pytorch: "2.3.0", rocm: "6.0-core"}
- {latest: "false", tag: "v1.10.0", python: "3.10", pytorch: "2.3.1", rocm: "6.0-core"}
steps:
-
name: Free Space
Expand All @@ -186,28 +202,35 @@ jobs:
-
name: Env Setter
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
REPO=${GITHUB_REPOSITORY,,}
echo "REPO_NAMESPACE=${REPO%%/*}" >> ${GITHUB_ENV}
echo "REPO_NAME=${REPO#*/}" >> ${GITHUB_ENV}
-
name: Checkout
uses: actions/checkout@v3
-
name: Permissions fixes
run: |
reponame="$(basename ${GITHUB_REPOSITORY})"
target="${HOME}/work/${reponame}/${reponame}/build/COPY*"
target="${HOME}/work/${{ env.REPO_NAME }}/${{ env.REPO_NAME }}/build/COPY*"
chmod -R ug+rwX ${target}
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
img_path_ghcr="ghcr.io/${{ env.REPO_NAMESPACE }}/${{ env.REPO_NAME }}"
img_path_dhub="${{ vars.DOCKERHUB_USER }}/${{ env.REPO_NAME }}-rocm"
if [[ -z '${{ matrix.build.tag }}' ]]; then
WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | jq -r '.[0].name')"
else
Expand All @@ -216,13 +239,16 @@ jobs:
[ -z "$WEBUI_TAG" ] && { echo "Error: WEBUI_TAG is empty. Exiting script." >&2; exit 1; }
echo "WEBUI_TAG=${WEBUI_TAG}" >> ${GITHUB_ENV}
base_tag="v2-rocm-${{ matrix.build.rocm }}-${{ env.UBUNTU_VERSION }}"
base_tag="v2-cuda-${{ matrix.build.cuda }}-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}, ${img_path}:${base_tag}, ${img_path}:latest-rocm, ${img_path}:latest-rocm-jupyter"
# GHCR.io Tags
TAGS="${img_path_ghcr}:${base_tag}-${WEBUI_TAG}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest-rocm"
# Docker.io Tags
TAGS="${TAGS}, ${img_path_dhub}:${base_tag}-${WEBUI_TAG}, ${img_path_dhub}:${base_tag}, ${img_path_dhub}:latest"
else
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}"
TAGS="${img_path_ghcr}:${base_tag}-${WEBUI_TAG}, ${img_path_dhub}:${base_tag}-${WEBUI_TAG}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
Expand Down
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Run [Automatic1111 WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webu
## Documentation

All AI-Dock containers share a common base which is designed to make running on cloud services such as [vast.ai](https://link.ai-dock.org/vast.ai) and [runpod.io](https://link.ai-dock.org/template) as straightforward and user friendly as possible.
All AI-Dock containers share a common base which is designed to make running on cloud services such as [vast.ai](https://link.ai-dock.org/vast.ai) as straightforward and user friendly as possible.

Common features and options are documented in the [base wiki](https://github.com/ai-dock/base-image/wiki) but any additional features unique to this image will be detailed below.

Expand All @@ -23,7 +23,7 @@ Tags follow these patterns:
##### _CUDA_
- `:v2-cuda-[x.x.x]-[base|runtime]-[ubuntu-version]`

- `:latest-cuda` → `:v2-cuda-11.8.0-base-22.04`
- `:latest-cuda` → `:v2-cuda-12.1.1-base-22.04`

##### _ROCm_
- `:rocm-[x.x.x]-runtime-[ubuntu-version]`
Expand All @@ -47,7 +47,7 @@ Supported Platforms: `NVIDIA CUDA`, `AMD ROCm`, `CPU`
| ------------------------ | ----------- |
| `AUTO_UPDATE` | Update A1111 Web UI on startup (default `false`) |
| `WEBUI_BRANCH` | WebUI branch/commit hash for auto update. (default `master`) |
| `WEBUI_FLAGS` | Startup flags. eg. `--no-half --api` |
| `WEBUI_ARGS` | Startup arguments. eg. `--no-half --api` |
| `WEBUI_PORT_HOST` | Web UI port (default `7860`) |
| `WEBUI_URL` | Override `$DIRECT_ADDRESS:port` with URL for Web UI |

Expand All @@ -70,16 +70,14 @@ The following services will be launched alongside the [default services](https:/

### Stable Diffusion WebUI

The service will launch on port `7860` unless you have specified an override with `WEBUI_PORT`.
The service will launch on port `7860` unless you have specified an override with `WEBUI_PORT_HOST`.

WebUI will be updated to the latest version on container start. You can pin the version to a branch or commit hash by setting the `WEBUI_BRANCH` variable.
You can set startup arguments by using variable `WEBUI_ARGS`.

You can set startup flags by using variable `WEBUI_FLAGS`.

To manage this service you can use `supervisorctl [start|stop|restart] webui`.
To manage this service you can use `supervisorctl [start|stop|restart] webui` or via the Service Portal application.

>[!NOTE]
>All services are password protected by default. See the [security](https://github.com/ai-dock/base-image/wiki#security) and [environment variables](https://github.com/ai-dock/base-image/wiki/2.0-Environment-Variables) documentation for more information.
>All services are password protected by default and HTTPS is available optionally. See the [security](https://github.com/ai-dock/base-image/wiki#security) and [environment variables](https://github.com/ai-dock/base-image/wiki/2.0-Environment-Variables) documentation for more information.

## Pre-Configured Templates
Expand All @@ -92,10 +90,4 @@ To manage this service you can use `supervisorctl [start|stop|restart] webui`.

---

**Runpod.​io**

- [A1111 WebUI:latest](https://link.ai-dock.org/template-runpod-sd-webui)

---

_The author ([@robballantyne](https://github.com/robballantyne)) may be compensated if you sign up to services linked in this document. Testing multiple variants of GPU images in many different environments is both costly and time-consuming; This helps to offset costs_
7 changes: 6 additions & 1 deletion build/COPY_ROOT_1/opt/ai-dock/bin/preflight.d/10-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
# This file will be sourced in init.sh

function preflight_main() {
if [[ -n $WEBUI_FLAGS ]]; then
export WEBUI_ARGS="$WEBUI_FLAGS"
env-store WEBUI_ARGS
fi
preflight_update_webui
printf "%s" "${WEBUI_FLAGS}" > /etc/a1111_webui_flags.conf
printf "%s" "${WEBUI_ARGS}" > /etc/a1111_webui_args.conf
ln -s /etc/a1111_webui_args.conf /etc/a1111_webui_flags.conf
}

function preflight_update_webui() {
Expand Down
1 change: 1 addition & 0 deletions build/COPY_ROOT_1/opt/ai-dock/bin/set-webui-args
4 changes: 4 additions & 0 deletions build/COPY_ROOT_1/opt/ai-dock/bin/set-webui-args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "$@" > /etc/a1111_webui_args.conf
supervisorctl restart webui
1 change: 1 addition & 0 deletions build/COPY_ROOT_1/opt/ai-dock/bin/set-webui-flags
4 changes: 0 additions & 4 deletions build/COPY_ROOT_1/opt/ai-dock/bin/set-webui-flags.sh

This file was deleted.

1 change: 1 addition & 0 deletions build/COPY_ROOT_1/opt/ai-dock/bin/set-webui-flags.sh
10 changes: 5 additions & 5 deletions build/COPY_ROOT_1/opt/ai-dock/bin/supervisor-webui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ function start() {

printf "Starting $SERVICE_NAME...\n"

PLATFORM_FLAGS=
PLATFORM_ARGS=
if [[ $XPU_TARGET = "CPU" ]]; then
PLATFORM_FLAGS="--use-cpu all --skip-torch-cuda-test --no-half"
PLATFORM_ARGS="--use-cpu all --skip-torch-cuda-test --no-half"
fi
# No longer skipping prepare-environment
BASE_FLAGS=""
BASE_ARGS=""

# Delay launch until micromamba is ready
if [[ -f /run/workspace_sync || -f /run/container_config ]]; then
Expand All @@ -70,13 +70,13 @@ function start() {
fuser -k -SIGKILL ${LISTEN_PORT}/tcp > /dev/null 2>&1 &
wait -n

FLAGS_COMBINED="${PLATFORM_FLAGS} ${BASE_FLAGS} $(cat /etc/a1111_webui_flags.conf)"
ARGS_COMBINED="${PLATFORM_ARGS} ${BASE_ARGS} $(cat /etc/a1111_webui_args.conf)"
printf "Starting %s...\n" "${SERVICE_NAME}"

cd /opt/stable-diffusion-webui
source "$WEBUI_VENV/bin/activate"
LD_PRELOAD=libtcmalloc.so python launch.py \
${FLAGS_COMBINED} --port ${LISTEN_PORT}
${ARGS_COMBINED} --port ${LISTEN_PORT}
}

start 2>&1
10 changes: 5 additions & 5 deletions config/provisioning/default-rocm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ function provisioning_start() {
"${WORKSPACE}/storage/stable_diffusion/models/esrgan" \
"${ESRGAN_MODELS[@]}"

PLATFORM_FLAGS=""
PLATFORM_ARGS=""
if [[ $XPU_TARGET = "CPU" ]]; then
PLATFORM_FLAGS="--use-cpu all --skip-torch-cuda-test --no-half"
PLATFORM_ARGS="--use-cpu all --skip-torch-cuda-test --no-half"
fi
PROVISIONING_FLAGS="--skip-python-version-check --no-download-sd-model --do-not-download-clip --port 11404 --exit"
FLAGS_COMBINED="${PLATFORM_FLAGS} $(cat /etc/a1111_webui_flags.conf) ${PROVISIONING_FLAGS}"
PROVISIONING_ARGS="--skip-python-version-check --no-download-sd-model --do-not-download-clip --port 11404 --exit"
ARGS_COMBINED="${PLATFORM_ARGS} $(cat /etc/a1111_webui_flags.conf) ${PROVISIONING_ARGS}"

# Start and exit because webui will probably require a restart
cd /opt/stable-diffusion-webui && \
source $WEBUI_VENV/bin/activate
LD_PRELOAD=libtcmalloc.so python launch.py \
${FLAGS_COMBINED}
${ARGS_COMBINED}
deactivate
provisioning_print_end
}
Expand Down
10 changes: 5 additions & 5 deletions config/provisioning/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ function provisioning_start() {
"${WORKSPACE}/storage/stable_diffusion/models/esrgan" \
"${ESRGAN_MODELS[@]}"

PLATFORM_FLAGS=""
PLATFORM_ARGS=""
if [[ $XPU_TARGET = "CPU" ]]; then
PLATFORM_FLAGS="--use-cpu all --skip-torch-cuda-test --no-half"
PLATFORM_ARGS="--use-cpu all --skip-torch-cuda-test --no-half"
fi
PROVISIONING_FLAGS="--skip-python-version-check --no-download-sd-model --do-not-download-clip --port 11404 --exit"
FLAGS_COMBINED="${PLATFORM_FLAGS} $(cat /etc/a1111_webui_flags.conf) ${PROVISIONING_FLAGS}"
PROVISIONING_ARGS="--skip-python-version-check --no-download-sd-model --do-not-download-clip --port 11404 --exit"
ARGS_COMBINED="${PLATFORM_ARGS} $(cat /etc/a1111_webui_flags.conf) ${PROVISIONING_ARGS}"

# Start and exit because webui will probably require a restart
cd /opt/stable-diffusion-webui && \
source "$WEBUI_VENV/bin/activate"
LD_PRELOAD=libtcmalloc.so python launch.py \
${FLAGS_COMBINED}
${ARGS_COMBINED}
deactivate
provisioning_print_end
}
Expand Down
Loading

0 comments on commit fd06c3f

Please sign in to comment.