diff --git a/README.md b/README.md index 2c0d151e..9ead18dd 100644 --- a/README.md +++ b/README.md @@ -200,8 +200,9 @@ Micromamba environments are particularly useful where several software packages | Environment | Packages | | -------------- | ----------------------------------------- | | `base` | micromamba's base environment | -| `comfyui` | ComfyUI and dependencies | | `system` | `supervisord`, `openssh` `rclone` | +| `fastapi` | `logtail web UI`, `port redirector web UI` | +| `comfyui` | ComfyUI and dependencies | | `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. @@ -274,6 +275,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. @@ -353,10 +373,13 @@ If you are logged into the container you can follow the logs by running `logtail Some ports need to be exposed for the services to run or for certain features of the provided software to function -| Open Port | Service / Description | -| --------------------- | --------------------- | -| `22` | SSH server | -| `8188` | ComfyUI Interface | +| Open Port | Service / Description | +| --------------------- | ------------------------- | +| `22` | SSH server | +| `1111` | Port redirector web UI | +| `1122` | Log viewer web UI | +| `8188` | ComfyUI Interface | +| `8888` | Jupyter | | `53682` | Rclone interactive config | ## Pre-Configured Templates diff --git a/build/COPY_ROOT/etc/supervisor/supervisord/conf.d/comfyui.conf b/build/COPY_ROOT/etc/supervisor/supervisord/conf.d/comfyui.conf index fd773393..71426c51 100644 --- a/build/COPY_ROOT/etc/supervisor/supervisord/conf.d/comfyui.conf +++ b/build/COPY_ROOT/etc/supervisor/supervisord/conf.d/comfyui.conf @@ -4,7 +4,7 @@ process_name=%(program_name)s numprocs=1 directory=/root priority=1500 -autostart=false +autostart=true startsecs=0 startretries=3 autorestart=unexpected diff --git a/build/COPY_ROOT/opt/ai-dock/bin/supervisor-comfyui.sh b/build/COPY_ROOT/opt/ai-dock/bin/supervisor-comfyui.sh index 4b81dd3f..04d5f307 100755 --- a/build/COPY_ROOT/opt/ai-dock/bin/supervisor-comfyui.sh +++ b/build/COPY_ROOT/opt/ai-dock/bin/supervisor-comfyui.sh @@ -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 +} + +SERVICE="ComfyUI" if [[ -z $COMFYUI_PORT ]]; then COMFYUI_PORT=8188 fi -printf "Starting ComfyUI...\n" +PORT=$COMFYUI_PORT +METRICS_PORT=1188 +SERVICE_NAME="ComfyUI" -if [[ $CF_QUICK_TUNNELS = "true" ]]; then - cloudflared tunnel --url localhost:${COMFYUI_PORT} > /var/log/supervisor/quicktunnel-comfyui.log 2>&1 & -fi +printf "{\"port\": \"$PORT\", \"metrics_port\": \"$METRICS_PORT\", \"service_name\": \"$SERVICE_NAME\"}" > /run/http_ports/$PORT PLATFORM_FLAGS="" if [[ $XPU_TARGET = "CPU" ]]; then @@ -18,6 +25,29 @@ if [[ $XPU_TARGET = "CPU" ]]; then fi BASE_FLAGS="--listen 0.0.0.0 --port ${COMFYUI_PORT} --disable-auto-launch" +if [[ -f /run/provisioning_script ]]; then + micromamba run -n fastapi python /opt/ai-dock/fastapi/logviewer/main.py \ + -p $COMFYUI_PORT \ + -r 5 \ + -s ${SERVICE} \ + -u comfyui \ + -t "Preparing ${SERVICE}" & + fastapi_pid=$! + + while [[ -f /run/provisioning_script ]]; do + sleep 1 + done + + printf "\nStarting %s... " ${SERVICE:-service} + kill $fastapi_pid && \ + printf "OK\n" +else + printf "Starting %s...\n" ${SERVICE} +fi + +kill -9 $(lsof -t -i:$COMFYUI_PORT) > /dev/null 2>&1 & +wait -n + cd /opt/ComfyUI micromamba run -n comfyui python main.py \ ${PLATFORM_FLAGS} \ diff --git a/build/COPY_ROOT/usr/local/share/ai-dock/comfyui.ipynb b/build/COPY_ROOT/usr/local/share/ai-dock/comfyui.ipynb index 84de1e85..651ba395 100644 --- a/build/COPY_ROOT/usr/local/share/ai-dock/comfyui.ipynb +++ b/build/COPY_ROOT/usr/local/share/ai-dock/comfyui.ipynb @@ -43,21 +43,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Get secure ComfyUI link\n", + "# Get secure UI links\n", "\n", - "!get-cfqt-comfyui.sh" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "08cbd5a5-0d3f-44d0-a952-cc0d0dd35a2a", - "metadata": {}, - "outputs": [], - "source": [ - "# Get secure Jupyter link\n", - "\n", - "!get-cfqt-jupyter.sh" + "!cfqt-url.sh -p 1111" ] } ], diff --git a/build/Dockerfile b/build/Dockerfile index b926be83..c219059b 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -9,6 +9,7 @@ LABEL org.opencontainers.image.description "ComfyUI Stable Diffusion backend and LABEL maintainer="Rob Ballantyne " +ENV IMAGE_SLUG="comfyui" # 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/ / diff --git a/docker-compose.yaml b/docker-compose.yaml index 68d0f3f0..0dce7594 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -48,6 +48,10 @@ 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 - ${COMFYUI_PORT_HOST:-8188}:${COMFYUI_PORT:-8188} # Jupyter server