Skip to content

Commit

Permalink
Update base
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Nov 5, 2023
1 parent 612698e commit 8a05497
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 66 deletions.
6 changes: 2 additions & 4 deletions build/COPY_ROOT/etc/supervisor/supervisord/conf.d/webui.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ numprocs=1
directory=/root
priority=1500
autostart=true
startsecs=0
startsecs=5
startretries=3
autorestart=true
stopsignal=TERM
Expand All @@ -15,7 +15,5 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/webui.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/webui.error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=1
redirect_stderr=true
environment=PROC_NAME="%(program_name)s"
3 changes: 2 additions & 1 deletion build/COPY_ROOT/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ create_env() {
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
gperftools \
httpx=0.24.1
}

install_jupyter_kernels() {
Expand Down
4 changes: 4 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ else
exit 1
fi

# webui 'prepare-environment'
cd /opt/stable-diffusion-webui
micromamba run -n webui python launch.py --skip-torch-cuda-test --skip-python-version-check --no-download-sd-model --do-not-download-clip --exit

/opt/ai-dock/bin/build/layer0/clean.sh
7 changes: 6 additions & 1 deletion build/COPY_ROOT/opt/ai-dock/bin/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
function preflight_main() {
preflight_copy_notebook
preflight_update_webui
printf "%s" "${WEBUI_FLAGS}" > /etc/a1111_webui_flags.conf
}

function preflight_copy_notebook() {
Expand All @@ -16,7 +17,11 @@ function preflight_copy_notebook() {
}

function preflight_update_webui() {
/opt/ai-dock/bin/update-webui.sh
if [[ ${AUTO_UPDATE,,} != "false" ]]; then
/opt/ai-dock/bin/update-webui.sh
else
printf "Skipping auto update (AUTO_UPDATE=false)"
fi
}

preflight_main "$@"
4 changes: 4 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/set-webui-flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "$@" > /etc/a1111_webui_flags.conf
supervisorctl restart webui
112 changes: 56 additions & 56 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-webui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,63 @@ function cleanup() {
rm /run/http_ports/$PORT > /dev/null 2>&1
}

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

PROXY_PORT=$WEBUI_PORT
SERVICE_NAME="A1111 SD Web UI"

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

printf "Starting $SERVICE_NAME...\n"

PLATFORM_FLAGS=""
if [[ $XPU_TARGET = "CPU" ]]; then
PLATFORM_FLAGS="--use-cpu all --skip-torch-cuda-test --no-half"
fi
# We can safely --skip-prepare-environment because it's already been done
BASE_FLAGS="--port ${LISTEN_PORT} --skip-prepare-environment"

# Delay launch until micromamba is ready
if [[ -f /run/workspace_moving || -f /run/provisioning_script ]]; then
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=$!
function start() {
if [[ -z $WEBUI_PORT ]]; then
WEBUI_PORT=7860
fi

PROXY_PORT=$WEBUI_PORT
SERVICE_NAME="A1111 SD Web UI"

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'
)"

while [[ -f /run/workspace_moving || -f /run/provisioning_script ]]; do
sleep 1
done
printf "%s" "$file_content" > /run/http_ports/$PROXY_PORT

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

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

# Delay launch until micromamba is ready
if [[ -f /run/workspace_sync || -f /run/container_config ]]; then
kill $(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 $fastapi_pid 2>/dev/null
fi

kill $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
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/stable-diffusion-webui

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

cd /opt/stable-diffusion-webui &&
exec micromamba run -n webui python launch.py \
${FLAGS_COMBINED} --port ${LISTEN_PORT}
}

micromamba run -n webui python launch.py \
${PLATFORM_FLAGS} \
${BASE_FLAGS} \
${WEBUI_FLAGS}
start 2>&1
3 changes: 1 addition & 2 deletions build/COPY_ROOT/opt/ai-dock/bin/update-webui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ cd /opt/stable-diffusion-webui
git checkout ${branch}
git pull

micromamba run -n webui ${PIP_INSTALL} -r requirements_versions.txt
micromamba run -n webui python launch.py --skip-torch-cuda-test --skip-python-version-check --no-download-sd-model --do-not-download-clip --exit
micromamba run -n webui ${PIP_INSTALL} -r requirements_versions.txt
6 changes: 5 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ COPY ./COPY_ROOT/ /
# Don't put anything heavy in here - We can use multi-stage building above if necessary.

ARG IMAGE_BASE
RUN /opt/ai-dock/bin/build/layer0/init.sh
RUN /opt/ai-dock/bin/build/layer0/init.sh | tee /var/log/build.log

ENV OPT_SYNC=stable-diffusion-webui:$OPT_SYNC
ENV MAMBA_DEFAULT_ENV=webui
ENV MAMBA_DEFAULT_RUN="micromamba run -n ${MAMBA_DEFAULT_ENV}"

# Set false when building specific versions
ARG AUTO_UPDATE=true
ENV AUTO_UPDATE=$AUTO_UPDATE
# Keep init.sh as-is and place additional logic in /opt/ai-dock/bin/preflight.sh
CMD ["init.sh"]
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ services:
# 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/default.sh:/opt/ai-dock/bin/provisioning.sh

ports:
# SSH available on host machine port 2222 to avoid conflict. Change to suit
Expand All @@ -61,6 +61,7 @@ services:

environment:
# Don't enclose values in quotes
- AUTO_UPDATE=${AUTO_UPDATE:-true}
- WEBUI_BRANCH=${WEBUI_BRANCH:-master}
- WEBUI_FLAGS=${WEBUI_FLAGS:-}
- WEBUI_PORT=${WEBUI_PORT:-8188}
Expand Down

0 comments on commit 8a05497

Please sign in to comment.