Files
Leo 3fa5cda796 chore: 安裝契約 — scripts/install.sh + .dev.vars 整合測試慣例
KBDB_BASE_URL 由安裝時的 AI 自動填(查 CF subdomain 拼基本盤 URL),不寫死 toml、不叫人填。
- scripts/install.sh:whoami → 查 subdomain → wrangler secret put → wrangler deploy
- .dev.vars.example:整合測試本地基本盤慣例(.dev.vars 已 gitignore)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 21:19:44 +08:00

51 lines
2.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# KBDB-graph 插件安裝器 — AI 照著跑,用戶零填寫。
#
# 設計(leo 2026-06-14,比照 arcrun self-hosted-init):
# KBDB_BASE_URL 是插件對外唯一通道,因部署而異(每個 self-hosted 用戶 subdomain 不同),
# 所以【不寫死 toml、不叫人填】。URL 是確定性的:能 deploy 就能查 subdomain(同一套 CF 憑證)。
#
# 流程:whoami → 查 subdomain → 拼基本盤 URL → wrangler secret put → wrangler deploy。
# - 基本盤一律連 workers.dev 預設域名:https://arcrun-kbdb.<subdomain>.workers.dev
# - 部署繞開 GitHubwrangler 直推),不開 Actions(避免再被 flag)。
#
# 用法:bash scripts/install.sh
# 選用環境變數:
# KBDB_BASE_URL — 直接指定基本盤網址(跳過自動推算,例如自訂域名)
# BASE_WORKER — 基本盤 worker 名(預設 arcrun-kbdb
set -euo pipefail
BASE_WORKER="${BASE_WORKER:-arcrun-kbdb}"
command -v wrangler >/dev/null 2>&1 || { echo "✗ 需先安裝 wranglerCloudflare CLI"; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "✗ 需先安裝 jq"; exit 1; }
# 1. 確認已登入 wrangler
echo "▸ 確認 Cloudflare 登入..."
wrangler whoami >/dev/null 2>&1 || { echo "✗ 未登入,請先 'wrangler login'"; exit 1; }
# 2. 算出基本盤 URL(除非已由環境變數指定)
if [ -z "${KBDB_BASE_URL:-}" ]; then
echo "▸ 查 workers.dev subdomain..."
# wrangler 內部 API 可查 subdomain;用 `wrangler subdomain` 或 CF API 皆可。
# 這裡用最穩的:部署後讀回 URL。先嘗試從 whoami/CF API 取 subdomain。
SUBDOMAIN="$(wrangler subdomain 2>/dev/null | grep -oE '[a-z0-9-]+\.workers\.dev' | sed 's/\.workers\.dev//' | head -1 || true)"
if [ -z "$SUBDOMAIN" ]; then
echo "✗ 無法自動取得 subdomain。請改用:KBDB_BASE_URL=https://${BASE_WORKER}.<你的subdomain>.workers.dev bash scripts/install.sh"
exit 1
fi
KBDB_BASE_URL="https://${BASE_WORKER}.${SUBDOMAIN}.workers.dev"
fi
echo "▸ 基本盤 URL = ${KBDB_BASE_URL}"
# 3. 注入為 secret(不寫進 git;toml 只留空占位)
echo "▸ 設定 KBDB_BASE_URL secret..."
printf '%s' "$KBDB_BASE_URL" | wrangler secret put KBDB_BASE_URL
# 4. 部署插件(wrangler 直推,不開 Actions
echo "▸ 部署 kbdb-graph-plugin..."
wrangler deploy
echo "✓ 完成。/health 應回 base_url_set:true"