Skip to content

Commit

Permalink
Fix and document AUTO_UPDATE var
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Aug 15, 2024
1 parent a5cd2c2 commit 5d83fe7
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 70 deletions.
64 changes: 29 additions & 35 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ jobs:
fail-fast: false
matrix:
build:
# Undeclared SHA tags with latest commit from master branch
# Only building periodic sha tagged images
- {latest: "true", sha: "de17a97", python: "3.10", pytorch: "2.3.1"}
- {latest: "false", comfyui: "v0.0.8", python: "3.10", pytorch: "2.4.0"}
steps:
-
name: Free Space
Expand Down Expand Up @@ -62,21 +60,21 @@ jobs:
name: Set tags
run: |
img_path_ghcr="ghcr.io/${{ env.REPO_NAMESPACE }}/${{ env.REPO_NAME }}"
if [[ -z '${{ matrix.build.sha }}' ]]; then
COMFYUI_SHA="$(curl -fsSL "https://api.github.com/repos/comfyanonymous/ComfyUI/commits/master" | jq -r '.sha[0:7]')"
if [[ -z '${{ matrix.build.comfyui }}' ]]; then
COMFYUI_BUILD_REF="$(curl -s https://api.github.com/repos/comfyanonymous/ComfyUI/tags | jq -r '.[0].name')"
else
COMFYUI_SHA="${{ matrix.build.sha }}"
COMFYUI_BUILD_REF="${{ matrix.build.comfyui }}"
fi
[ -z "$COMFYUI_SHA" ] && { echo "Error: COMFYUI_SHA is empty. Exiting script." >&2; exit 1; }
echo "COMFYUI_SHA=${COMFYUI_SHA}" >> ${GITHUB_ENV}
[ -z "$COMFYUI_BUILD_REF" ] && { echo "Error: COMFYUI_BUILD_REF is empty. Exiting script." >&2; exit 1; }
echo "COMFYUI_BUILD_REF=${COMFYUI_BUILD_REF}" >> ${GITHUB_ENV}
base_tag="v2-cpu-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_SHA}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest-cpu"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_BUILD_REF}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest-cpu"
else
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_SHA}"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_BUILD_REF}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
Expand All @@ -88,7 +86,7 @@ jobs:
IMAGE_BASE=ghcr.io/ai-dock/python:${{ matrix.build.python }}-v2-cpu-${{ env.UBUNTU_VERSION }}
PYTHON_VERSION=${{ matrix.build.python }}
PYTORCH_VERSION=${{ matrix.build.pytorch }}
COMFYUI_SHA=${{ env.COMFYUI_SHA }}
COMFYUI_BUILD_REF=${{ env.COMFYUI_BUILD_REF }}
push: true
# Avoids unknown/unknown architecture and extra metadata
provenance: false
Expand All @@ -100,9 +98,7 @@ jobs:
fail-fast: false
matrix:
build:
# Undeclared SHA tags with latest commit from master branch
# Only building periodic sha tagged images
- {latest: "true", sha: "de17a97", python: "3.10", pytorch: "2.3.1", cuda: "12.1.1-base"}
- {latest: "false", comfyui: "v0.0.8", python: "3.10", pytorch: "2.3.1", cuda: "12.1.1-base"}
steps:
-
name: Free Space
Expand Down Expand Up @@ -147,24 +143,24 @@ jobs:
run: |
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.sha }}' ]]; then
COMFYUI_SHA="$(curl -fsSL "https://api.github.com/repos/comfyanonymous/ComfyUI/commits/master" | jq -r '.sha[0:7]')"
if [[ -z '${{ matrix.build.comfyui }}' ]]; then
COMFYUI_BUILD_REF="$(curl -s https://api.github.com/repos/comfyanonymous/ComfyUI/tags | jq -r '.[0].name')"
else
COMFYUI_SHA="${{ matrix.build.sha }}"
COMFYUI_BUILD_REF="${{ matrix.build.comfyui }}"
fi
[ -z "$COMFYUI_SHA" ] && { echo "Error: COMFYUI_SHA is empty. Exiting script." >&2; exit 1; }
echo "COMFYUI_SHA=${COMFYUI_SHA}" >> ${GITHUB_ENV}
[ -z "$COMFYUI_BUILD_REF" ] && { echo "Error: COMFYUI_BUILD_REF is empty. Exiting script." >&2; exit 1; }
echo "COMFYUI_BUILD_REF=${COMFYUI_BUILD_REF}" >> ${GITHUB_ENV}
base_tag="v2-cuda-${{ matrix.build.cuda }}-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
# GHCR.io Tags
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_SHA}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest, ${img_path_ghcr}:latest-cuda"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_BUILD_REF}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest, ${img_path_ghcr}:latest-cuda"
# Docker.io Tags
TAGS="${TAGS}, ${img_path_dhub}:${COMFYUI_SHA}, ${img_path_dhub}:latest"
TAGS="${TAGS}, ${img_path_dhub}:${COMFYUI_BUILD_REF}, ${img_path_dhub}:latest"
else
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_SHA}, ${img_path_dhub}:${COMFYUI_SHA}"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_BUILD_REF}, ${img_path_dhub}:${COMFYUI_BUILD_REF}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
Expand All @@ -176,7 +172,7 @@ jobs:
IMAGE_BASE=ghcr.io/ai-dock/python:${{ matrix.build.python }}-v2-cuda-${{ matrix.build.cuda }}-${{ env.UBUNTU_VERSION }}
PYTHON_VERSION=${{ matrix.build.python }}
PYTORCH_VERSION=${{ matrix.build.pytorch }}
COMFYUI_SHA=${{ env.COMFYUI_SHA }}
COMFYUI_BUILD_REF=${{ env.COMFYUI_BUILD_REF }}
push: true
provenance: false
tags: ${{ env.TAGS }}
Expand All @@ -187,9 +183,7 @@ jobs:
fail-fast: false
matrix:
build:
# Undeclared SHA tags with latest commit from master branch
# Only building periodic sha tagged images
- {latest: "true", sha: "de17a97", python: "3.10", pytorch: "2.3.1", rocm: "6.0-runtime"}
- {latest: "false", comfyui: "v0.0.8", python: "3.10", pytorch: "2.3.1", rocm: "6.0-runtime"}
steps:
-
name: Free Space
Expand Down Expand Up @@ -234,24 +228,24 @@ jobs:
run: |
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.sha }}' ]]; then
COMFYUI_SHA="$(curl -fsSL "https://api.github.com/repos/comfyanonymous/ComfyUI/commits/master" | jq -r '.sha[0:7]')"
if [[ -z '${{ matrix.build.comfyui }}' ]]; then
COMFYUI_BUILD_REF="$(curl -s https://api.github.com/repos/comfyanonymous/ComfyUI/tags | jq -r '.[0].name')"
else
COMFYUI_SHA="${{ matrix.build.sha }}"
COMFYUI_BUILD_REF="${{ matrix.build.comfyui }}"
fi
[ -z "$COMFYUI_SHA" ] && { echo "Error: COMFYUI_SHA is empty. Exiting script." >&2; exit 1; }
echo "COMFYUI_SHA=${COMFYUI_SHA}" >> ${GITHUB_ENV}
[ -z "$COMFYUI_BUILD_REF" ] && { echo "Error: COMFYUI_BUILD_REF is empty. Exiting script." >&2; exit 1; }
echo "COMFYUI_BUILD_REF=${COMFYUI_BUILD_REF}" >> ${GITHUB_ENV}
base_tag="v2-rocm-${{ matrix.build.rocm }}-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
# GHCR.io Tags
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_SHA}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest-rocm"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_BUILD_REF}, ${img_path_ghcr}:${base_tag}, ${img_path_ghcr}:latest-rocm"
# Docker.io Tags
TAGS="${TAGS}, ${img_path_dhub}:${COMFYUI_SHA}, ${img_path_dhub}:latest"
TAGS="${TAGS}, ${img_path_dhub}:${COMFYUI_BUILD_REF}, ${img_path_dhub}:latest"
else
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_SHA}, ${img_path_dhub}:${COMFYUI_SHA}"
TAGS="${img_path_ghcr}:${base_tag}-${COMFYUI_BUILD_REF}, ${img_path_dhub}:${COMFYUI_BUILD_REF}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
Expand All @@ -263,7 +257,7 @@ jobs:
IMAGE_BASE=ghcr.io/ai-dock/python:${{ matrix.build.python }}-v2-rocm-${{ matrix.build.rocm }}-${{ env.UBUNTU_VERSION }}
PYTHON_VERSION=${{ matrix.build.python }}
PYTORCH_VERSION=${{ matrix.build.pytorch }}
COMFYUI_SHA=${{ env.COMFYUI_SHA }}
COMFYUI_BUILD_REF=${{ env.COMFYUI_BUILD_REF }}
push: true
provenance: false
tags: ${{ env.TAGS }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Supported Platforms: `NVIDIA CUDA`, `AMD ROCm`, `CPU`
| ------------------------ | ----------- |
| `AUTO_UPDATE` | Update ComfyUI on startup (default `false`) |
| `CIVITAI_TOKEN` | Authenticate download requests from Civitai - Required for gated models |
| `COMFYUI_BRANCH` | ComfyUI branch/commit hash for auto update (default `master`) |
| `COMFYUI_ARGS` | Startup flags. eg. `--gpu-only --highvram` |
| `COMFYUI_ARGS` | Startup arguments. eg. `--gpu-only --highvram` |
| `COMFYUI_PORT_HOST` | ComfyUI interface port (default `8188`) |
| `COMFYUI_REF` | Git reference for auto update. Accepts branch, tag or commit hash. Default: latest release |
| `COMFYUI_URL` | Override `$DIRECT_ADDRESS:port` with URL for ComfyUI |
| `HF_TOKEN` | Authenticate download requests from HuggingFace - Required for gated models (SD3, FLUX, etc.) |

Expand Down
12 changes: 6 additions & 6 deletions build/COPY_ROOT_1/opt/ai-dock/bin/build/layer1/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ build_common_install_api() {
}

build_common_install_comfyui() {
# Set git SHA to latest if not provided
if [[ -z $COMFYUI_SHA ]]; then
export COMFYUI_SHA="$(curl -fsSL "https://api.github.com/repos/comfyanonymous/ComfyUI/commits/master" \
| jq -r '.sha[0:7]')"
env-store COMFYUI_SHA
# Set to latest release if not provided
if [[ -z $COMFYUI_BUILD_REF ]]; then
export COMFYUI_BUILD_REF="$(curl -s https://api.github.com/repos/comfyanonymous/ComfyUI/tags | \
jq -r '.[0].name')"
env-store COMFYUI_BUILD_REF
fi

cd /opt
git clone https://github.com/comfyanonymous/ComfyUI
cd /opt/ComfyUI
git checkout "$COMFYUI_SHA"
git checkout "$COMFYUI_BUILD_REF"

$COMFYUI_VENV_PIP install --no-cache-dir \
-r requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions 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 @@ -4,12 +4,12 @@

function preflight_main() {
preflight_update_comfyui
printf "%s" "${COMFYUI_FLAGS}" > /etc/comfyui_flags.conf
printf "%s" "${COMFYUI_ARGS}" > /etc/comfyui_args.conf
}

function preflight_serverless() {
printf "Skipping ComfyUI updates in serverless mode\n"
printf "%s" "${COMFYUI_FLAGS}" > /etc/comfyui_flags.conf
printf "%s" "${COMFYUI_ARGS}" > /etc/comfyui_args.conf
}

function preflight_update_comfyui() {
Expand Down
10 changes: 5 additions & 5 deletions build/COPY_ROOT_1/opt/ai-dock/bin/supervisor-comfyui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ function start() {

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

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

BASE_FLAGS="--disable-auto-launch"
BASE_ARGS="--disable-auto-launch"

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

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

cd /opt/ComfyUI
source "$COMFYUI_VENV/bin/activate"
LD_PRELOAD=libtcmalloc.so \
python main.py \
${FLAGS_COMBINED} --port ${LISTEN_PORT}
${ARGS_COMBINED} --port ${LISTEN_PORT}
}

start 2>&1
27 changes: 17 additions & 10 deletions build/COPY_ROOT_1/opt/ai-dock/bin/update-comfyui.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#!/bin/bash
umask 002

branch=master
source /opt/ai-dock/bin/venv-set.sh comfyui

if [[ -n "${COMFYUI_BRANCH}" ]]; then
branch="${COMFYUI_BRANCH}"
if [[ -n "${COMFYUI_REF}" ]]; then
ref="${COMFYUI_REF}"
else
# The latest tagged release
ref="$(curl -s https://api.github.com/repos/comfyanonymous/ComfyUI/tags | \
jq -r '.[0].name')"
fi

# -b flag has priority
while getopts b: flag
# -r argument has priority
while getopts r: flag
do
case "${flag}" in
b) branch="$OPTARG";;
r) ref="$OPTARG";;
esac
done

printf "Updating ComfyUI (${branch})...\n"
[[ -n $ref ]] || { echo "Failed to get update target"; exit 1; }

printf "Updating ComfyUI (${ref})...\n"

cd /opt/ComfyUI
git checkout ${branch}
git fetch --tags
git checkout ${ref}
git pull

"$COMFYUI_VENV_PIP" install --no-cache-dir \
-r requirements.txt
"$COMFYUI_VENV_PIP" install --no-cache-dir -r requirements.txt
8 changes: 4 additions & 4 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# For build automation - Allows building from any ai-dock base image
# Use a *cuda*base* image as default because pytorch brings the libs
ARG IMAGE_BASE="ghcr.io/ai-dock/python:3.10-cuda-12.1.1-base-22.04"
ARG IMAGE_BASE="ghcr.io/ai-dock/python:3.10-v2-cuda-12.1.1-base-22.04"
FROM ${IMAGE_BASE}

LABEL org.opencontainers.image.source https://github.com/ai-dock/comfyui
Expand All @@ -21,16 +21,16 @@ ENV OPT_SYNC=ComfyUI
# Prepare environment
ARG PYTHON_VERSION="3.10"
ENV PYTHON_VERSION=${PYTHON_VERSION}
ARG PYTORCH_VERSION="2.3.1"
ARG PYTORCH_VERSION="2.4.0"
ENV PYTORCH_VERSION="${PYTORCH_VERSION}"
COPY --chown=0:1111 ./COPY_ROOT_0/ /
ARG IMAGE_BASE
RUN set -eo pipefail && /opt/ai-dock/bin/build/layer0/init.sh | tee /var/log/build.log

RUN echo "bust cache"
# Install software
ARG COMFYUI_SHA
ENV COMFYUI_SHA=${COMFYUI_SHA}
ARG COMFYUI_BUILD_REF
ENV COMFYUI_BUILD_REF=${COMFYUI_BUILD_REF}
COPY --chown=0:1111 ./COPY_ROOT_1/ /
RUN set -eo pipefail && /opt/ai-dock/bin/build/layer1/init.sh | tee -a /var/log/build.log

Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ services:
args:
PYTHON_VERSION: ${PYTHON_VERSION:-3.10}
PYTORCH_VERSION: ${PYTORCH_VERSION:-2.3.0}
COMFYUI_SHA: ${COMFYUI_SHA:-}
COMFYUI_BUILD_REF: ${COMFYUI_BUILD_REF:-}
# Base on Python image which is base + python + jupyter
IMAGE_BASE: ${IMAGE_BASE:-ghcr.io/ai-dock/python:${PYTHON_VERSION:-3.10}-v2-cuda-12.1.1-base-22.04}
tags:
- "ghcr.io/ai-dock/comfyui:${IMAGE_TAG:-pytorch-${PYTORCH_VERSION:-2.3.0}-py3.10-cuda-12.1.1-base-22.04}"
- "ghcr.io/ai-dock/comfyui:${IMAGE_TAG:-pytorch-${PYTORCH_VERSION:-2.3.0}-py3.10-v2-cuda-12.1.1-base-22.04}"

image: ghcr.io/ai-dock/comfyui:${IMAGE_TAG:-pytorch-${PYTORCH_VERSION:-2.3.0}-py3.10-cuda-12.1.1-base-22.04}
image: ghcr.io/ai-dock/comfyui:${IMAGE_TAG:-pytorch-${PYTORCH_VERSION:-2.3.0}-py3.10-v2-cuda-12.1.1-base-22.04}

## For Nvidia GPU's - You probably want to uncomment this
#deploy:
Expand All @@ -40,7 +40,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
# In-container development
- ./build/COPY_ROOT_1/opt/ai-dock/api-wrapper:/opt/ai-dock/api-wrapper
ports:
Expand Down Expand Up @@ -68,14 +68,14 @@ services:
- CIVITAI_TOKEN=${CIVITAI_TOKEN:-}
- HF_TOKEN=${HF_TOKEN:-}
- WEB_ENABLE_AUTH=${WEB_ENABLE_AUTH:-true}
- WEB_ENABLE_HTTPS=${WEB_ENABLE_HTTPS:-true}
- WEB_ENABLE_HTTPS=${WEB_ENABLE_HTTPS:-false}
- WEB_USER=${WEB_USER:-user}
- WEB_PASSWORD=${WEB_PASSWORD:-password}
- SSH_PORT_HOST=${SSH_PORT_HOST:-2222}
- SERVICEPORTAL_PORT_HOST=${SERVICEPORTAL_PORT_HOST:-1111}
- SERVICEPORTAL_METRICS_PORT=${SERVICEPORTAL_METRICS_PORT:-21111}
- SERVICEPORTAL_URL=${SERVICEPORTAL_URL:-}
- COMFYUI_FLAGS=${COMFYUI_FLAGS:-}
- COMFYUI_ARGS=${COMFYUI_ARGS:-}
- COMFYUI_PORT_HOST=${COMFYUI_PORT_HOST:-8188}
- COMFYUI_METRICS_PORT=${COMFYUI_METRICS_PORT:-28188}
- COMFYUI_URL=${COMFYUI_URL:-}
Expand Down

0 comments on commit 5d83fe7

Please sign in to comment.