mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-05 23:02:49 +08:00
Refactor entrypoint.sh for improved logging and ownership
This commit is contained in:
parent
7b3b6fcbfd
commit
d303280af5
@ -1,70 +1,101 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
# Timestamped xtrace (enable by uncommenting: set -x)
|
||||||
|
export PS4='+ [${EPOCHREALTIME}] ${BASH_SOURCE##*/}:${LINENO}: '
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
log() { printf '[entrypoint] %s\n' "$*" >&2; }
|
||||||
|
|
||||||
APP_USER=${APP_USER:-appuser}
|
APP_USER=${APP_USER:-appuser}
|
||||||
APP_GROUP=${APP_GROUP:-appuser}
|
APP_GROUP=${APP_GROUP:-appuser}
|
||||||
PUID=${PUID:-1000}
|
PUID=${PUID:-1000}
|
||||||
PGID=${PGID:-1000}
|
PGID=${PGID:-1000}
|
||||||
|
|
||||||
BASE_DIR=/app/ComfyUI
|
BASE_DIR=/app/ComfyUI
|
||||||
CUSTOM_NODES_DIR="$BASE_DIR/custom_nodes"
|
CUSTOM_NODES_DIR="$BASE_DIR/custom_nodes"
|
||||||
|
|
||||||
# If running as root, map to requested UID/GID, fix ownership, and make Python install targets writable
|
|
||||||
if [ "$(id -u)" = "0" ]; then
|
if [ "$(id -u)" = "0" ]; then
|
||||||
|
log "Running as root; mapping to UID=${PUID} GID=${PGID} and fixing ownerships"
|
||||||
# Map group to PGID if it already exists, otherwise remap the named group
|
# Map group to PGID if it already exists, otherwise remap the named group
|
||||||
if getent group "${PGID}" >/dev/null; then
|
if getent group "${PGID}" >/dev/null; then
|
||||||
EXISTING_GRP="$(getent group "${PGID}" | cut -d: -f1)"
|
EXISTING_GRP="$(getent group "${PGID}" | cut -d: -f1)"
|
||||||
|
log "Using existing group ${EXISTING_GRP} for GID ${PGID}"
|
||||||
usermod -g "${EXISTING_GRP}" "${APP_USER}" || true
|
usermod -g "${EXISTING_GRP}" "${APP_USER}" || true
|
||||||
APP_GROUP="${EXISTING_GRP}"
|
APP_GROUP="${EXISTING_GRP}"
|
||||||
else
|
else
|
||||||
|
log "Remapping group ${APP_GROUP} to GID ${PGID}"
|
||||||
groupmod -o -g "${PGID}" "${APP_GROUP}" || true
|
groupmod -o -g "${PGID}" "${APP_GROUP}" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Map user to PUID
|
# Map user to PUID
|
||||||
|
log "Remapping user ${APP_USER} to UID ${PUID}"
|
||||||
usermod -o -u "${PUID}" "${APP_USER}" || true
|
usermod -o -u "${PUID}" "${APP_USER}" || true
|
||||||
|
|
||||||
# Ensure home and app dir exist and are owned
|
# Ensure home and app dir exist and are owned
|
||||||
mkdir -p "/home/${APP_USER}"
|
mkdir -p "/home/${APP_USER}"
|
||||||
for d in "$BASE_DIR" "/home/$APP_USER"; do
|
for d in "$BASE_DIR" "/home/$APP_USER"; do
|
||||||
[ -e "$d" ] && chown -R "${APP_USER}:${APP_GROUP}" "$d" || true
|
if [ -e "$d" ]; then
|
||||||
|
log "Ensuring ownership ${APP_USER}:${APP_GROUP} on ${d}"
|
||||||
|
chown -R "${APP_USER}:${APP_GROUP}" "$d" || true
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Make Python system install targets writable for the runtime user
|
# Discover Python system install targets and make them writable for runtime user
|
||||||
# Includes: site-packages (purelib/platlib), scripts, headers, data, and data/share(+man1)
|
# Includes: site-packages (purelib/platlib), scripts, headers, data, and data/share(+man1)
|
||||||
# Discards anything not under /usr/local to avoid over-broad changes.
|
# Discards anything not under /usr/local to avoid over-broad changes.
|
||||||
readarray -t PY_PATHS < <(python - <<'PY'
|
log "Discovering Python install paths via sysconfig (unbuffered Python logging enabled)"
|
||||||
import sysconfig, os
|
readarray -t PY_PATHS < <(
|
||||||
keys = ("purelib","platlib","scripts","include","platinclude","data")
|
env PYTHONUNBUFFERED=1 python - <<'PY'
|
||||||
|
import sys, os, sysconfig
|
||||||
|
|
||||||
|
def emit(label, path):
|
||||||
|
if not path:
|
||||||
|
return
|
||||||
|
# stdout: raw path for readarray
|
||||||
|
print(path)
|
||||||
|
# stderr: labeled diagnostics for logs
|
||||||
|
print(f"[py] {label}: {path}", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
p = sysconfig.get_paths()
|
p = sysconfig.get_paths()
|
||||||
for k in keys:
|
for k in ("purelib","platlib","scripts","include","platinclude","data"):
|
||||||
v = p.get(k)
|
emit(k, p.get(k))
|
||||||
if v:
|
|
||||||
print(v)
|
|
||||||
d = p.get("data")
|
d = p.get("data")
|
||||||
if d:
|
if d:
|
||||||
# Wheel .data/data payloads commonly land under {data}/share, including manpages like ttx.1
|
# Wheel .data/data payloads commonly land under {data}/share, including manpages like ttx.1
|
||||||
print(os.path.join(d, "share"))
|
emit("share", os.path.join(d, "share"))
|
||||||
print(os.path.join(d, "share", "man", "man1"))
|
emit("man1", os.path.join(d, "share", "man", "man1"))
|
||||||
PY
|
PY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log "Found ${#PY_PATHS[@]} Python target paths:"
|
||||||
|
for p in "${PY_PATHS[@]}"; do
|
||||||
|
printf ' - %s\n' "$p" >&2
|
||||||
|
done
|
||||||
|
|
||||||
for d in "${PY_PATHS[@]}"; do
|
for d in "${PY_PATHS[@]}"; do
|
||||||
case "$d" in
|
case "$d" in
|
||||||
/usr/local/*)
|
/usr/local/*)
|
||||||
|
log "Ensuring writable under /usr/local: ${d}"
|
||||||
mkdir -p "$d" || true
|
mkdir -p "$d" || true
|
||||||
chown -R "${APP_USER}:${APP_GROUP}" "$d" || true
|
chown -R "${APP_USER}:${APP_GROUP}" "$d" || true
|
||||||
chmod -R u+rwX,g+rwX "$d" || true
|
chmod -R u+rwX,g+rwX "$d" || true
|
||||||
;;
|
;;
|
||||||
*) : ;;
|
*)
|
||||||
|
log "Skipping non-/usr/local path: ${d}"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Re-exec as the runtime user
|
log "Re-exec as runtime user ${APP_USER} (UID=${PUID}, GID=${PGID})"
|
||||||
exec runuser -u "${APP_USER}" -- "$0" "$@"
|
exec runuser -u "${APP_USER}" -- "$0" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log "Running as $(id -un) (UID=$(id -u))"
|
||||||
|
|
||||||
# Ensure ComfyUI-Manager exists (bind mounts can hide baked content)
|
# Ensure ComfyUI-Manager exists (bind mounts can hide baked content)
|
||||||
if [ ! -d "$CUSTOM_NODES_DIR/ComfyUI-Manager" ]; then
|
if [ ! -d "$CUSTOM_NODES_DIR/ComfyUI-Manager" ]; then
|
||||||
echo "[bootstrap] Installing ComfyUI-Manager into $CUSTOM_NODES_DIR/ComfyUI-Manager"
|
log "Installing ComfyUI-Manager into $CUSTOM_NODES_DIR/ComfyUI-Manager"
|
||||||
git clone --depth 1 https://github.com/ltdrdata/ComfyUI-Manager.git "$CUSTOM_NODES_DIR/ComfyUI-Manager" || true
|
git clone --depth 1 https://github.com/ltdrdata/ComfyUI-Manager.git "$CUSTOM_NODES_DIR/ComfyUI-Manager" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -75,18 +106,19 @@ export PYTHONPATH="$HOME/.local/lib/python${pyver}/site-packages:${PYTHONPATH:-}
|
|||||||
|
|
||||||
# Auto-install custom node deps
|
# Auto-install custom node deps
|
||||||
if [ "${COMFY_AUTO_INSTALL:-1}" = "1" ]; then
|
if [ "${COMFY_AUTO_INSTALL:-1}" = "1" ]; then
|
||||||
echo "[deps] Scanning custom nodes for requirements..."
|
log "[deps] Scanning custom nodes for requirements..."
|
||||||
while IFS= read -r -d '' req; do
|
while IFS= read -r -d '' req; do
|
||||||
echo "[deps] pip install --user -r $req"
|
log "[deps] pip install --user -r $req"
|
||||||
pip install --no-cache-dir --user -r "$req" || true
|
pip install --no-cache-dir --user -r "$req" || true
|
||||||
done < <(find "$CUSTOM_NODES_DIR" -maxdepth 3 -type f \( -iname 'requirements.txt' -o -iname 'requirements-*.txt' -o -path '*/requirements/*.txt' \) -print0)
|
done < <(find "$CUSTOM_NODES_DIR" -maxdepth 3 -type f \( -iname 'requirements.txt' -o -iname 'requirements-*.txt' -o -path '*/requirements/*.txt' \) -print0)
|
||||||
|
|
||||||
while IFS= read -r -d '' pjt; do
|
while IFS= read -r -d '' pjt; do
|
||||||
d="$(dirname "$pjt")"
|
d="$(dirname "$pjt")"
|
||||||
echo "[deps] pip install --user . in $d"
|
log "[deps] pip install --user . in $d"
|
||||||
(cd "$d" && pip install --no-cache-dir --user .) || true
|
(cd "$d" && pip install --no-cache-dir --user .) || true
|
||||||
done < <(find "$CUSTOM_NODES_DIR" -maxdepth 2 -type f -iname 'pyproject.toml' -print0)
|
done < <(find "$CUSTOM_NODES_DIR" -maxdepth 2 -type f -iname 'pyproject.toml' -print0)
|
||||||
|
|
||||||
|
log "[deps] pip check (sanity)"
|
||||||
pip check || true
|
pip check || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user