fix: 调试发布run

This commit is contained in:
npc0-hue
2026-07-22 11:44:48 +08:00
parent b06623d0ce
commit 6c3eb6e45f
41 changed files with 1289 additions and 206 deletions
+117 -5
View File
@@ -26,7 +26,8 @@ export PLATFORM_BOOTSTRAP_ADMIN_PASSWORD="${PLATFORM_BOOTSTRAP_ADMIN_PASSWORD:-o
export PLATFORM_SECRET_ENVELOPE_KEY="${PLATFORM_SECRET_ENVELOPE_KEY:-local-debug-secret-envelope-key-change-me}"
export PLATFORM_AI_PROVIDER_MODE="${PLATFORM_AI_PROVIDER_MODE:-mock}"
export RUN_REPO_DIR="${RUN_REPO_DIR:-$(cd "$LOCAL_DEBUG_ROOT_DIR/.." && pwd)/run}"
export RUN_SOURCE_DIR="${RUN_SOURCE_DIR:-${RUN_REPO_DIR:-$LOCAL_DEBUG_ROOT_DIR/run}}"
export RUN_REPO_DIR="$RUN_SOURCE_DIR"
export RUN_MODE="${RUN_MODE:-worker}"
export RUN_PLATFORM_URL="${RUN_PLATFORM_URL:-http://127.0.0.1:$LOCAL_DEBUG_PLATFORM_PORT}"
export RUN_ENDPOINT_ID="${RUN_ENDPOINT_ID:-run-local-debug}"
@@ -34,6 +35,9 @@ export RUN_DISPLAY_NAME="${RUN_DISPLAY_NAME:-Local Debug Run}"
export RUN_VERSION="${RUN_VERSION:-0.1.0-local-debug}"
export RUN_REGISTRATION_TOKEN="${RUN_REGISTRATION_TOKEN:-local-debug-registration}"
export RUN_WORKSPACE_ROOT="${RUN_WORKSPACE_ROOT:-$LOCAL_DEBUG_ROOT/run/workspace}"
export RUN_BUILD_BUCKET_ROOT="${RUN_BUILD_BUCKET_ROOT:-$LOCAL_DEBUG_ROOT/run/build-buckets}"
export RUN_BUILD_SOURCE_ROOT="${RUN_BUILD_SOURCE_ROOT:-$RUN_BUILD_BUCKET_ROOT/source/current}"
export RUN_BOOTSTRAP_BIN="${RUN_BOOTSTRAP_BIN:-$RUN_BUILD_BUCKET_ROOT/bootstrap/bin/run}"
export RUN_SPOOL_ROOT="${RUN_SPOOL_ROOT:-$LOCAL_DEBUG_ROOT/run/spool}"
export RUN_MAX_JOBS="${RUN_MAX_JOBS:-1}"
export RUN_HEARTBEAT_INTERVAL_MS="${RUN_HEARTBEAT_INTERVAL_MS:-2000}"
@@ -52,12 +56,120 @@ local_debug_web_url() {
printf 'http://127.0.0.1:%s' "$LOCAL_DEBUG_WEB_PORT"
}
ensure_local_run_repo() {
if [[ ! -f "$RUN_REPO_DIR/go.mod" ]]; then
printf 'run repo not found at %s\n' "$RUN_REPO_DIR" >&2
printf 'clone git@git.npc0.com:admin343/run.git beside this repo or set RUN_REPO_DIR to the independent run checkout\n' >&2
local_debug_plugin_source_dir() {
case "$1" in
game.example)
printf '%s/plugins/examples/dev-game-plugin' "$LOCAL_DEBUG_ROOT_DIR"
;;
game.scum)
printf '%s/plugins/examples/scum-server-plugin' "$LOCAL_DEBUG_ROOT_DIR"
;;
*)
printf 'unknown local-debug plugin id: %s\n' "$1" >&2
return 1
;;
esac
}
local_debug_seed_lifecycle_scope() {
local source_dir="$1"
local scope="$2"
local true_binary="/usr/bin/true"
if [[ ! -x "$true_binary" ]]; then
printf 'required local true executable not found at %s\n' "$true_binary" >&2
return 1
fi
mkdir -p "$scope/actions" "$scope/bin"
local action
for action in install start stop restart status; do
if [[ -f "$source_dir/actions/$action.json" ]]; then
cp "$source_dir/actions/$action.json" "$scope/actions/$action.json"
fi
done
cp "$true_binary" "$scope/bin/install-server"
cp "$true_binary" "$scope/bin/game-server"
chmod +x "$scope/bin/install-server" "$scope/bin/game-server"
}
local_debug_seed_plugin_lifecycle_template() {
local plugin_id="$1"
local profile_key="${2:-run-local}"
local source_dir
source_dir="$(local_debug_plugin_source_dir "$plugin_id")"
local_debug_seed_lifecycle_scope "$source_dir" "$RUN_WORKSPACE_ROOT/plugins/$plugin_id/$profile_key"
}
local_debug_seed_server_lifecycle_workspace() {
local server_id="$1"
local plugin_id="$2"
local profile_key="${3:-run-local}"
local source_dir
source_dir="$(local_debug_plugin_source_dir "$plugin_id")"
local_debug_seed_lifecycle_scope "$source_dir" "$RUN_WORKSPACE_ROOT/$server_id"
local_debug_seed_lifecycle_scope "$source_dir" "$RUN_WORKSPACE_ROOT/instances/$server_id/$profile_key"
}
local_debug_prepare_run_lifecycle_templates() {
mkdir -p "$RUN_WORKSPACE_ROOT"
local_debug_seed_plugin_lifecycle_template game.example run-local
local_debug_seed_plugin_lifecycle_template game.scum run-local
}
local_debug_require_bucket_path() {
local target="$1"
local parent
parent="$(dirname "$target")"
mkdir -p "$parent"
local resolved_parent
resolved_parent="$(cd "$parent" && pwd -P)"
local resolved="$resolved_parent/$(basename "$target")"
case "$resolved" in
"$LOCAL_DEBUG_ROOT"/* | /private/tmp/browser-local-debug-*/* | /tmp/browser-local-debug-*/*)
return 0
;;
esac
printf 'refusing to clear non-local-debug build bucket path: %s\n' "$target" >&2
printf 'set RUN_BUILD_BUCKET_ROOT/RUN_BUILD_SOURCE_ROOT under %s or an approved browser-local-debug temp root\n' "$LOCAL_DEBUG_ROOT" >&2
return 1
}
ensure_local_run_repo() {
if [[ ! -f "$RUN_SOURCE_DIR/go.mod" ]]; then
printf 'run source repo not found at %s\n' "$RUN_SOURCE_DIR" >&2
printf 'clone git@git.npc0.com:admin343/run.git into %s/run or set RUN_SOURCE_DIR/RUN_REPO_DIR to another independent run checkout\n' "$LOCAL_DEBUG_ROOT_DIR" >&2
return 1
fi
}
local_debug_prepare_run_build_source() {
ensure_local_run_repo
local_debug_require_bucket_path "$RUN_BUILD_SOURCE_ROOT"
rm -rf "$RUN_BUILD_SOURCE_ROOT"
mkdir -p "$RUN_BUILD_SOURCE_ROOT"
rsync -a --delete \
--exclude '.git/' \
--exclude '.local-debug/' \
--exclude '.run-workspace/' \
--exclude '.tmp/' \
--exclude 'node_modules/' \
"$RUN_SOURCE_DIR"/ "$RUN_BUILD_SOURCE_ROOT"/
cat >"$RUN_BUILD_SOURCE_ROOT/.local-debug-source.json" <<EOF
{
"sourceDir": "$RUN_SOURCE_DIR",
"buildSourceRoot": "$RUN_BUILD_SOURCE_ROOT",
"createdBy": "scripts/local-debug-env.sh"
}
EOF
}
local_debug_build_bootstrap_run() {
local_debug_prepare_run_build_source
mkdir -p "$(dirname "$RUN_BOOTSTRAP_BIN")"
(
cd "$RUN_BUILD_SOURCE_ROOT"
env GOCACHE="$GOCACHE" go build -trimpath -o "$RUN_BOOTSTRAP_BIN" ./cmd/run
)
chmod +x "$RUN_BOOTSTRAP_BIN"
}
local_debug_forbidden_pattern() {