Skip to content

Commit

Permalink
Update base for port and log UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Sep 13, 2023
1 parent b54bcc1 commit dc43432
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ IMAGE_TAG="pytorch-2.0.1-py3.10-cuda-11.8.0-base-22.04"

### Runtime Vars ###
WEBUI_BRANCH=master
WEBUI_FLAGS=
#WEBUI_FLAGS="--use-cpu all --skip-torch-cuda-test --no-half"
WEBUI_PORT=7860
WEBUI_PORT_HOST=7860
PROVISIONING_SCRIPT=https://raw.githubusercontent.com/ai-dock/stable-diffusion-webui/main/config/provisioning/get-models-sd-official.sh
PROVISIONING_SCRIPT=https://raw.githubusercontent.com/ai-dock/stable-diffusion-webui/main/config/provisioning/default.sh
JUPYTER_TOKEN=password
JUPYTER_PORT=8888
JUPYTER_PORT_HOST=8888
Expand All @@ -18,4 +18,6 @@ CF_TUNNEL_TOKEN=
CF_QUICK_TUNNELS=true
SSH_PORT=22
SSH_PORT_HOST=2222
REDIRECTOR_PORT_HOST=1111
LOG_VIEWER_PORT_HOST=1122
RCLONE_PORT_HOST=53682
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Micromamba environments are particularly useful where several software packages
| `base` | micromamba's base environment |
| `webui` | AUTOMATIC1111 WebUI and dependencies |
| `system` | `supervisord`, `openssh` `rclone` |
| `fastapi` | `logtail web UI`, `port redirector web UI` |
| `python_[ver]` | `python` |

If you are extending this image or running an interactive session where additional software is required, you should almost certainly create a new environment first. See below for guidance.
Expand Down Expand Up @@ -306,6 +307,25 @@ Jupyter's official documentation is available at https://jupyter.org/
>[!NOTE]
>_If you have enabled `CF_QUICK_TUNNELS` a secure `https://[random-auto-generated-sub-domain].trycloudflare.com` link will be created. You can find it at `/var/log/supervisor/quicktunnel-jupyter.log`_
### Port Redirector

This is a simple list of links to the web services available inside the container.

The service will bind to port `1111`.

For each service, you will find a direct link and, if you have set `CF_QUICK_TUNNELS=true`, a link to the service via a fast and secure Cloudflare tunnel.

>[!NOTE]
>*This service will not show links to any pre-configured Cloudflare tunnels as the domains are static and already known to the user.*
### Log Viewer

The web based log viewer will start on port `1122`.

It's a very lightweight websocket based stream of the latest updates in `/var/log/logtail.log`.

This service will also be accessible on any other exposed ports until the program designated to that port is ready to use.

### Cloudflared

The Cloudflare tunnel daemon will start if you have provided a token with the `CF_TUNNEL_TOKEN` environment variable.
Expand Down Expand Up @@ -388,6 +408,8 @@ Some ports need to be exposed for the services to run or for certain features of
| Open Port | Service / Description |
| --------------------- | --------------------- |
| `22` | SSH server |
| `1111` | Port redirector web UI |
| `1122` | Log viewer web UI |
| `7860` | Stable Diffusion WebUI |
| `53682` | Rclone interactive config |

Expand Down
2 changes: 2 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ create_env() {
exported_env=/tmp/${MAMBA_DEFAULT_ENV}.yaml
micromamba env export -n ${MAMBA_DEFAULT_ENV} > "${exported_env}"
$MAMBA_CREATE -n webui --file "${exported_env}"
$MAMBA_INSTALL -n webui -c conda-forge -y \
gperftools
}

install_jupyter_kernels() {
Expand Down
31 changes: 25 additions & 6 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-webui.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
#!/bin/bash

trap 'kill $(jobs -p)' EXIT
trap cleanup EXIT

function cleanup() {
kill $(jobs -p) > /dev/null 2>&1
rm /run/http_ports/$PORT > /dev/null 2>&1
}

if [[ -z $WEBUI_PORT ]]; then
WEBUI_PORT=7860
fi

printf "Starting webui...\n"
PORT=$WEBUI_PORT
METRICS_PORT=1860
SERVICE_NAME="A1111 SD Web UI"

if [[ $CF_QUICK_TUNNELS = "true" ]]; then
cloudflared tunnel --url localhost:${WEBUI_PORT} > /var/log/supervisor/quicktunnel-webui.log 2>&1 &
fi
printf "{\"port\": \"$PORT\", \"metrics_port\": \"$METRICS_PORT\", \"service_name\": \"$SERVICE_NAME\"}" > /run/http_ports/$PORT

printf "Starting $SERVICE_NAME...\n"

PLATFORM_FLAGS=""
if [[ $XPU_TARGET = "CPU" ]]; then
Expand All @@ -19,10 +26,22 @@ fi
# We can safely --skip-prepare-environment because it's already been done
BASE_FLAGS="--listen --port ${WEBUI_PORT} --skip-prepare-environment"

if [[ -f /run/provisioning_script ]]; then
micromamba run -n fastapi python /opt/ai-dock/fastapi/logviewer/main.py \
-p $WEBUI_PORT \
-r 5 \
-s "${SERVICE_NAME}" \
-t "Preparing ${SERVICE_NAME}" &
fastapi_pid=$!
fi

while [[ -f /run/provisioning_script ]]; do
sleep 1
done

cd /opt/stable-diffusion-webui

micromamba run -n webui python launch.py \
${PLATFORM_FLAGS} \
${BASE_FLAGS} \
${WEBUI_FLAGS}

1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LABEL org.opencontainers.image.description "Automatic1111 Stable Diffusion Web U

LABEL maintainer="Rob Ballantyne <rob@dynamedia.uk>"

ENV IMAGE_SLUG="stable-diffusion-webui"
# Copy early so we can use scripts in the build - Changes to these files will invalidate the cache and cause a rebuild.
COPY ./COPY_ROOT/ /

Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ services:
ports:
# SSH available on host machine port 2222 to avoid conflict. Change to suit
- ${SSH_PORT_HOST:-2222}:${SSH_PORT:-22}
# redirect to Cloudflare quick tunnel
- ${REDIRECTOR_PORT_HOST}:1111
# Websocket log viewer
- ${LOG_VIEWER_PORT_HOST}:1122
# ComfyUI web interface
- ${WEBUI_PORT_HOST:-8188}:${WEBUI_PORT:-8188}
- ${WEBUI_PORT_HOST:-7860}:${WEBUI_PORT:-7860}
# Jupyter server
- ${JUPYTER_PORT_HOST:-8888}:${JUPYTER_PORT:-8888}
# Rclone webserver for interactive configuration
Expand Down

0 comments on commit dc43432

Please sign in to comment.