Refactor bootstrap script for SwarmUI management and enhance error handling

- Introduced functions `swarm_git_ok`, `clone_swarmui`, and `update_swarmui` to streamline the cloning and updating process of SwarmUI.
- Improved error handling during the update process, ensuring a fallback to cloning if the update fails.
- Enhanced logging messages for better visibility during cloning and updating operations.
- Updated tests to verify the presence of new functions and logging messages in the bootstrap script.
This commit is contained in:
Leonid Pershin
2026-08-21 10:27:25 +03:00
parent 9e63c0722e
commit dd0ffbf69b
2 changed files with 31 additions and 5 deletions
+29 -5
View File
@@ -127,16 +127,30 @@ fi
rm -f "${DATA_ROOT}/.gpu-rent-llm-only" 2>/dev/null || true
if [[ ! -d "${SWARM_ROOT}/.git" ]]; then
log "clone SwarmUI -> ${SWARM_ROOT}"
swarm_git_ok() {
# .git dir can exist after a failed/partial boot and still not be a repo.
[[ -d "${SWARM_ROOT}/.git" ]] \
&& git -C "$SWARM_ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1
}
clone_swarmui() {
mkdir -p "$(dirname "$SWARM_ROOT")"
if [[ -e "$SWARM_ROOT" ]]; then
log "удаляю битый/неполный ${SWARM_ROOT} перед clone"
rm -rf "$SWARM_ROOT"
fi
log "clone SwarmUI -> ${SWARM_ROOT}"
git clone --depth 1 "$SWARM_REPO" "$SWARM_ROOT"
elif [[ "${GPU_RENT_UPDATE_GIT:-1}" == "1" ]]; then
log "обновляю SwarmUI в ${SWARM_ROOT}"
}
update_swarmui() {
local branch
branch="$(git -C "$SWARM_ROOT" remote show origin 2>/dev/null | sed -n '/HEAD branch/s/.*: //p' || true)"
branch="${branch:-master}"
# shallow clone: deepen tip of default branch
git -C "$SWARM_ROOT" fetch --depth 1 origin "$branch" || git -C "$SWARM_ROOT" fetch --depth 1 origin
git -C "$SWARM_ROOT" fetch --depth 1 origin "$branch" \
|| git -C "$SWARM_ROOT" fetch --depth 1 origin \
|| return 1
if git -C "$SWARM_ROOT" rev-parse --verify -q "origin/${branch}" >/dev/null; then
git -C "$SWARM_ROOT" checkout -B "$branch" "origin/${branch}"
git -C "$SWARM_ROOT" reset --hard "origin/${branch}"
@@ -144,6 +158,16 @@ elif [[ "${GPU_RENT_UPDATE_GIT:-1}" == "1" ]]; then
git -C "$SWARM_ROOT" pull --ff-only || true
fi
log "SwarmUI @ $(git -C "$SWARM_ROOT" rev-parse --short HEAD)"
}
if ! swarm_git_ok; then
clone_swarmui
elif [[ "${GPU_RENT_UPDATE_GIT:-1}" == "1" ]]; then
log "обновляю SwarmUI в ${SWARM_ROOT}"
if ! update_swarmui; then
log "WARN: git update failed (exit $?) — переклонирую"
clone_swarmui
fi
else
log "SwarmUI уже в ${SWARM_ROOT} (update off)"
fi