|
1 | | -# Cloudflare 部署说明(AgentBoot 分发 Worker) |
| 1 | +# Cloudflare Worker 部署 |
2 | 2 |
|
3 | | -本目录的 `worker.js` 承担 `https://boot.ide.pub` 的安装脚本分发: |
| 3 | +`cloudflare/worker.js` 为 `https://boot.ide.pub` 提供: |
4 | 4 |
|
5 | | -``` |
6 | | -curl -fsSL https://boot.ide.pub/install.sh | sh |
7 | | -``` |
8 | | - |
9 | | -Worker 名称固定为 **boot**(对应"域名前缀用 boot"的要求)。`*.workers.dev` |
10 | | -在中国大陆通常被阻断,因此同时把自定义域 `boot.ide.pub` 绑定到该 Worker。 |
| 5 | +- `/`、`/en`:中英文产品页; |
| 6 | +- `/install.sh`、`/install.ps1`:当前 Release 安装器; |
| 7 | +- `/rel/<asset>`:Release 资产代理,支持 `Range` / `If-Range`; |
| 8 | +- `/health`:实际探测当前版本安装器、在线包与 SHA-256 旁车。 |
11 | 9 |
|
12 | | -## 手动部署(Cloudflare 控制台) |
| 10 | +Worker 名称固定为 `boot`,配置见 `wrangler.jsonc`。部署只使用 Wrangler OAuth 或最小权限 API Token,不使用 Cloudflare Global API Key。 |
13 | 11 |
|
14 | | -1. Workers & Pages → Create Worker → 名称填 `boot` → 粘贴 `worker.js` → Deploy。 |
15 | | -2. Worker 详情 → Settings → Domains & Routes → Add → Custom domain → `boot.ide.pub` |
16 | | - (Cloudflare 会自动创建 DNS 记录与路由)。 |
17 | | - |
18 | | -## 脚本部署(Cloudflare API,无需 wrangler) |
19 | | - |
20 | | -先准备环境变量(全局 API Key 在 Cloudflare 控制台 My Profile → API Tokens 页获取): |
| 12 | +## 首次登录 |
21 | 13 |
|
22 | 14 | ```sh |
23 | | -export CF_EMAIL="你的账号邮箱" |
24 | | -export CF_KEY="你的 Global API Key" |
25 | | -export CF_ACCOUNT_ID="账户 ID(域名为 ide.pub 的那个账户)" |
26 | | -export CF_ZONE_ID="ide.pub 这个 zone 的 ID" |
| 15 | +npx wrangler login |
| 16 | +npx wrangler whoami |
27 | 17 | ``` |
28 | 18 |
|
29 | | -然后: |
| 19 | +浏览器授权应至少允许 Workers Scripts 与 Routes 写入,以及 Zone 读取。 |
| 20 | + |
| 21 | +## 发布 |
| 22 | + |
| 23 | +先确保 GitHub Release 与 Pages 已发布当前 `VERSION`,再执行: |
30 | 24 |
|
31 | 25 | ```sh |
32 | | -# 1) 部署/更新 Worker(模块语法上传) |
33 | | -curl -X PUT \ |
34 | | - "https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/workers/scripts/boot" \ |
35 | | - -H "X-Auth-Email: $CF_EMAIL" -H "X-Auth-Key: $CF_KEY" \ |
36 | | - -F 'metadata={"main_module":"worker.js","compatibility_date":"2024-09-23"};type=application/json' \ |
37 | | - -F 'worker.js=@worker.js;type=application/javascript+module' |
38 | | - |
39 | | -# 2) 启用 workers.dev 预览地址(可选) |
40 | | -curl -X POST \ |
41 | | - "https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/workers/scripts/boot/subdomain" \ |
42 | | - -H "X-Auth-Email: $CF_EMAIL" -H "X-Auth-Key: $CF_KEY" \ |
43 | | - -H "Content-Type: application/json" -d '{"enabled":true}' |
44 | | - |
45 | | -# 3) DNS:创建 boot 子域(AAAA 100:: + 代理,把流量交给 Cloudflare) |
46 | | -curl -X POST \ |
47 | | - "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records" \ |
48 | | - -H "X-Auth-Email: $CF_EMAIL" -H "X-Auth-Key: $CF_KEY" \ |
49 | | - -H "Content-Type: application/json" \ |
50 | | - -d '{"type":"AAAA","name":"boot","content":"100::","proxied":true}' |
51 | | - |
52 | | -# 4) 路由:boot.ide.pub/* 全部交给 Worker boot 处理 |
53 | | -curl -X POST \ |
54 | | - "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/workers/routes" \ |
55 | | - -H "X-Auth-Email: $CF_EMAIL" -H "X-Auth-Key: $CF_KEY" \ |
56 | | - -H "Content-Type: application/json" \ |
57 | | - -d '{"pattern":"boot.ide.pub/*","script":"boot"}' |
| 26 | +cd cloudflare |
| 27 | +sh deploy.sh |
58 | 28 | ``` |
59 | 29 |
|
60 | | -## 验证 |
| 30 | +`deploy.sh` 会执行: |
61 | 31 |
|
62 | 32 | ```sh |
63 | | -curl -fsSL https://boot.ide.pub/health |
64 | | -curl -fsSL https://boot.ide.pub/install.sh | head -n 5 |
| 33 | +npx wrangler deploy --config wrangler.jsonc |
| 34 | +python3 ../scripts/verify-live-release.py |
65 | 35 | ``` |
66 | 36 |
|
67 | | -## 版本升级 |
| 37 | +只有以下条件全部满足才算发布成功: |
68 | 38 |
|
69 | | -`worker.js` 顶部的 `REPO` / `TAG` 与各安装脚本中的 `TAG` 保持一致;发新版本时同步修改。 |
| 39 | +- `/health` 返回当前 tag 且 `ok=true`; |
| 40 | +- Worker 与 Pages 的 `install.sh` / `install.ps1` 都指向当前 tag; |
| 41 | +- 两个来源的在线 tar/zip 与各自 `.sha256` 一致; |
| 42 | +- Worker `/rel/` 正确返回 `206 Partial Content`。 |
70 | 43 |
|
71 | | -当前推荐使用已登录的 Wrangler OAuth 会话部署,配置位于 `wrangler.jsonc`: |
| 44 | +## 回滚 |
72 | 45 |
|
73 | 46 | ```sh |
74 | | -cd cloudflare |
75 | | -npx wrangler deploy --config wrangler.jsonc |
| 47 | +npx wrangler deployments list --name boot |
| 48 | +npx wrangler rollback --name boot |
76 | 49 | python3 ../scripts/verify-live-release.py |
77 | 50 | ``` |
78 | 51 |
|
79 | | -`verify-live-release.py` 会同时检查 `boot.ide.pub` 与 GitHub Pages:版本、安装器、在线 tar/zip 及 SHA-256 必须一致。 |
| 52 | +回滚 Worker 后,验证器会按仓库当前 `VERSION` 检查。如果同时回滚 GitHub Release,需要先切换到对应源码/tag再运行验证。 |
0 commit comments