Initial: ImageLab v3 RunPod image

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
donnyandClaude Opus 4.7 committed 2026-05-17 21:42:52 -07:00
commit c8b93a1300
5 files changed
+424

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
.git
.gitea
README.md
*.md
+47
View File
@@ -0,0 +1,47 @@
name: Build and push image
on:
push:
branches:
- main
- master
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Gitea registry
uses: docker/login-action@v3
with:
registry: gitea.dev.blueoceanswim.com
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
- name: Compute tags
id: tags
run: |
IMAGE="gitea.dev.blueoceanswim.com/donny/imagelab-runpod"
TAGS="${IMAGE}:latest"
if [ -n "${GITHUB_REF_NAME:-}" ] && [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
TAGS="${TAGS},${IMAGE}:${GITHUB_REF_NAME}"
fi
SHA_SHORT=$(echo "${GITHUB_SHA}" | cut -c1-7)
TAGS="${TAGS},${IMAGE}:${SHA_SHORT}"
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=registry,ref=gitea.dev.blueoceanswim.com/donny/imagelab-runpod:buildcache
cache-to: type=registry,ref=gitea.dev.blueoceanswim.com/donny/imagelab-runpod:buildcache,mode=max
+90
View File
@@ -0,0 +1,90 @@
# ============================================================================
# ImageLab RunPod ComfyUI image
# CUDA 12.8 — Blackwell / Hopper / Ampere / consumer GPUs
# ============================================================================
# Build: docker build -t imagelab-runpod .
# Run: docker run --gpus all -p 8188:8188 \
# -e CIVITAI_TOKEN=... \
# -e IMAGELAB_AUTO_DOWNLOAD=... \
# -v /path/to/models:/workspace/ComfyUI/models \
# imagelab-runpod
#
# All model downloading is owned by the imagelab_v3_extension custom node
# (CIVITAI_TOKEN + IMAGELAB_AUTO_DOWNLOAD). This image only sets up the
# environment, ComfyUI itself, and the custom nodes the web app's workflow
# graph depends on.
# ============================================================================
FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu24.04
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_PREFER_BINARY=1
ENV CMAKE_BUILD_PARALLEL_LEVEL=8
# System deps: git for clones, build-essential + ninja for SageAttention,
# libgl/glib/etc for OpenCV-using custom nodes, jq for startup helpers.
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
curl \
wget \
ca-certificates \
python3 \
python3-venv \
python3-pip \
python3-dev \
build-essential \
ninja-build \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
jq \
&& rm -rf /var/lib/apt/lists/*
# Isolated venv keeps the system Python untouched on RunPod.
RUN python3 -m venv /opt/venv
ENV PATH=/opt/venv/bin:$PATH
RUN pip install --upgrade pip setuptools wheel
# PyTorch nightly w/ CUDA 12.8 — required for Blackwell (B200/GB200/5090).
RUN pip install --pre torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/nightly/cu128
# Triton up front so the SageAttention install step is fast at boot.
RUN pip install triton
# A handful of deps the startup script and most custom nodes pull in.
RUN pip install pyyaml huggingface_hub torchsde einops packaging aiohttp
WORKDIR /workspace
# Startup
COPY startup.sh /startup/startup.sh
RUN chmod +x /startup/startup.sh
# Model dir scaffolding (RunPod mounts a volume on top of /workspace/ComfyUI/models
# in most templates; pre-creating the tree means the imagelab_v3_extension node
# finds it whether or not a volume is mounted).
RUN mkdir -p /workspace/ComfyUI/models/checkpoints \
/workspace/ComfyUI/models/vae \
/workspace/ComfyUI/models/loras \
/workspace/ComfyUI/models/controlnet \
/workspace/ComfyUI/models/upscale_models \
/workspace/ComfyUI/models/embeddings \
/workspace/ComfyUI/models/clip \
/workspace/ComfyUI/models/clip_vision
EXPOSE 8188
# Defaults — override at runtime.
ENV CIVITAI_TOKEN=""
ENV IMAGELAB_AUTO_DOWNLOAD=""
ENV HF_TOKEN=""
ENV SAGE_ATTENTION="true"
ENV COMFYUI_ARGS=""
CMD ["/startup/startup.sh"]
+74
View File
@@ -0,0 +1,74 @@
# imagelab-runpod
ComfyUI Docker image for RunPod, built around the **imagelab_v3_extension** custom node. Model downloading is owned by the extension (`CIVITAI_TOKEN` + `IMAGELAB_AUTO_DOWNLOAD`); this image only sets up the runtime and the small set of custom nodes the ImageLab web app's workflow graph needs.
## What's inside
- `nvidia/cuda:12.8.1-cudnn-devel-ubuntu24.04` base
- PyTorch nightly w/ CUDA 12.8 — required for Blackwell (B200 / 5090) GPUs; works on Hopper / Ampere / consumer cards too
- Triton + SageAttention (installed in background at boot; auto-enabled when present)
- ComfyUI launched with `--preview-method taesd --preview-size 768 --enable-cors-header` so the web app sees live previews
### Custom nodes installed
| Node | Why |
| --- | --- |
| `imagelab_v3_extension` | `/imagelab/*` API — model hashing, CivitAI lookups + downloads, model delete |
| `ComfyUI-Inpaint-CropAndStitch` | `InpaintCropImproved` / `InpaintStitchImproved` (canvas inpaint pipeline) |
| `ComfyUI-BRIA_AI-RMBG` | `BRIA_RMBG_ModelLoader_Zho` / `BRIA_RMBG_Zho` (Remove BG post step) |
| `ComfyUI-WD14-Tagger` | `WD14Tagger\|pysssss` (legacy auto-tag path; harmless if unused) |
| `ComfyUI-Manager` | In-UI node manager — useful on a fresh pod |
| `ComfyUI-Custom-Scripts` | rgthree-adjacent QoL — pythongosssss helpers |
| `rgthree-comfy` | QoL routing / reroute / fast groups |
| `ComfyUI_essentials` | Common utility nodes a lot of community workflows assume |
The BRIA RMBG-1.4 model is downloaded at first boot into the node's `RMBG-1.4` folder (HF; works without auth, but pass `HF_TOKEN` if you've been rate-limited).
## Environment variables
| Var | Default | Effect |
| --- | --- | --- |
| `CIVITAI_TOKEN` | unset | Read by the extension. **Required** for any gated CivitAI download. |
| `IMAGELAB_AUTO_DOWNLOAD` | unset | Comma/newline list the extension queues at server start (CivitAI version ids, model ids, full URLs, or `<folder>::<entry>` overrides). |
| `HF_TOKEN` | unset | Used by the BRIA RMBG download if HuggingFace rate-limits anon. |
| `SAGE_ATTENTION` | `true` | `false` to skip install + `--use-sage-attention` entirely. |
| `COMFYUI_ARGS` | (auto) | Override the auto-derived ComfyUI args completely. |
## Building locally
```bash
docker build -t imagelab-runpod .
docker run --gpus all -p 8188:8188 \
-e CIVITAI_TOKEN=... \
-e IMAGELAB_AUTO_DOWNLOAD=... \
-v /path/to/models:/workspace/ComfyUI/models \
imagelab-runpod
```
## CI / publishing
`.gitea/workflows/build.yml` builds + pushes the image to `gitea.dev.blueoceanswim.com/donny/imagelab-runpod` on every push to `main` and on every `v*` tag:
- `:latest` — every main build
- `:<short-sha>` — every build
- `:<tag>` — when a `v*` tag is pushed
Needs a `GITEA_TOKEN` secret with write access to the package registry on this repo.
## Pointing RunPod at the image
In RunPod, pick **Custom Template**, set the image to `gitea.dev.blueoceanswim.com/donny/imagelab-runpod:latest`, expose port `8188`, mount your volume at `/workspace/ComfyUI/models`, and set the env vars above.
## GPU notes
The startup script reads `nvidia-smi` and picks ComfyUI flags by VRAM bucket:
| VRAM | Precision | Notes |
| --- | --- | --- |
| ≥ 180 GB | `--bf16-vae --bf16-unet` | B200 / GB200 |
| ≥ 80 GB | `--bf16-vae --bf16-unet` | H100 / H200 |
| ≥ 40 GB | `--fp16-vae --fp16-unet` | A100 |
| ≥ 20 GB | `--fp16-vae --fp16-unet` | RTX 3090 / 4090 / 5090 |
| < 20 GB | `--lowvram` | anything smaller |
When SageAttention is installed (default), `--use-sage-attention` is added automatically.
Executable
+209
View File
@@ -0,0 +1,209 @@
#!/bin/bash
set -e
# ============================================================================
# ImageLab RunPod startup
# ----------------------------------------------------------------------------
# All model-downloading is owned by imagelab_v3_extension (it reads
# IMAGELAB_AUTO_DOWNLOAD + CIVITAI_TOKEN at server start). This script just
# brings up ComfyUI + the custom nodes the web app's graph references, then
# launches the server with sensible flags for the detected GPU.
# ============================================================================
COMFYUI_DIR="/workspace/ComfyUI"
CUSTOM_NODES_DIR="$COMFYUI_DIR/custom_nodes"
# Colors
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_step() { echo -e "${BLUE}[STEP]${NC} $1"; }
# ----------------------------------------------------------------------------
# Custom nodes
# ----------------------------------------------------------------------------
# Everything the web app's graph references plus a small set of QoL nodes.
# Keep this list tight — every entry slows boot.
#
# * imagelab_v3_extension → /imagelab/* API: hashing, downloads, CivitAI
# * ComfyUI-Inpaint-CropAndStitch → InpaintCropImproved / InpaintStitchImproved
# * ComfyUI-BRIA_AI-RMBG → BRIA_RMBG_ModelLoader_Zho + BRIA_RMBG_Zho
# * ComfyUI-WD14-Tagger → kept available (old AutoTag path; harmless if unused)
# * ComfyUI-Manager → in-UI node manager (very useful on a fresh pod)
# * rgthree-comfy / custom-scripts → QoL UI nodes the user is likely to want
# ----------------------------------------------------------------------------
CUSTOM_NODES=(
"https://gitea.dev.blueoceanswim.com/donny/imagelab_v3_extension.git"
"https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch.git"
"https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG.git"
"https://github.com/pythongosssss/ComfyUI-WD14-Tagger.git"
"https://github.com/ltdrdata/ComfyUI-Manager.git"
"https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git"
"https://github.com/rgthree/rgthree-comfy.git"
"https://github.com/cubiq/ComfyUI_essentials.git"
)
# ----------------------------------------------------------------------------
# ComfyUI
# ----------------------------------------------------------------------------
setup_comfyui() {
log_step "Setting up ComfyUI"
if [ -d "$COMFYUI_DIR/.git" ]; then
log_info "ComfyUI exists — pulling latest"
git -C "$COMFYUI_DIR" pull --ff-only || log_warn "Failed to pull ComfyUI updates"
else
log_info "Cloning ComfyUI"
git clone --depth 1 https://github.com/comfyanonymous/ComfyUI.git "$COMFYUI_DIR"
fi
log_info "Installing ComfyUI requirements (skipping pre-installed torch)"
cd "$COMFYUI_DIR"
grep -v -E "^torch==|^torch\[|^torch$|^torchvision|^torchaudio" requirements.txt > /tmp/comfy_req.txt
pip install -r /tmp/comfy_req.txt 2>&1 | tail -10
rm -f /tmp/comfy_req.txt
}
# ----------------------------------------------------------------------------
# Custom nodes
# ----------------------------------------------------------------------------
install_custom_nodes() {
log_step "Installing custom nodes"
mkdir -p "$CUSTOM_NODES_DIR"
for repo in "${CUSTOM_NODES[@]}"; do
name=$(basename "$repo" .git)
path="$CUSTOM_NODES_DIR/$name"
if [ -d "$path/.git" ]; then
log_info "Updating $name"
git -C "$path" pull --ff-only 2>/dev/null || log_warn "Failed to update $name"
else
log_info "Cloning $name"
git -C "$CUSTOM_NODES_DIR" clone --depth 1 "$repo" 2>/dev/null || log_warn "Failed to clone $name"
fi
done
log_step "Installing node requirements"
for path in "$CUSTOM_NODES_DIR"/*/; do
name=$(basename "$path")
if [ -f "$path/requirements.txt" ]; then
log_info " $name"
pip install -q -r "$path/requirements.txt" 2>&1 | grep -v "already satisfied" || true
fi
done
# Some nodes have an install.py — run it if present.
for path in "$CUSTOM_NODES_DIR"/*/; do
if [ -f "$path/install.py" ]; then
log_info " install.py for $(basename "$path")"
( cd "$path" && python install.py 2>&1 | tail -3 ) || true
fi
done
}
# ----------------------------------------------------------------------------
# BRIA RMBG model (the BRIA_RMBG_* nodes look for it under their own dir)
# ----------------------------------------------------------------------------
download_bria_model() {
BRIA_DIR="$CUSTOM_NODES_DIR/ComfyUI-BRIA_AI-RMBG/RMBG-1.4"
if [ -f "$BRIA_DIR/model.pth" ]; then
log_info "BRIA RMBG-1.4 already present"
return
fi
log_step "Downloading BRIA RMBG-1.4"
python3 - <<PY || log_warn "BRIA RMBG download failed"
import os
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="briaai/RMBG-1.4",
local_dir="$BRIA_DIR",
token=os.environ.get("HF_TOKEN") or None,
)
print("BRIA RMBG-1.4 downloaded")
PY
}
# ----------------------------------------------------------------------------
# SageAttention (background) — ~3x sampler speedup on supported GPUs.
# ----------------------------------------------------------------------------
install_sage_attention() {
local setting="${SAGE_ATTENTION:-true}"
if [ "$setting" = "false" ]; then
log_info "SageAttention disabled (SAGE_ATTENTION=false)"
return
fi
log_step "Installing SageAttention in the background"
(
pip install -q sageattention 2>&1 | tail -3 \
&& touch /tmp/.sageattention_installed \
&& log_info "SageAttention installed" \
|| log_warn "SageAttention install failed"
) &
}
# ----------------------------------------------------------------------------
# ComfyUI launch — GPU-aware default args
# ----------------------------------------------------------------------------
start_comfyui() {
log_step "Starting ComfyUI"
cd "$COMFYUI_DIR"
if [ -z "$COMFYUI_ARGS" ]; then
VRAM_MB=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | head -1)
VRAM_GB=$(( ${VRAM_MB:-0} / 1024 ))
GPU_NAME=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
log_info "GPU: ${GPU_NAME:-unknown} (${VRAM_GB} GB)"
# Common args: bind all ifaces, TAESD live previews (what the web app
# reads as binary WS frames), CORS open so the browser can talk to us.
BASE_ARGS="--listen 0.0.0.0 --port 8188 --preview-method taesd --preview-size 768 --enable-cors-header"
if [ "$VRAM_GB" -ge 180 ]; then
log_info "Blackwell-class GPU — bf16"
COMFYUI_ARGS="$BASE_ARGS --bf16-vae --bf16-unet"
elif [ "$VRAM_GB" -ge 80 ]; then
log_info "Hopper-class GPU — bf16"
COMFYUI_ARGS="$BASE_ARGS --bf16-vae --bf16-unet"
elif [ "$VRAM_GB" -ge 40 ]; then
log_info "Ampere-class GPU — fp16"
COMFYUI_ARGS="$BASE_ARGS --fp16-vae --fp16-unet"
elif [ "$VRAM_GB" -ge 20 ]; then
log_info "Consumer GPU — fp16"
COMFYUI_ARGS="$BASE_ARGS --fp16-vae --fp16-unet"
else
log_info "Low-VRAM GPU — --lowvram"
COMFYUI_ARGS="$BASE_ARGS --lowvram"
fi
if [ -f /tmp/.sageattention_installed ] && [ "${SAGE_ATTENTION:-true}" != "false" ]; then
log_info "Enabling --use-sage-attention"
COMFYUI_ARGS="$COMFYUI_ARGS --use-sage-attention"
fi
fi
log_info "Args: $COMFYUI_ARGS"
log_info "ComfyUI on http://0.0.0.0:8188"
exec python main.py $COMFYUI_ARGS
}
# ----------------------------------------------------------------------------
# main
# ----------------------------------------------------------------------------
log_info "=========================================="
log_info "ImageLab RunPod"
log_info "=========================================="
log_info "CIVITAI_TOKEN=$( [ -n "$CIVITAI_TOKEN" ] && echo set || echo unset )"
log_info "IMAGELAB_AUTO_DOWNLOAD=$( [ -n "$IMAGELAB_AUTO_DOWNLOAD" ] && echo set || echo unset )"
log_info "SAGE_ATTENTION=${SAGE_ATTENTION:-true}"
log_info "=========================================="
setup_comfyui
install_custom_nodes
install_sage_attention # background
download_bria_model &
BRIA_PID=$!
wait $BRIA_PID || true
start_comfyui