Files
browser/scripts/local-debug-env.sh
T
2026-07-20 16:42:33 +08:00

66 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Shared configuration for the first-party local debug workspace.
set -euo pipefail
LOCAL_DEBUG_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOCAL_DEBUG_ROOT_DIR="$(cd "$LOCAL_DEBUG_SCRIPT_DIR/.." && pwd)"
export LOCAL_DEBUG_ROOT="${LOCAL_DEBUG_ROOT:-$LOCAL_DEBUG_ROOT_DIR/.local-debug}"
export LOCAL_DEBUG_LOG_DIR="${LOCAL_DEBUG_LOG_DIR:-$LOCAL_DEBUG_ROOT/logs}"
export LOCAL_DEBUG_PID_DIR="${LOCAL_DEBUG_PID_DIR:-$LOCAL_DEBUG_ROOT/pids}"
export GOCACHE="${GOCACHE:-$LOCAL_DEBUG_ROOT/go-build-cache}"
export LOCAL_DEBUG_PLATFORM_PORT="${LOCAL_DEBUG_PLATFORM_PORT:-18080}"
export LOCAL_DEBUG_WEB_PORT="${LOCAL_DEBUG_WEB_PORT:-5173}"
export PLATFORM_ADDR="${PLATFORM_ADDR:-127.0.0.1:$LOCAL_DEBUG_PLATFORM_PORT}"
export PLATFORM_STORAGE_BACKEND="${PLATFORM_STORAGE_BACKEND:-file}"
export PLATFORM_DATA_DIR="${PLATFORM_DATA_DIR:-$LOCAL_DEBUG_ROOT/platform}"
export PLATFORM_METADATA_PATH="${PLATFORM_METADATA_PATH:-$PLATFORM_DATA_DIR/metadata.json}"
export PLATFORM_LOG_BODY_BACKEND="${PLATFORM_LOG_BODY_BACKEND:-file}"
export PLATFORM_LOG_DIR="${PLATFORM_LOG_DIR:-$PLATFORM_DATA_DIR/logs}"
export PLATFORM_ARTIFACT_DIR="${PLATFORM_ARTIFACT_DIR:-$PLATFORM_DATA_DIR/artifacts}"
export PLATFORM_BOOTSTRAP_ADMIN_EMAIL="${PLATFORM_BOOTSTRAP_ADMIN_EMAIL:-operator.local@example.test}"
export PLATFORM_BOOTSTRAP_ADMIN_PASSWORD="${PLATFORM_BOOTSTRAP_ADMIN_PASSWORD:-operator-local}"
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_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}"
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_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}"
export RUN_POLL_INTERVAL_MS="${RUN_POLL_INTERVAL_MS:-1000}"
export RUN_RETRY_BACKOFF_MS="${RUN_RETRY_BACKOFF_MS:-500}"
export PLATFORM_API_PROXY="${PLATFORM_API_PROXY:-http://127.0.0.1:$LOCAL_DEBUG_PLATFORM_PORT}"
export VITE_PLATFORM_API_BASE_URL="${VITE_PLATFORM_API_BASE_URL:-/api/v1}"
export VITE_ENABLE_LOCAL_AUTH_FALLBACK="${VITE_ENABLE_LOCAL_AUTH_FALLBACK:-false}"
local_debug_platform_url() {
printf 'http://127.0.0.1:%s' "$LOCAL_DEBUG_PLATFORM_PORT"
}
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
return 1
fi
}
local_debug_forbidden_pattern() {
printf '%s' '(/Users/|/private/|unix://|tcp://|Bearer |sk-|password=|apiKeyRef|rawApiKey|sessionToken|run session token|direct run URL|plugin-owned transport)'
}