From f4e13b80e76ddaeddd4ebc863ca9ba97c3bca506 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Sat, 11 Jul 2026 15:11:22 +0200 Subject: [PATCH] feat: add script to launch Image Studio with local ComfyUI server --- README.md | 14 ++++++++ package.json | 1 + scripts/dev-with-comfy.sh | 74 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100755 scripts/dev-with-comfy.sh diff --git a/README.md b/README.md index fc50c8f..7e21406 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,19 @@ Start the development server: bun dev ``` +To start Image Studio together with the local headless ComfyUI server: + +```bash +bun run dev:full +``` + +The combined launcher reuses a ComfyUI server already listening at +`http://127.0.0.1:8188`. Otherwise, it starts the existing local ComfyUI +installation and stops that process when Image Studio exits. Its paths and +address can be overridden with the `COMFYUI_BASE_DIR`, `COMFYUI_SOURCE_DIR`, +`COMFYUI_PYTHON`, `COMFYUI_MODEL_PATHS_CONFIG`, `COMFYUI_HOST`, and +`COMFYUI_PORT` environment variables. + Build for production: ```bash @@ -53,6 +66,7 @@ bun start | Command | Description | | --- | --- | | `bun dev` | Start the app with Bun hot reload | +| `bun run dev:full` | Start the app and local headless ComfyUI server | | `bun run build` | Build the production bundle | | `bun start` | Run the production server | | `bun test` | Run tests | diff --git a/package.json b/package.json index aac2bf8..c673406 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "dev": "bun --hot index.ts", + "dev:full": "./scripts/dev-with-comfy.sh", "start": "NODE_ENV=production bun index.ts", "build": "bun run build.ts", "lint": "eslint .", diff --git a/scripts/dev-with-comfy.sh b/scripts/dev-with-comfy.sh new file mode 100755 index 0000000..afb6b33 --- /dev/null +++ b/scripts/dev-with-comfy.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +set -euo pipefail + +COMFYUI_HOST="${COMFYUI_HOST:-127.0.0.1}" +COMFYUI_PORT="${COMFYUI_PORT:-8188}" +COMFYUI_URL="${COMFYUI_URL:-http://${COMFYUI_HOST}:${COMFYUI_PORT}}" +COMFYUI_BASE_DIR="${COMFYUI_BASE_DIR:-/Users/syntaxbullet/Documents/ComfyUI}" +COMFYUI_SOURCE_DIR="${COMFYUI_SOURCE_DIR:-/Users/syntaxbullet/ComfyUI-Installs/ComfyUI/ComfyUI}" +COMFYUI_PYTHON="${COMFYUI_PYTHON:-${COMFYUI_BASE_DIR}/.venv/bin/python}" +COMFYUI_MODEL_PATHS_CONFIG="${COMFYUI_MODEL_PATHS_CONFIG:-/Users/syntaxbullet/Library/Application Support/Comfy Desktop/shared_model_paths.yaml}" +COMFYUI_READY_TIMEOUT_SECONDS="${COMFYUI_READY_TIMEOUT_SECONDS:-120}" + +comfy_pid="" + +cleanup() { + if [[ -n "${comfy_pid}" ]] && kill -0 "${comfy_pid}" 2>/dev/null; then + echo "Stopping ComfyUI (PID ${comfy_pid})..." + kill "${comfy_pid}" 2>/dev/null || true + wait "${comfy_pid}" 2>/dev/null || true + fi +} + +trap cleanup EXIT INT TERM + +comfy_is_ready() { + curl --fail --silent --show-error --max-time 2 "${COMFYUI_URL}/object_info" >/dev/null 2>&1 +} + +if comfy_is_ready; then + echo "Using existing ComfyUI server at ${COMFYUI_URL}." +else + if [[ ! -x "${COMFYUI_PYTHON}" ]]; then + echo "ComfyUI Python executable not found: ${COMFYUI_PYTHON}" >&2 + exit 1 + fi + + if [[ ! -f "${COMFYUI_SOURCE_DIR}/main.py" ]]; then + echo "ComfyUI entrypoint not found: ${COMFYUI_SOURCE_DIR}/main.py" >&2 + exit 1 + fi + + echo "Starting ComfyUI at ${COMFYUI_URL}..." + "${COMFYUI_PYTHON}" "${COMFYUI_SOURCE_DIR}/main.py" \ + --base-directory "${COMFYUI_BASE_DIR}" \ + --user-directory "${COMFYUI_BASE_DIR}/user" \ + --input-directory "${COMFYUI_BASE_DIR}/input" \ + --output-directory "${COMFYUI_BASE_DIR}/output" \ + --extra-model-paths-config "${COMFYUI_MODEL_PATHS_CONFIG}" \ + --listen "${COMFYUI_HOST}" \ + --port "${COMFYUI_PORT}" & + comfy_pid=$! + + deadline=$((SECONDS + COMFYUI_READY_TIMEOUT_SECONDS)) + until comfy_is_ready; do + if ! kill -0 "${comfy_pid}" 2>/dev/null; then + wait "${comfy_pid}" || true + echo "ComfyUI exited before becoming ready." >&2 + exit 1 + fi + + if (( SECONDS >= deadline )); then + echo "Timed out waiting for ComfyUI after ${COMFYUI_READY_TIMEOUT_SECONDS} seconds." >&2 + exit 1 + fi + + sleep 1 + done + + echo "ComfyUI is ready." +fi + +echo "Starting Image Studio..." +COMFYUI_URL="${COMFYUI_URL}" bun --hot index.ts