Skip to content

Commit

Permalink
Updates:
Browse files Browse the repository at this point in the history
Base - Improved logging
Base - Improved workspace sync
Base - No auto update with AUTO_UPDATE=false
Base - Initial serverless framework
  • Loading branch information
robballantyne committed Oct 25, 2023
1 parent e39b4f2 commit 086a92c
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/comfyui.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/comfyui.error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s"
6 changes: 6 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/amd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ main() {
}

install_comfyui() {
# Mamba export does not include pip packages.
# We need to get torch again - todo find a better way?
micromamba -n comfyui run pip install \
--no-cache-dir \
--index-url https://download.pytorch.org/whl/rocm${ROCM_VERSION} \
torch==${PYTORCH_VERSION} torchvision torchaudio
/opt/ai-dock/bin/update-comfyui.sh
}

Expand Down
28 changes: 0 additions & 28 deletions build/COPY_ROOT/opt/ai-dock/bin/get-cfqt-comfyui.sh

This file was deleted.

11 changes: 10 additions & 1 deletion build/COPY_ROOT/opt/ai-dock/bin/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ function preflight_main() {
preflight_update_comfyui
}

function preflight_serverless() {
printf "Refusing to update ComfyUI in serverless mode\n \
Nothing to do. \n"
}

function preflight_copy_notebook() {
if micromamba env list | grep 'jupyter' > /dev/null 2>&1; then
if [[ ! -f "${WORKSPACE}comfyui.ipynb" ]]; then
Expand All @@ -19,4 +24,8 @@ function preflight_update_comfyui() {
/opt/ai-dock/bin/update-comfyui.sh
}

preflight_main "$@"
if [[ ${SERVERLESS,,} != "true" ]]; then
preflight_main "$@"
else
preflight_serverless "$@"
fi
116 changes: 63 additions & 53 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-comfyui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,77 @@

trap cleanup EXIT

LISTEN_PORT=1818
METRICS_PORT=1918
LISTEN_PORT=18188
METRICS_PORT=28188
PROXY_SECURE=true

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

if [[ -z $COMFYUI_PORT ]]; then
COMFYUI_PORT=8188
fi

PROXY_PORT=$COMFYUI_PORT
SERVICE_NAME="ComfyUI"

file_content=$(
jq --null-input \
--arg listen_port "${LISTEN_PORT}" \
--arg metrics_port "${METRICS_PORT}" \
--arg proxy_port "${PROXY_PORT}" \
--arg proxy_secure "${PROXY_SECURE,,}" \
--arg service_name "${SERVICE_NAME}" \
'$ARGS.named'
)

printf "%s" $file_content > /run/http_ports/$PROXY_PORT

PLATFORM_FLAGS=""
if [[ $XPU_TARGET = "CPU" ]]; then
PLATFORM_FLAGS="--cpu"
fi

BASE_FLAGS="--listen 127.0.0.1 --port ${LISTEN_PORT} --disable-auto-launch"

# Delay launch until micromamba is ready
if [[ -f /run/workspace_moving || -f /run/provisioning_script ]]; then
/usr/bin/python3 /opt/ai-dock/fastapi/logviewer/main.py \
-p $LISTEN_PORT \
-r 5 \
-s "${SERVICE_NAME}" \
-t "Preparing ${SERVICE_NAME}" &
fastapi_pid=$!
function start() {
if [[ -z $COMFYUI_PORT ]]; then
COMFYUI_PORT=8188
fi

while [[ -f /run/workspace_moving || -f /run/provisioning_script ]]; do
sleep 1
done
PROXY_PORT=$COMFYUI_PORT
SERVICE_NAME="ComfyUI"

file_content="$(
jq --null-input \
--arg listen_port "${LISTEN_PORT}" \
--arg metrics_port "${METRICS_PORT}" \
--arg proxy_port "${PROXY_PORT}" \
--arg proxy_secure "${PROXY_SECURE,,}" \
--arg service_name "${SERVICE_NAME}" \
'$ARGS.named'
)"

printf "%s" "$file_content" > /run/http_ports/$PROXY_PORT

PLATFORM_FLAGS=""
if [[ $XPU_TARGET = "CPU" ]]; then
PLATFORM_FLAGS="--cpu"
fi

BASE_FLAGS="--listen 127.0.0.1 --port ${LISTEN_PORT} --disable-auto-launch"

# Delay launch until micromamba is ready
if [[ -f /run/workspace_sync || -f /run/container_config ]]; then
if [[ ${SERVERLESS,,} != "true" ]]; then
printf "Waiting for workspace sync...\n"
kill -9 $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
/usr/bin/python3 /opt/ai-dock/fastapi/logviewer/main.py \
-p $LISTEN_PORT \
-r 5 \
-s "${SERVICE_NAME}" \
-t "Preparing ${SERVICE_NAME}" &
fastapi_pid=$!

while [[ -f /run/workspace_sync || -f /run/container_config ]]; do
sleep 1
done

kill $fastapi_pid &
wait -n
else
printf "Waiting for workspace symlinks and pre-flight checks...\n"
while [[ -f /run/workspace_sync || -f /run/container_config ]]; do
sleep 0.1s
done
fi
fi

printf "\nStarting %s... " ${SERVICE_NAME:-service}
kill $fastapi_pid &
wait -n
printf "OK\n"
else
printf "Starting %s...\n" ${SERVICE_NAME}
fi

kill -9 $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
cd /opt/ComfyUI
kill -9 $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
micromamba run -n comfyui python main.py \
${PLATFORM_FLAGS} \
${BASE_FLAGS} \
${COMFYUI_FLAGS}
}

cd /opt/ComfyUI
micromamba run -n comfyui python main.py \
${PLATFORM_FLAGS} \
${BASE_FLAGS} \
${COMFYUI_FLAGS}
start 2>&1
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COPY ./COPY_ROOT/ /
ARG IMAGE_BASE
RUN /opt/ai-dock/bin/build/layer0/init.sh

ENV OPT_SYNC=ComfyUI:$OPT_SYNC
ENV MAMBA_DEFAULT_ENV=comfyui
ENV MAMBA_DEFAULT_RUN="micromamba run -n $MAMBA_DEFAULT_ENV"

Expand Down
17 changes: 9 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ services:
- /etc/group:/etc/group:ro
- ./config/rclone:/etc/rclone
# Workspace
- ./workspace:${WORKSPACE:-/workspace/}:rshared
#- ./workspace:${WORKSPACE:-/workspace/}:rshared
# Will echo to root-owned authorized_keys file;
# Avoids changing local file owner
- ./config/authorized_keys:/root/.ssh/authorized_keys_mount
- ./config/provisioning/default.sh:/opt/ai-dock/bin/provisioning.sh
- ./config/provisioning/animated.sh:/opt/ai-dock/bin/provisioning.sh

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
- ${REDIRECTOR_PORT_HOST:-1111}:1111
# Websocket log viewer
- ${LOG_VIEWER_PORT_HOST}:1122
- ${LOG_VIEWER_PORT_HOST:-1122}:1122
# ComfyUI web interface
- ${COMFYUI_PORT_HOST:-8188}:${COMFYUI_PORT:-8188}
# Jupyter server
Expand All @@ -68,10 +68,11 @@ services:
# Allows running true SSH alongside provider proxy SSH
- SSH_PORT=${SSH_PORT:-22}
- WORKSPACE=${WORKSPACE:-/workspace}
- WORKSPACE_SYNC=${WORKSPACE_SYNC}
- WORKSPACE_SYNC=${WORKSPACE_SYNC:-true}
- CF_TUNNEL_TOKEN=${CF_TUNNEL_TOKEN:-}
- CF_QUICK_TUNNELS=${CF_QUICK_TUNNELS:-true}
- WEB_ENABLE_AUTH=${WEB_ENABLE_AUTH}
- WEB_USER=${WEB_USER}
- WEB_PASSWORD=${WEB_PASSWORD}
- WEB_ENABLE_AUTH=${WEB_ENABLE_AUTH:-true}
- WEB_USER=${WEB_USER:-user}
- WEB_PASSWORD=${WEB_PASSWORD:-password}
- SERVERLESS=${SERVERLESS:-false}
#- PROVISIONING_SCRIPT=${PROVISIONING_SCRIPT:-}
Empty file removed workspace/.gitkeep
Empty file.

0 comments on commit 086a92c

Please sign in to comment.