Fix local run freshness and plugin asset handling

This commit is contained in:
npc0-hue
2026-08-22 19:45:00 +08:00
parent bb5e48b29c
commit ebd616c549
23 changed files with 312 additions and 58 deletions
+87 -5
View File
@@ -60,6 +60,39 @@ wait_for_pid_exit() {
return 1
}
hash_stream() {
shasum -a 256 | awk '{print $1}'
}
tracked_tree_fingerprint() {
local repo_dir="$1"
shift
(
cd "$repo_dir"
{
git ls-files -z -- "$@"
git ls-files -z --others --exclude-standard -- "$@"
} | sort -z | while IFS= read -r -d '' file; do
[[ -f "$file" ]] || continue
shasum -a 256 "$file"
done
git diff --binary -- "$@"
) | hash_stream
}
file_fingerprint() {
local file="$1"
if [[ ! -f "$file" ]]; then
printf 'missing:%s\n' "$file" | hash_stream
return 0
fi
shasum -a 256 "$file" | awk '{print $1}'
}
combined_fingerprint() {
printf '%s\n' "$@" | hash_stream
}
descendant_pids() {
local pid="$1"
local child
@@ -148,17 +181,30 @@ ensure_port_available() {
start_service() {
local name="$1"
local service_dir="$2"
local fingerprint="$3"
local pid_file="$LOCAL_DEBUG_PID_DIR/$name.pid"
shift 2
local fingerprint_file="$LOCAL_DEBUG_PID_DIR/$name.fingerprint"
shift 3
if [[ -f "$pid_file" ]]; then
local existing_pid
existing_pid="$(cat "$pid_file")"
if kill -0 "$existing_pid" 2>/dev/null; then
local previous_fingerprint=""
if [[ -n "$fingerprint" && -f "$fingerprint_file" ]]; then
previous_fingerprint="$(cat "$fingerprint_file")"
fi
if [[ -n "$fingerprint" && "$previous_fingerprint" != "$fingerprint" ]]; then
printf '%s source or environment changed; restarting pid %s\n' "$name" "$existing_pid"
stop_pid_tree "$name" "$existing_pid"
rm -f "$pid_file"
else
printf '%s already running with pid %s\n' "$name" "$existing_pid"
return 0
fi
else
rm -f "$pid_file" "$fingerprint_file"
fi
rm -f "$pid_file"
fi
printf 'starting %s\n' "$name"
@@ -167,6 +213,11 @@ start_service() {
exec nohup "$@" >"$LOCAL_DEBUG_LOG_DIR/$name.log" 2>&1
) >/dev/null 2>&1 &
printf '%s' "$!" >"$pid_file"
if [[ -n "$fingerprint" ]]; then
printf '%s' "$fingerprint" >"$fingerprint_file"
else
rm -f "$fingerprint_file"
fi
printf '%s pid %s log %s\n' "$name" "$(cat "$pid_file")" "$LOCAL_DEBUG_LOG_DIR/$name.log"
}
@@ -202,10 +253,26 @@ printf 'platform log: %s\n' "$LOCAL_DEBUG_LOG_DIR/platform.log"
printf 'run log: %s\n' "$LOCAL_DEBUG_LOG_DIR/run.log"
printf 'platform_web log: %s\n' "$LOCAL_DEBUG_LOG_DIR/platform_web.log"
platform_fingerprint="$(combined_fingerprint \
"$(tracked_tree_fingerprint "$ROOT_DIR" platform scripts/dev-start.sh scripts/local-debug)" \
"PLATFORM_ADDR=$PLATFORM_ADDR" \
"PLATFORM_STORAGE_BACKEND=$PLATFORM_STORAGE_BACKEND" \
"PLATFORM_METADATA_PATH=$PLATFORM_METADATA_PATH" \
"PLATFORM_LOG_BODY_BACKEND=$PLATFORM_LOG_BODY_BACKEND" \
"PLATFORM_RUN_RELEASE_URL=$PLATFORM_RUN_RELEASE_URL" \
"PLATFORM_BUILDER_IMAGE=$PLATFORM_BUILDER_IMAGE" \
"PLATFORM_BUILDER_SOURCE_DIR=$PLATFORM_BUILDER_SOURCE_DIR" \
"PLATFORM_BUILDER_SOURCE_REVISION=$PLATFORM_BUILDER_SOURCE_REVISION")"
web_fingerprint="$(combined_fingerprint \
"$(tracked_tree_fingerprint "$ROOT_DIR" platform_web package.json package-lock.json scripts/dev-start.sh scripts/local-debug)" \
"PLATFORM_API_PROXY=$PLATFORM_API_PROXY" \
"VITE_PLATFORM_API_BASE_URL=$VITE_PLATFORM_API_BASE_URL" \
"VITE_ENABLE_LOCAL_AUTH_FALLBACK=$VITE_ENABLE_LOCAL_AUTH_FALLBACK")"
ensure_port_available platform "$LOCAL_DEBUG_PLATFORM_PORT"
ensure_port_available platform_web "$LOCAL_DEBUG_WEB_PORT"
start_service platform "$ROOT_DIR/platform" env \
start_service platform "$ROOT_DIR/platform" "$platform_fingerprint" env \
GOCACHE="$GOCACHE" \
PLATFORM_ADDR="$PLATFORM_ADDR" \
PLATFORM_STORAGE_BACKEND="$PLATFORM_STORAGE_BACKEND" \
@@ -230,7 +297,7 @@ start_service platform "$ROOT_DIR/platform" env \
wait_for_url platform "$(local_debug_platform_url)/healthz"
start_service platform_web "$ROOT_DIR" env \
start_service platform_web "$ROOT_DIR" "$web_fingerprint" env \
PLATFORM_API_PROXY="$PLATFORM_API_PROXY" \
VITE_PLATFORM_API_BASE_URL="$VITE_PLATFORM_API_BASE_URL" \
VITE_ENABLE_LOCAL_AUTH_FALLBACK="$VITE_ENABLE_LOCAL_AUTH_FALLBACK" \
@@ -240,7 +307,22 @@ wait_for_url platform_web "$(local_debug_web_url)"
stop_orphaned_run_bootstrap
local_debug_build_bootstrap_run
start_service run "$(dirname "$RUN_BOOTSTRAP_BIN")" env \
run_fingerprint="$(combined_fingerprint \
"$(tracked_tree_fingerprint "$RUN_SOURCE_DIR" .)" \
"$(file_fingerprint "$RUN_BOOTSTRAP_BIN")" \
"RUN_MODE=$RUN_MODE" \
"RUN_PLATFORM_URL=$RUN_PLATFORM_URL" \
"RUN_ENDPOINT_ID=$RUN_ENDPOINT_ID" \
"RUN_DISPLAY_NAME=$RUN_DISPLAY_NAME" \
"RUN_VERSION=$RUN_VERSION" \
"RUN_WORKSPACE_ROOT=$RUN_WORKSPACE_ROOT" \
"RUN_BUILD_SOURCE_ROOT=$RUN_BUILD_SOURCE_ROOT" \
"RUN_SPOOL_ROOT=$RUN_SPOOL_ROOT" \
"RUN_MAX_JOBS=$RUN_MAX_JOBS" \
"RUN_HEARTBEAT_INTERVAL_MS=$RUN_HEARTBEAT_INTERVAL_MS" \
"RUN_POLL_INTERVAL_MS=$RUN_POLL_INTERVAL_MS" \
"RUN_RETRY_BACKOFF_MS=$RUN_RETRY_BACKOFF_MS")"
start_service run "$(dirname "$RUN_BOOTSTRAP_BIN")" "$run_fingerprint" env \
GOCACHE="$GOCACHE" \
RUN_MODE="$RUN_MODE" \
RUN_PLATFORM_URL="$RUN_PLATFORM_URL" \