diff --git a/.github/workflows/desktop-package.yml b/.github/workflows/desktop-package.yml index 75c04247d1..4a576f1379 100644 --- a/.github/workflows/desktop-package.yml +++ b/.github/workflows/desktop-package.yml @@ -1170,12 +1170,11 @@ jobs: echo "Beta channel manifest did not converge to ${CANDIDATE_VERSION}." >&2 exit 1 - # Nudge the openbitfun.com mirror to sync now instead of on its next - # 10-minute cron tick. Until the mirror has these bytes, CN clients have + # Nudge the configured download mirror to sync now instead of on its next + # 10-minute cron tick. Until the mirror has these bytes, clients have # only the GitHub origin to fall back to. Best effort: the cron run is # still the source of truth, so a failed or unconfigured ping never fails # the release. Receiver: scripts/openbitfun-release-sync.sh. - # Host restore: deploy/openbitfun-host/README.md. - name: Request openbitfun mirror sync if: github.repository == 'GCWing/OpenBitFun' continue-on-error: true diff --git a/deploy/README.md b/deploy/README.md index 192b707bd7..e2ac0f69a5 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,14 +1,26 @@ -# Deploy runbooks +# Deployment references -Production origin restore and product deploys for the current OpenBitFun host -(`ssh lwb`). +Community self-hosting references for OpenBitFun. The official hosted services +are operated separately; their configuration and access details are not +published in this repository. + +Each guide uses placeholder hosts, domains, and paths. Replace them with your +own environment before running commands. | Directory | Use | | --- | --- | -| [openbitfun-host/](openbitfun-host/README.md) | New-host restore: website, release mirror, Relay Nginx, New API boundary | -| [miniapp-market/](miniapp-market/README.md) | MiniApp market only | -| [skin-market/](skin-market/README.md) | Skin market only | +| [market-data-migration/](market-data-migration/README.md) | Legacy market data migration tooling | +| [miniapp-market/](miniapp-market/README.md) | MiniApp market | +| [skin-market/](skin-market/README.md) | Skin market | +| [relay-v1/](relay-v1/README.md) | Versioned Relay deployment | | [outbound-mail/](outbound-mail/README.md) | Send-only Postfix/OpenDKIM: auth integration, DNS, maintenance and rollback | +| [model-router/](model-router/README.md) | Client-side router launcher and system prompt | + +Component source guides: + +- Relay: [`src/apps/relay-server/README.md`](../src/apps/relay-server/README.md) +- MiniApp market server: [`src/apps/miniapp-market-server/README.md`](../src/apps/miniapp-market-server/README.md) +- Skin market service: [`src/crates/services/skin-market-service/README.md`](../src/crates/services/skin-market-service/README.md) -An Agent that is asked to move or rebuild the server starts at -`openbitfun-host/AGENTS.md`. +For deployment changes, read the relevant component guide and keep every +example hostname, path, and credential as a placeholder. diff --git a/deploy/market-data-migration/AGENTS.md b/deploy/market-data-migration/AGENTS.md new file mode 100644 index 0000000000..1ab1a7c5f1 --- /dev/null +++ b/deploy/market-data-migration/AGENTS.md @@ -0,0 +1,12 @@ +# Legacy market data migration + +This directory holds community self-hosting tooling for migrating pre-rename +market data. Read [README.md](README.md) before changing the migration script. + +- Never commit real hostnames, SSH aliases, credentials, tokens, certificates, + production data, or other operational secrets. +- Examples use placeholder domains and paths. Keep them generic. +- Back up data with the SQLite backup API and verify integrity before running a + migration. Do not use destructive Git commands to force a deployment. +- MiniApp and Skin markets have their own runbooks. Do not mix their checkouts, + secrets, or Compose projects. diff --git a/deploy/market-data-migration/README.md b/deploy/market-data-migration/README.md new file mode 100644 index 0000000000..eef7cdbf43 --- /dev/null +++ b/deploy/market-data-migration/README.md @@ -0,0 +1,31 @@ +# Legacy market data migration + +This directory contains one-time migration tooling for pre-rename MiniApp and +Skin market data. It does not describe the official hosted service, and no +official hostnames, SSH aliases, credentials, or production data belong here. + +## What is here + +| Path | Purpose | +| --- | --- | +| `migrate-market-data-v1.py` | One-time data migration for pre-rename market data | +| `test_migrate_market_data_v1.py` | Tests for the migration tool | + +[`migrate-market-data-v1.py`](migrate-market-data-v1.py) refuses to run against +the live database when `--live-database` points at the same path. Work on a +copy, keep the original, and verify SQLite `integrity_check` plus package +checksums before switching traffic. + +Run the tests before modifying it: + +```bash +python3 -m unittest test_migrate_market_data_v1.py +``` + +## Related guides + +- MiniApp market: [`../miniapp-market/README.md`](../miniapp-market/README.md) +- Skin market: [`../skin-market/README.md`](../skin-market/README.md) +- Relay: [`../relay-v1/README.md`](../relay-v1/README.md) and + [`../../src/apps/relay-server/README.md`](../../src/apps/relay-server/README.md) +- Outbound mail: [`../outbound-mail/README.md`](../outbound-mail/README.md) diff --git a/deploy/openbitfun-host/migrate-market-data-v1.py b/deploy/market-data-migration/migrate-market-data-v1.py similarity index 100% rename from deploy/openbitfun-host/migrate-market-data-v1.py rename to deploy/market-data-migration/migrate-market-data-v1.py diff --git a/deploy/openbitfun-host/test_migrate_market_data_v1.py b/deploy/market-data-migration/test_migrate_market_data_v1.py similarity index 100% rename from deploy/openbitfun-host/test_migrate_market_data_v1.py rename to deploy/market-data-migration/test_migrate_market_data_v1.py diff --git a/deploy/miniapp-market/README.md b/deploy/miniapp-market/README.md index 4c8ea7b45d..d6bbbb513b 100644 --- a/deploy/miniapp-market/README.md +++ b/deploy/miniapp-market/README.md @@ -1,7 +1,17 @@ -# OpenBitFun MiniApp Market 生产部署手册 +# OpenBitFun MiniApp Market 自建部署手册 -这份 Runbook 用于更新 `ssh lwb` 上的 MiniApp 市场网页和后端。它同时面向人工 -操作和 AI Agent,命令默认从 OpenBitFun 仓库根目录执行。 +这份 Runbook 用于在自建 Linux 主机上部署和更新 MiniApp 市场网页与后端。它同时 +面向人工操作和 AI Agent,命令默认从 OpenBitFun 仓库根目录执行。 + +> 本文是社区自部署模板。`$DEPLOY_HOST`、`market.example.com`、`auth.example.com` +> 以及 `/srv/openbitfun-miniapp-market`、`/etc/openbitfun-miniapp-market` 等路径都是 +> 示例,请替换为你自己的 SSH 主机、域名和目录。开始前先在当前 shell 设置: +> +> ```bash +> DEPLOY_HOST=root@your-server +> ``` +> +> 官方托管服务的配置不在本仓库中。 相关源码说明: @@ -16,7 +26,7 @@ MiniApp 市场网页源码在 `src/miniapp-market-web/`,后端入口在 `src/crates/services/miniapp-market-service/`。 网页和后端由 `src/apps/miniapp-market-server/Dockerfile` 打进同一个镜像。 -因此只改网页、只改后端、或前后端一起改,生产发布动作相同: +因此只改网页、只改后端、或前后端一起改,部署动作相同: 1. 本地检查并提交一个明确 Git commit; 2. 验证或创建部署前备份; @@ -33,27 +43,22 @@ Skin 市场复用本服务的 GitHub OAuth、桌面 token 和 Web 会话别名 验证 Skin 的“我的投稿”和“审核”接口;Skin 容器只能通过它自己的部署手册和 专用 checkout 更新,不能从 MiniApp Compose 项目重建。 -## 生产边界 - -本目录只能部署 MiniApp 市场。不得修改、清理或重启现有 Relay、New API、官网 -及其 Nginx vhost/container。 +## 部署边界 -服务器上另外两个仓库有需要保留的状态: +本目录只能部署 MiniApp 市场。如果同一主机上还运行 Relay、官网或其他服务,不要 +修改、清理或重启它们的 Nginx vhost/container。 -- `/root/repos/OpenBitFun` 可能包含 Relay 的未跟踪 `.env`; -- `/root/repos/OpenBitFun-Website` 可能是 dirty worktree。 +市场使用独立 checkout `/srv/openbitfun-miniapp-market/app`。任何部署都不得在其他 +服务的 checkout 中运行 `git clean`、`git reset --hard`、强制 checkout 或部署脚本。 -市场使用独立 checkout `/srv/openbitfun-miniapp-market/app`。任何部署都不得在上述 -两个现有仓库运行 `git clean`、`git reset --hard`、强制 checkout 或部署脚本。 - -## 生产事实 +## 部署事实 | 项目 | 值 | | --- | --- | -| SSH | `ssh lwb`(当前配置为生产 root 登录) | -| 公网地址 | `https://market.openbitfun.com/miniapp/` | -| API | `https://market.openbitfun.com/miniapp/api/v1` | -| OAuth callback | `https://auth.openbitfun.com/api/v1/auth/github/callback` | +| SSH | `ssh "$DEPLOY_HOST"`(设为你的部署主机) | +| 公网地址 | `https://market.example.com/miniapp/` | +| API | `https://market.example.com/miniapp/api/v1` | +| OAuth callback | `https://auth.example.com/api/v1/auth/github/callback` | | 专用 checkout | `/srv/openbitfun-miniapp-market/app` | | SQLite | `/srv/openbitfun-miniapp-market/data/market.sqlite` | | packages/screenshots | `/srv/openbitfun-miniapp-market/artifacts` | @@ -61,7 +66,7 @@ Skin 市场复用本服务的 GitHub OAuth、桌面 token 和 Web 会话别名 | secrets | `/etc/openbitfun-miniapp-market/market.env`,`root:root`、`0600` | | 容器 | `openbitfun-miniapp-market` | | 监听 | 仅宿主 `127.0.0.1:9710` | -| Nginx vhost | `/etc/nginx/sites-available/market.openbitfun.com.conf` | +| Nginx vhost | `/etc/nginx/sites-available/market.example.com.conf` | | Nginx 未知 Host 兜底 | `/etc/nginx/sites-available/00-default-server.conf` | | 部署 ref | `refs/heads/market-deploy` | @@ -78,11 +83,11 @@ capabilities 方式运行。数据和 artifacts 通过独立宿主目录持久 4. 不读取、复制、输出 `/etc/openbitfun-miniapp-market/market.env` 内容。 5. 不记录 token、Cookie、请求 body、包内容或个人 IP。 6. 发布前记录旧 commit;数据库相关变更先验证备份。 -7. 不修改 Relay、New API、官网或它们的 Nginx/container。 +7. 不修改同一主机上的其他服务或它们的 Nginx/container。 8. 每个外部写操作后做只读验证。任何验证失败立即停止,不连续尝试破坏性修复。 9. 只有容器 healthy、镜像 revision 等于目标 commit、公网健康检查通过,才可以 报告“部署成功”。 -10. schema 变更回滚、生产数据恢复或 OAuth 配置不明确时,停止并请求人工确认, +10. schema 变更回滚、数据恢复或 OAuth 配置不明确时,停止并请求人工确认, 不猜测。 下面步骤中的 `DEPLOY_COMMIT`、`PREVIOUS_COMMIT` 等变量保存在本地 shell。应在 @@ -129,12 +134,12 @@ git show --stat --oneline "$DEPLOY_COMMIT" git status --short ``` -如果最后一条仍有属于本任务的未提交改动,停止;它们不会进入生产镜像。 +如果最后一条仍有属于本任务的未提交改动,停止;它们不会进入部署镜像。 -## 2. 只读检查当前生产状态 +## 2. 只读检查当前部署状态 ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu git -C /srv/openbitfun-miniapp-market/app status --short git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD docker inspect --format "{{.Config.Image}} {{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{end}}" openbitfun-miniapp-market @@ -155,7 +160,7 @@ stat -c "%U:%G %a %n" /etc/openbitfun-miniapp-market/market.env' ```bash PREVIOUS_COMMIT="$( - ssh lwb 'git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD' + ssh "$DEPLOY_HOST" 'git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD' )" ``` @@ -165,7 +170,7 @@ PREVIOUS_COMMIT="$( migration、包存储或审核流程变更必须在发布前拥有当天的一致性备份。 ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu systemctl is-enabled openbitfun-miniapp-market-backup.timer systemctl is-active openbitfun-miniapp-market-backup.timer today="$(date -u +%F)" @@ -184,7 +189,7 @@ artifacts 快照。它会拒绝覆盖同一天已有备份。 涉及 migration 或高风险存储改动时,再对最新备份做一次恢复演练: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu latest="$(find /srv/openbitfun-miniapp-market/backups/daily \ -mindepth 1 -maxdepth 1 -type d -print | sort | tail -n 1)" test -n "$latest" @@ -195,28 +200,28 @@ test -n "$latest" ## 4. 把精确 commit 送到专用 checkout -生产 ref 只用于这个市场 checkout。使用 `--force-with-lease` 防止覆盖未知的并发 +部署 ref 只用于这个市场 checkout。使用 `--force-with-lease` 防止覆盖未知的并发 发布,不使用无条件 `--force`。 ```bash REMOTE_REF_COMMIT="$( - ssh lwb 'git -C /srv/openbitfun-miniapp-market/app \ + ssh "$DEPLOY_HOST" 'git -C /srv/openbitfun-miniapp-market/app \ rev-parse refs/heads/market-deploy' )" git push \ --force-with-lease="refs/heads/market-deploy:${REMOTE_REF_COMMIT}" \ - ssh://lwb/srv/openbitfun-miniapp-market/app \ + ssh://$DEPLOY_HOST/srv/openbitfun-miniapp-market/app \ "${DEPLOY_COMMIT}:refs/heads/market-deploy" ``` -如果 lease 失败,表示另一个发布修改了服务器 ref。停止并重新检查生产状态,不要 +如果 lease 失败,表示另一个发布修改了服务器 ref。停止并重新检查部署状态,不要 改成无条件 force。 确认服务器专用 checkout 干净后切到目标 commit: ```bash -ssh lwb "set -eu +ssh "$DEPLOY_HOST" "set -eu test -z \"\$(git -C /srv/openbitfun-miniapp-market/app status --porcelain)\" git -C /srv/openbitfun-miniapp-market/app checkout --detach '$DEPLOY_COMMIT' test \"\$(git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD)\" = '$DEPLOY_COMMIT'" @@ -229,7 +234,7 @@ test \"\$(git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD)\" = '$DEPLOY 构建期间旧容器继续服务。只有镜像构建成功后才 recreate: ```bash -ssh lwb "set -eu +ssh "$DEPLOY_HOST" "set -eu cd /srv/openbitfun-miniapp-market/app test \"\$(git rev-parse HEAD)\" = '$DEPLOY_COMMIT' export MARKET_GIT_COMMIT='$DEPLOY_COMMIT' @@ -246,7 +251,7 @@ docker compose -f deploy/miniapp-market/docker-compose.yml \ 等待 Compose healthcheck 变成 `healthy`: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu for attempt in $(seq 1 30); do status="$( docker inspect --format \ @@ -264,7 +269,7 @@ exit 1' ```bash DEPLOYED_COMMIT="$( - ssh lwb 'docker inspect --format \ + ssh "$DEPLOY_HOST" 'docker inspect --format \ "{{index .Config.Labels \"org.opencontainers.image.revision\"}}" \ openbitfun-miniapp-market' )" @@ -274,17 +279,17 @@ test "$DEPLOYED_COMMIT" = "$DEPLOY_COMMIT" 检查 origin 和公网: ```bash -ssh lwb 'curl -fsS http://127.0.0.1:9710/miniapp/api/v1/health' -curl -fsS https://market.openbitfun.com/miniapp/api/v1/health -curl -fsS https://market.openbitfun.com/miniapp/api/v1/config -curl -fsS https://market.openbitfun.com/miniapp/ >/dev/null +ssh "$DEPLOY_HOST" 'curl -fsS http://127.0.0.1:9710/miniapp/api/v1/health' +curl -fsS https://market.example.com/miniapp/api/v1/health +curl -fsS https://market.example.com/miniapp/api/v1/config +curl -fsS https://market.example.com/miniapp/ >/dev/null ``` -生产 `/config` 应返回 `"webSubmissionsEnabled":false`。此开关关闭时,Web +`/config` 应返回 `"webSubmissionsEnabled":false`。此开关关闭时,Web 投稿写请求由后端拒绝,网页仅保留“我的投稿”历史;OpenBitFun Desktop 的 Bearer 投稿和 Web 管理员审核继续可用。未来重新开放网页投稿时,必须先完成对应安全 回归,再显式修改 root-only `market.env` 并仅 recreate 市场容器。 -环境变量缺失时后端也默认关闭,但生产 `market.env` 应显式保留 +环境变量缺失时后端也默认关闭,但 `market.env` 应显式保留 `MARKET_WEB_SUBMISSIONS_ENABLED=false`,避免后续运维人员误判当前策略。 再用浏览器人工检查: @@ -295,12 +300,12 @@ curl -fsS https://market.openbitfun.com/miniapp/ >/dev/null `/miniapp/submit` 提示改用 OpenBitFun Desktop,“我的投稿”仍可读取; - OAuth 已配置时,GitHub 登录 callback 正常; - 与本次改动有关的浏览、下载、投稿、审核、安装或更新流程正常; -- Relay、New API 和官网仍可用,且它们的容器/vhost 没被重启或改写。 +- 同一主机上的其他服务仍可用,且它们的容器/vhost 没被重启或改写。 -查看最近日志时只读有限行数,不把完整生产日志复制到公开位置: +查看最近日志时只读有限行数,不把完整运行日志复制到公开位置: ```bash -ssh lwb 'docker logs --since 10m --tail 200 openbitfun-miniapp-market' +ssh "$DEPLOY_HOST" 'docker logs --since 10m --tail 200 openbitfun-miniapp-market' ``` ## 7. 只有 Nginx 文件变化时才更新 Nginx @@ -309,12 +314,12 @@ ssh lwb 'docker logs --since 10m --tail 200 openbitfun-miniapp-market' - `deploy/miniapp-market/nginx-default-server.conf` - `deploy/miniapp-market/nginx-log-format.conf` -- `deploy/miniapp-market/nginx-market.openbitfun.com.conf` +- `deploy/miniapp-market/nginx-market.conf`(模板文件名,安装时改成你的域名) 确有修改时才安装市场专用文件: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu install -m 0644 \ /srv/openbitfun-miniapp-market/app/deploy/miniapp-market/nginx-default-server.conf \ /etc/nginx/sites-available/00-default-server.conf @@ -325,8 +330,8 @@ install -m 0644 \ /srv/openbitfun-miniapp-market/app/deploy/miniapp-market/nginx-log-format.conf \ /etc/nginx/conf.d/miniapp-market-log-format.conf install -m 0644 \ - /srv/openbitfun-miniapp-market/app/deploy/miniapp-market/nginx-market.openbitfun.com.conf \ - /etc/nginx/sites-available/market.openbitfun.com.conf + /srv/openbitfun-miniapp-market/app/deploy/miniapp-market/nginx-market.conf \ + /etc/nginx/sites-available/market.example.com.conf nginx -t systemctl reload nginx' ``` @@ -335,22 +340,21 @@ systemctl reload nginx' vhost 的上传上限是 25 MiB;访问日志刻意不记录 IP、query、Cookie、body 或 Authorization。 -`nginx-default-server.conf` 是服务器级安全兜底,不代理任何产品。当前 -`openbitfun.com` 的 DNS/WAF 会让未显式配置的子域名也到达该源站;这个 -`default_server` 必须返回 404,避免未知 Host 因 Nginx 加载顺序落到 New API、 -Relay、官网或市场。新增 vhost 后至少验证: +`nginx-default-server.conf` 是服务器级安全兜底,不代理任何产品。如果你的 DNS/WAF +会让未显式配置的子域名也到达源站,这个 `default_server` 必须返回 404,避免未知 +Host 因 Nginx 加载顺序落到同一主机上的其他服务或市场。新增 vhost 后至少验证: ```bash curl -sS -o /dev/null -w "%{http_code}\n" \ - -H "Host: unconfigured.openbitfun.com" http://127.0.0.1/ + -H "Host: unconfigured.example.com" http://127.0.0.1/ curl -sS -o /dev/null -w "%{http_code} %{redirect_url}\n" \ - -H "Host: market.openbitfun.com" http://127.0.0.1/ + -H "Host: market.example.com" http://127.0.0.1/ curl -sS -o /dev/null -w "%{http_code}\n" \ - https://unconfigured.openbitfun.com/ + https://unconfigured.example.com/ ``` 预期依次为 `404`、跳转到 -`https://market.openbitfun.com/miniapp/`、`404`。不要用真实但尚未发布的 +`https://market.example.com/miniapp/`、`404`。不要用真实但尚未发布的 产品域名做探针,避免以后与新 vhost 冲突。 ## 8. 回滚 @@ -358,7 +362,7 @@ curl -sS -o /dev/null -w "%{http_code}\n" \ 纯前端或兼容后端故障可以回滚到部署前保存的 `$PREVIOUS_COMMIT`: ```bash -ssh lwb "set -eu +ssh "$DEPLOY_HOST" "set -eu test -n '$PREVIOUS_COMMIT' test -z \"\$(git -C /srv/openbitfun-miniapp-market/app status --porcelain)\" git -C /srv/openbitfun-miniapp-market/app checkout --detach '$PREVIOUS_COMMIT' @@ -377,12 +381,12 @@ docker compose -f deploy/miniapp-market/docker-compose.yml \ ```bash ROLLBACK_REF_COMMIT="$( - ssh lwb 'git -C /srv/openbitfun-miniapp-market/app \ + ssh "$DEPLOY_HOST" 'git -C /srv/openbitfun-miniapp-market/app \ rev-parse refs/heads/market-deploy' )" git push \ --force-with-lease="refs/heads/market-deploy:${ROLLBACK_REF_COMMIT}" \ - ssh://lwb/srv/openbitfun-miniapp-market/app \ + ssh://$DEPLOY_HOST/srv/openbitfun-miniapp-market/app \ "${PREVIOUS_COMMIT}:refs/heads/market-deploy" ``` @@ -391,23 +395,23 @@ git push \ 制定数据迁移/恢复方案。Nginx 有改动时也要从旧 commit 恢复市场专用配置, `nginx -t` 后再 reload。 -## 修改生产配置 +## 修改运行配置 实际配置只在 `/etc/openbitfun-miniapp-market/market.env`。只能在服务器本地用受控 编辑器修改,不能 `cat`、下载或提交: ```bash -ssh -t lwb 'umask 077; vi /etc/openbitfun-miniapp-market/market.env' -ssh lwb 'stat -c "%U:%G %a %n" /etc/openbitfun-miniapp-market/market.env' +ssh -t "$DEPLOY_HOST" 'umask 077; vi /etc/openbitfun-miniapp-market/market.env' +ssh "$DEPLOY_HOST" 'stat -c "%U:%G %a %n" /etc/openbitfun-miniapp-market/market.env' ``` 配置变化后,用当前 checkout commit recreate 容器: ```bash CURRENT_COMMIT="$( - ssh lwb 'git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD' + ssh "$DEPLOY_HOST" 'git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD' )" -ssh lwb "set -eu +ssh "$DEPLOY_HOST" "set -eu cd /srv/openbitfun-miniapp-market/app export MARKET_GIT_COMMIT='$CURRENT_COMMIT' docker compose -f deploy/miniapp-market/docker-compose.yml \ @@ -418,7 +422,17 @@ docker compose -f deploy/miniapp-market/docker-compose.yml \ GitHub OAuth App callback 必须精确为: -`https://auth.openbitfun.com/api/v1/auth/github/callback` +`https://auth.example.com/api/v1/auth/github/callback` + +统一登录部署需在 `market.env` 中设置同一地址: + +```bash +MARKET_GITHUB_CALLBACK_URL=https://auth.example.com/api/v1/auth/github/callback +``` + +桌面登录页和完成页会使用该回调 URL 的 origin;未设置时使用 +`MARKET_PUBLIC_BASE_URL` 的 origin。GitHub OAuth App 的 callback 必须与 +`MARKET_GITHUB_CALLBACK_URL` 完全一致。 创建或复用 OAuth App 时的实操要点: @@ -433,11 +447,11 @@ GitHub OAuth App callback 必须精确为: 配置生效的只读验证: ```bash -curl -fsS https://market.openbitfun.com/miniapp/api/v1/health +curl -fsS https://market.example.com/miniapp/api/v1/health # 预期包含 "githubAuthConfigured":true curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" \ - https://market.openbitfun.com/miniapp/api/v1/auth/github/start + https://market.example.com/miniapp/api/v1/auth/github/start # 预期 307,跳转 github.com/login/oauth/authorize, # 且 client_id、redirect_uri 与注册的 App 一致 ``` @@ -450,7 +464,7 @@ curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" \ ### 初次开放市场 初次开放市场时保持 `MARKET_PUBLIC_BROWSE=false`,先由管理员 GitHub ID -`24753352` 登录、上传并批准样例,再用全新桌面客户端验证安装和手动更新。 +`` 登录、上传并批准样例,再用全新桌面客户端验证安装和手动更新。 全部通过后才可改为 `true` 并 recreate。审批完成不代表用户自动授予 MiniApp 权限。 @@ -465,9 +479,9 @@ curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" \ 同时安装 `nginx-default-server.conf`,让所有未知 Host fail closed; 4. 安装 `backup.sh`、`restore-drill.sh`、systemd service/timer; 5. 运行一次备份和恢复演练; -6. 以 `MARKET_PUBLIC_BROWSE=false` 完成生产验收后再开放。 +6. 以 `MARKET_PUBLIC_BROWSE=false` 完成部署验收后再开放。 -已有生产安装不要重复初始化。更改备份脚本或 systemd 文件时,逐个安装对应文件, +已有安装不要重复初始化。更改备份脚本或 systemd 文件时,逐个安装对应文件, 运行 `systemctl daemon-reload`,手工验证一次,再确认 timer 是 enabled/active。 每日备份保留 14 份,周备份保留 8 份。备份脚本的删除范围已经限制在市场专用 @@ -475,16 +489,16 @@ backup root;不要放宽该保护。 ## 统一 GitHub 登录入口 -`https://auth.openbitfun.com` 是市场与远控共用的登录入口,桌面授权完成页为 +`https://auth.example.com` 是市场与远控共用的登录入口,桌面授权完成页为 `/complete`,身份 API 为 `/api/v1`。它复用本服务和数据库;不新增账号库。 -安装同目录 `nginx-auth.openbitfun.com.conf` 前,先确认该域名的 DNS、TLS/WAF -已覆盖,并配置当前可信 WAF 源网段。该配置只开放登录、身份、token 生命周期和 -页面静态资源,不代理市场写接口。 +安装同目录 `nginx-auth.conf`(模板文件名,安装时改成你的域名)前, +先确认该域名的 DNS、TLS/WAF 已覆盖,并配置你自己的可信 WAF 源网段。该配置只开放 +登录、身份、token 生命周期和页面静态资源,不代理市场写接口。 GitHub OAuth App 的注册 callback 为 -`https://auth.openbitfun.com/api/v1/auth/github/callback`。统一入口将 code/state 原样转交市场的兼容完成端点;只有市场 +`https://auth.example.com/api/v1/auth/github/callback`。统一入口将 code/state 原样转交市场的兼容完成端点;只有市场 host 写入两组 host-only Cookie(`/miniapp` 与 `/skin`),然后桌面授权跳转到 -独立完成页;不要通过 `Domain=.openbitfun.com` 扩大 Cookie 信任范围。桌面 +独立完成页;不要通过 `Domain=.example.com` 扩大 Cookie 信任范围。桌面 poll token 仍受一次性 transaction secret 约束。旧市场 API 与旧完成页路径保留, 已有安装无需手动迁移。 @@ -520,7 +534,7 @@ migration 0002 保留原用户 ID 和外键,但旧 binary 不认识邮箱用 ### 登录语言与验证码邮件 -各端打开 `https://auth.openbitfun.com/sign-in` 时通过 `locale` 查询参数传递当前界面语言。 +各端打开 `https://auth.example.com/sign-in` 时通过 `locale` 查询参数传递当前界面语言。 认证页优先使用该参数,其次使用已保存的语言和浏览器语言;别名遵循共享 i18n contract。 发送验证码请求可携带 `locale`(`en-US`、`zh-CN` 或 `zh-TW`),邮件主题、HTML 和纯文本使用同一语言。 旧客户端省略该字段或传入未知值时默认发送英文邮件,不影响验证码和令牌协议。 @@ -541,7 +555,7 @@ Bind Postfix only to loopback and the auth bridge gateway; restrict `mynetworks` to loopback and the auth container's exact address, with `permit_mynetworks, reject` relay/client restrictions. Recheck the container address after deployment. Do not expose SMTP through a public Docker port or WAF. Restrict envelope senders -to the owned sender domain (for example, `*@openbitfun.com`), sign all its sender +to the owned sender domain (for example, `*@example.com`), sign all its sender addresses with OpenDKIM, and keep `relayhost` empty for direct MX delivery. Enable opportunistic TLS for outbound delivery, persistent queues, and systemd startup ordering after Docker. Keep DKIM private keys and any SMTP diff --git a/deploy/miniapp-market/backup.sh b/deploy/miniapp-market/backup.sh index 7e2b8526e7..cd8592771e 100755 --- a/deploy/miniapp-market/backup.sh +++ b/deploy/miniapp-market/backup.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -readonly MARKET_ROOT="/srv/openbitfun-miniapp-market" +readonly MARKET_ROOT="${MARKET_ROOT:-/srv/openbitfun-miniapp-market}" readonly DATA_ROOT="${MARKET_ROOT}/data" readonly ARTIFACT_ROOT="${MARKET_ROOT}/artifacts" readonly BACKUP_ROOT="${MARKET_ROOT}/backups" @@ -11,8 +11,8 @@ readonly TODAY="$(date -u +%F)" readonly WEEK="$(date -u +%G-W%V)" readonly DAILY_TARGET="${DAILY_ROOT}/${TODAY}" -if [[ "${MARKET_ROOT}" != "/srv/openbitfun-miniapp-market" ]]; then - echo "Unexpected backup root" >&2 +if [[ "${MARKET_ROOT}" != /* || "${MARKET_ROOT}" == "/" ]]; then + echo "MARKET_ROOT must be an absolute path below /" >&2 exit 1 fi diff --git a/deploy/miniapp-market/docker-compose.yml b/deploy/miniapp-market/docker-compose.yml index bcb1c2cb74..aaab9a7343 100644 --- a/deploy/miniapp-market/docker-compose.yml +++ b/deploy/miniapp-market/docker-compose.yml @@ -18,18 +18,17 @@ services: ports: - "127.0.0.1:9710:9710" env_file: - - /etc/openbitfun-miniapp-market/market.env - - path: /etc/openbitfun-miniapp-market/smtp.env + - ${MINIAPP_MARKET_ENV_DIR:-/etc/openbitfun-miniapp-market}/market.env + - path: ${MINIAPP_MARKET_ENV_DIR:-/etc/openbitfun-miniapp-market}/smtp.env required: false environment: - MARKET_GITHUB_CALLBACK_URL: https://auth.openbitfun.com/api/v1/auth/github/callback MARKET_BIND: 0.0.0.0:9710 MARKET_DATABASE_PATH: /app/data/market.sqlite MARKET_ARTIFACT_DIR: /app/artifacts MARKET_WEB_DIR: /app/web volumes: - - /srv/openbitfun-miniapp-market/data:/app/data - - /srv/openbitfun-miniapp-market/artifacts:/app/artifacts + - ${MINIAPP_MARKET_ROOT:-/srv/openbitfun-miniapp-market}/data:/app/data + - ${MINIAPP_MARKET_ROOT:-/srv/openbitfun-miniapp-market}/artifacts:/app/artifacts tmpfs: - /tmp:rw,noexec,nosuid,nodev,size=64m healthcheck: diff --git a/deploy/miniapp-market/market.env.example b/deploy/miniapp-market/market.env.example index 54a12f43fa..16ba6a188a 100644 --- a/deploy/miniapp-market/market.env.example +++ b/deploy/miniapp-market/market.env.example @@ -1,17 +1,21 @@ -MARKET_PUBLIC_BASE_URL=https://market.openbitfun.com/miniapp +MARKET_PUBLIC_BASE_URL=https://market.example.com/miniapp +# Unified GitHub sign-in callback. Leave empty to derive it from the public base. +MARKET_GITHUB_CALLBACK_URL=https://auth.example.com/api/v1/auth/github/callback MARKET_PUBLIC_BROWSE=false # Keep browser-based submission writes disabled. OpenBitFun Desktop uses Bearer auth and remains enabled. MARKET_WEB_SUBMISSIONS_ENABLED=false MARKET_GITHUB_CLIENT_ID= MARKET_GITHUB_CLIENT_SECRET= MARKET_SESSION_SECRET=replace-with-at-least-32-random-bytes -MARKET_ADMIN_GITHUB_IDS=24753352 +# Comma-separated numeric GitHub IDs allowed to administer the market. +# Empty means no administrator until this deployment sets its own IDs. +MARKET_ADMIN_GITHUB_IDS= RUST_LOG=openbitfun_miniapp_market=info,tower_http=info # Optional email-code sign-in. Production stores these in a separate root-only smtp.env. # SMTP_HOST=smtp.qiye.aliyun.com # SMTP_PORT=465 # SMTP_SECURITY=ssl -# SMTP_USERNAME=hello@openbitfun.com +# SMTP_USERNAME=hello@example.com # SMTP_PASSWORD= # SMTP_FROM_NAME=OpenBitFun diff --git a/deploy/miniapp-market/nginx-auth.openbitfun.com.conf b/deploy/miniapp-market/nginx-auth.conf similarity index 83% rename from deploy/miniapp-market/nginx-auth.openbitfun.com.conf rename to deploy/miniapp-market/nginx-auth.conf index b75c0deb8f..220f1d24fe 100644 --- a/deploy/miniapp-market/nginx-auth.openbitfun.com.conf +++ b/deploy/miniapp-market/nginx-auth.conf @@ -1,26 +1,26 @@ -# Shared GitHub sign-in facade. Install beside the market host; keep the -# unified GitHub callback on auth.openbitfun.com. The completion bridge keeps -# host-only marketplace cookies isolated from other subdomains. Requires relay-v1.conf's -# trusted WAF peer map and the existing miniapp_market_json log format. +# Shared GitHub sign-in facade. Install beside the market host and replace the +# example hostnames below. The completion bridge keeps host-only marketplace +# cookies isolated from other subdomains. Requires the trusted-proxy peer map +# from relay-v1/nginx-http.conf and the miniapp_market_json log format. server { listen 80; listen [::]:80; - server_name auth.openbitfun.com; + server_name auth.example.com; if ($relay_v1_trusted_origin_peer = 0) { return 403; } - access_log /var/log/nginx/auth.openbitfun.com.access.log miniapp_market_json; + access_log /var/log/nginx/miniapp-auth.access.log miniapp_market_json; error_log /dev/null crit; real_ip_header X-Forwarded-For; real_ip_recursive on; - set_real_ip_from 190.92.193.0/24; - set_real_ip_from 159.138.94.0/24; - set_real_ip_from 101.44.169.0/24; - set_real_ip_from 2405:f080:110::/120; + # Replace with the egress ranges of your own reverse proxy or WAF. + # The placeholder ranges below are documentation-only and trust nobody. + set_real_ip_from 192.0.2.0/24; + set_real_ip_from 2001:db8::/32; client_max_body_size 16k; add_header X-Content-Type-Options nosniff always; add_header Referrer-Policy no-referrer always; add_header X-Frame-Options DENY always; - proxy_set_header Host market.openbitfun.com; + proxy_set_header Host market.example.com; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-For $remote_addr; proxy_connect_timeout 5s; @@ -33,7 +33,7 @@ server { add_header Referrer-Policy "no-referrer" always; add_header X-Content-Type-Options nosniff always; add_header X-Frame-Options DENY always; - return 302 https://market.openbitfun.com/miniapp/api/v1/auth/github/callback$is_args$args; + return 302 https://market.example.com/miniapp/api/v1/auth/github/callback$is_args$args; } # Pages sign-in uses the existing auth origin; published content stays on diff --git a/deploy/miniapp-market/nginx-default-server.conf b/deploy/miniapp-market/nginx-default-server.conf index 9b96d1c3ce..59da4d13f2 100644 --- a/deploy/miniapp-market/nginx-default-server.conf +++ b/deploy/miniapp-market/nginx-default-server.conf @@ -1,9 +1,8 @@ # Fail closed for hostnames that do not have an explicit Nginx vhost. # -# openbitfun.com currently uses wildcard DNS/WAF routing, so an unknown -# subdomain can still reach this origin. Without a default_server, Nginx sends -# that request to whichever vhost was loaded first (historically New API). -# Keep this server free of proxy_pass directives. +# Wildcard DNS or a shared WAF can route an unknown subdomain to this origin. +# Without a default_server, Nginx sends that request to whichever vhost was +# loaded first. Keep this server free of proxy_pass directives. server { listen 80 default_server; listen [::]:80 default_server; diff --git a/deploy/miniapp-market/nginx-market.openbitfun.com.conf b/deploy/miniapp-market/nginx-market.conf similarity index 89% rename from deploy/miniapp-market/nginx-market.openbitfun.com.conf rename to deploy/miniapp-market/nginx-market.conf index 75a7b18ba9..eaa13dddfc 100644 --- a/deploy/miniapp-market/nginx-market.openbitfun.com.conf +++ b/deploy/miniapp-market/nginx-market.conf @@ -1,9 +1,10 @@ server { listen 80; listen [::]:80; - server_name market.openbitfun.com; + # Replace with the public hostname of your market deployment. + server_name market.example.com; - access_log /var/log/nginx/market.openbitfun.com.access.log miniapp_market_json; + access_log /var/log/nginx/miniapp-market.access.log miniapp_market_json; # Nginx error records include the client address and cannot use a custom # anonymized format. Application errors remain available as structured logs. error_log /dev/null crit; @@ -12,11 +13,11 @@ server { error_page 413 = @market_payload_too_large; location = / { - return 308 https://market.openbitfun.com/miniapp/; + return 308 https://market.example.com/miniapp/; } location = /miniapp { - return 308 https://market.openbitfun.com/miniapp/; + return 308 https://market.example.com/miniapp/; } location ^~ /miniapp/ { @@ -37,7 +38,7 @@ server { } location = /skin { - return 308 https://market.openbitfun.com/skin/; + return 308 https://market.example.com/skin/; } location ^~ /skin/ { diff --git a/deploy/miniapp-market/restore-drill.sh b/deploy/miniapp-market/restore-drill.sh index 4e16eadc5c..bbf51333bb 100755 --- a/deploy/miniapp-market/restore-drill.sh +++ b/deploy/miniapp-market/restore-drill.sh @@ -1,11 +1,17 @@ #!/usr/bin/env bash set -euo pipefail -readonly BACKUP_ROOT="/srv/openbitfun-miniapp-market/backups" +readonly MARKET_ROOT="${MARKET_ROOT:-/srv/openbitfun-miniapp-market}" +readonly BACKUP_ROOT="${MARKET_ROOT}/backups" readonly SOURCE="${1:-}" +if [[ "${MARKET_ROOT}" != /* || "${MARKET_ROOT}" == "/" ]]; then + echo "MARKET_ROOT must be an absolute path below /" >&2 + exit 2 +fi + if [[ -z "${SOURCE}" || "${SOURCE}" != "${BACKUP_ROOT}/"* || ! -d "${SOURCE}" ]]; then - echo "Usage: $0 /srv/openbitfun-miniapp-market/backups/{daily|weekly}/" >&2 + echo "Usage: $0 ${BACKUP_ROOT}/{daily|weekly}/" >&2 exit 2 fi diff --git a/deploy/openbitfun-host/AGENTS.md b/deploy/openbitfun-host/AGENTS.md deleted file mode 100644 index 748fdd352a..0000000000 --- a/deploy/openbitfun-host/AGENTS.md +++ /dev/null @@ -1,14 +0,0 @@ -# OpenBitFun production host - -This directory is the restore entry for the current production origin -(`ssh lwb`). Read [README.md](README.md) before changing cron, Nginx, the -release mirror, Relay, the website, New API, or either market. - -This is a **move of an existing origin**, not a green-field install. Do not -re-run the export/import steps against the live `lwb` host. Do not invent a -second copy of `scripts/openbitfun-release-sync.sh`. Cron must run the in-repo -script from the OpenBitFun checkout. - -MiniApp and Skin markets have their own runbooks. Do not mix their checkouts, -secrets, or Compose projects with this host index. Do not generate new market -secrets when the old `market.env` files still exist. diff --git a/deploy/openbitfun-host/README.md b/deploy/openbitfun-host/README.md deleted file mode 100644 index cc1e84d8b2..0000000000 --- a/deploy/openbitfun-host/README.md +++ /dev/null @@ -1,602 +0,0 @@ -# OpenBitFun 生产源站恢复手册 - -给换机后的人和 AI Agent:clone OpenBitFun 之后按本文把当前 `ssh lwb` 这台源站 -搬到新机器。命令默认从 OpenBitFun 仓库根目录执行。 - -这是 **已有源站搬迁**,不是从零装一套空服务。不要对仍在服务的 `lwb` 重跑 -clone、`crontab` 整表安装、市场 first-install 或空 volume 的 `deploy.sh`。 - -不要再发明一份脱离仓库的同步脚本副本。历史上的 -`/root/repos/OpenBitFun-AutoUpdate/` 只是旧主机上的运行拷贝,换机后不要重建。 -当前源站只靠 cron,不必恢复 webhook listener。 - -## Agent 先读这个 - -1. 根目录 `AGENTS.md`,再读本文件。 -2. MiniApp / Skin 分别只走它们自己的手册,不要从本目录重建那两个容器。 -3. 不要 `cat`、下载或打印 `/etc/openbitfun-*/market.env`、New API 数据目录、账号密码。 -4. 不要在 `/root/repos/OpenBitFun` 或 `/root/repos/OpenBitFun-Website` 上跑 `git clean`。 - 共享 OpenBitFun checkout 上也禁止无确认的 `git reset --hard`(与 MiniApp 手册一致)。 - 该 checkout 里可能有 Relay 的未跟踪 `.env`。 -5. 本机 Nginx 只听 80。HTTPS 在前面的云 WAF / 负载均衡终止,不要在这台机器上 - 擅自申请 Let's Encrypt 或改 443。 -6. 未知 Host 必须落到 `00-default-server.conf` 的 404,不能落到 New API 或 Relay。 -7. 每步失败立刻停。先做旧机只读导出,再在新机导入。 - -## 这台机器上有什么 - -| 产品 | 公网 | 源站 | 仓库内入口 | -| --- | --- | --- | --- | -| 官网 + 下载页 | `https://openbitfun.com/` 、`/download` | Nginx → `OpenBitFun-Website/dist` | 本文「官网」 | -| OpenBitFun Playbook | `https://playbook.openbitfun.com/` | Nginx → `/srv/openbitfun-playbook/current` | 本文「OpenBitFun Playbook」 | -| Release 镜像 | `https://openbitfun.com/release/` | cron → `/srv/openbitfun-release` | 本文「Release 镜像」;脚本在 `scripts/openbitfun-release-sync.sh` | -| Relay | `https://remote.openbit.fun/relay` | `openbitfun-relay:9700` | `src/apps/relay-server/README.md` + 本文 Nginx | -| MiniApp 市场 | `https://market.openbitfun.com/miniapp/` | `127.0.0.1:9710` | [../miniapp-market/README.md](../miniapp-market/README.md) | -| Skin 市场 | `https://market.openbitfun.com/skin/` | `127.0.0.1:9720` | [../skin-market/README.md](../skin-market/README.md) | -| New API | `https://api.openbit.fun/` | `0.0.0.0:33292` | **不在 OpenBitFun 仓库**。见本文「New API」 | - -当前生产 SSH 别名是 `lwb`(root)。下文旧机用 `OLD_HOST=lwb`,新机用 -`NEW_HOST`。换机后可以把 `lwb` 指到新主机,但导出/导入期间必须同时能 SSH -到两台。 - -生产路径约定: - -| 路径 | 用途 | -| --- | --- | -| `/root/repos/OpenBitFun` | OpenBitFun checkout。Relay 静态页和同步脚本从这里读 | -| `/root/repos/OpenBitFun-Website` | 官网独立仓库 `GCWing/OpenBitFun-Website` | -| `/srv/openbitfun-release` | GitHub Release 镜像(禁止放进 Website `dist/`) | -| `/srv/openbitfun-playbook` | Playbook 的不可变静态版本与 `current` 软链接 | -| `/srv/openbitfun-miniapp-market` | MiniApp 专用 checkout / 数据 / 备份 | -| `/srv/openbitfun-skin-market` | Skin 专用 checkout / 数据 / 备份 | -| `/etc/openbitfun-miniapp-market/market.env` | MiniApp secrets,`root:root` `0600` | -| `/etc/openbitfun-skin-market/market.env` | Skin secrets,`root:root` `0600` | -| `/root/repos/new_api_bak` | New API 镜像 tar + `data/` 卷。OpenBitFun 不管 | - -Git remote 不要混用: - -- **换机新 clone** `https://github.com/GCWing/OpenBitFun.git` 之后,唯一 remote 是 - `origin`,跟踪 `origin/main`。 -- **当前仍在服务的 `lwb`** 是 `origin=bobleer/OpenBitFun`、 - `upstream=GCWing/OpenBitFun`。只在这台旧机上才使用 `upstream`。 - -脚本里的 `OPENBITFUN_BASE_URL` 写死为 `https://openbitfun.com/release`。 -域名变了要改 `scripts/openbitfun-release-sync.sh`,不能只改 Nginx。 - -## A. 旧机只读导出 - -在能 SSH 到旧机的机器上执行。默认 `OLD_HOST=lwb`。导出目录在旧机 -`/root/openbitfun-host-export`,不要写进 Website `dist/` 或 OpenBitFun checkout。 - -```bash -OLD_HOST=lwb -ssh "$OLD_HOST" 'set -eu -EXPORT=/root/openbitfun-host-export -rm -rf "$EXPORT" -install -d -m 0700 "$EXPORT" - -git -C /root/repos/OpenBitFun remote -v >"$EXPORT/openbitfun.remotes" -git -C /root/repos/OpenBitFun rev-parse HEAD >"$EXPORT/openbitfun.rev" -git -C /root/repos/OpenBitFun-Website rev-parse HEAD >"$EXPORT/website.rev" -git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD >"$EXPORT/miniapp.rev" -git -C /srv/openbitfun-skin-market/app rev-parse HEAD >"$EXPORT/skin.rev" -crontab -l >"$EXPORT/root.crontab" -uname -a >"$EXPORT/uname.txt" -docker ps --format "{{.Names}} {{.Image}} {{.Status}}" >"$EXPORT/docker.ps" -node -v >"$EXPORT/node.version" 2>/dev/null || true - -docker run --rm \ - -v relay-server_relay-db:/data \ - -v "$EXPORT":/backup \ - alpine tar czf /backup/relay-server_relay-db.tar.gz -C /data . -docker run --rm \ - -v relay-server_room-web:/data \ - -v "$EXPORT":/backup \ - alpine tar czf /backup/relay-server_room-web.tar.gz -C /data . - -test -s "$EXPORT/openbitfun.rev" -test -s "$EXPORT/relay-server_relay-db.tar.gz" -test -s "$EXPORT/relay-server_room-web.tar.gz" -ls -la "$EXPORT"' -``` - -然后把导出目录、Release 镜像、市场数据、New API 和 secrets **拷到新机**。 -`rsync` 不要加 `-v` 去扫 `market.env` 内容。 - -```bash -OLD_HOST=lwb -NEW_HOST=new-openbitfun # 换成新机器 SSH 别名 -ssh "$NEW_HOST" 'install -d -m 0700 /root/openbitfun-host-export /root/repos /srv' - -rsync -aH --numeric-ids "$OLD_HOST:/root/openbitfun-host-export/" \ - "$NEW_HOST:/root/openbitfun-host-export/" -rsync -aH --numeric-ids "$OLD_HOST:/srv/openbitfun-release/" \ - "$NEW_HOST:/srv/openbitfun-release/" -rsync -aH --numeric-ids \ - "$OLD_HOST:/srv/openbitfun-miniapp-market/" \ - "$NEW_HOST:/srv/openbitfun-miniapp-market/" -rsync -aH --numeric-ids \ - "$OLD_HOST:/srv/openbitfun-skin-market/" \ - "$NEW_HOST:/srv/openbitfun-skin-market/" -rsync -aH --numeric-ids \ - "$OLD_HOST:/etc/openbitfun-miniapp-market/" \ - "$NEW_HOST:/etc/openbitfun-miniapp-market/" -rsync -aH --numeric-ids \ - "$OLD_HOST:/etc/openbitfun-skin-market/" \ - "$NEW_HOST:/etc/openbitfun-skin-market/" -rsync -aH --numeric-ids \ - "$OLD_HOST:/root/repos/new_api_bak/" \ - "$NEW_HOST:/root/repos/new_api_bak/" -``` - -验收:新机上 `test -s /root/openbitfun-host-export/relay-server_relay-db.tar.gz`、 -`test -d /srv/openbitfun-release/1.0.0`、`test -f /etc/openbitfun-miniapp-market/market.env`。 -不要 `cat` 任何 `market.env`。 - -## B. 新机导入 - -下面 `ssh` 目标都是 `$NEW_HOST`。先装 Docker、Nginx、cron,再按顺序做。 -每块做完就跑该块验证。 - -### 1. 基础软件和 Node - -生产官网构建用 **Node v20.20.2**,装在 `/root/.nvm`。非交互 SSH 默认不加载 -nvm,所以每条 `npm` 命令都要先 `source`。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -export DEBIAN_FRONTEND=noninteractive -apt-get update -apt-get install -y docker.io nginx cron rsync curl ca-certificates python3 -systemctl enable --now docker nginx cron -command -v docker -command -v nginx -systemctl is-active cron - -export NVM_DIR="$HOME/.nvm" -if [ ! -s "$NVM_DIR/nvm.sh" ]; then - curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash -fi -# shellcheck disable=SC1091 -. "$NVM_DIR/nvm.sh" -nvm install 20.20.2 -nvm alias default 20.20.2 -node -v -test "$(node -v)" = "v20.20.2"' -``` - -### 2. OpenBitFun checkout - -新机从 **GCWing/OpenBitFun** clone,只用 `origin`。checkout 导出记录的 commit, -不要猜 `upstream/main`。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -OPENBITFUN_REV="$(cat /root/openbitfun-host-export/openbitfun.rev)" -test -n "$OPENBITFUN_REV" -if [ ! -d /root/repos/OpenBitFun/.git ]; then - git clone https://github.com/GCWing/OpenBitFun.git /root/repos/OpenBitFun -fi -cd /root/repos/OpenBitFun -git remote -v -git fetch origin -git checkout --detach "$OPENBITFUN_REV" -test "$(git rev-parse HEAD)" = "$OPENBITFUN_REV" -test -x scripts/openbitfun-release-sync.sh' -``` - -`git remote -v` 应只有 `origin → github.com/GCWing/OpenBitFun.git`。 - -### 3. Nginx 兜底(先拆 Ubuntu default) - -新装 Nginx 自带 `sites-enabled/default`,也是 `default_server`。不删掉的话, -未知 Host 不会落到市场手册里的 404 兜底。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -rm -f /etc/nginx/sites-enabled/default -install -m 0644 \ - /root/repos/OpenBitFun/deploy/miniapp-market/nginx-default-server.conf \ - /etc/nginx/sites-available/00-default-server.conf -ln -sfn /etc/nginx/sites-available/00-default-server.conf \ - /etc/nginx/sites-enabled/00-default-server.conf -nginx -t -systemctl reload nginx -code="$(curl -sS -o /dev/null -w "%{http_code}" \ - -H "Host: unconfigured.openbitfun.com" http://127.0.0.1/)" -test "$code" = "404"' -``` - -### 4. Release 镜像 - -先用旧机 rsync 过来的目录,再跑一次 in-repo 同步补最新版。不要对空目录只 -sync 一次就当完成。 - -1.X 发布前必须更新仓库内同步脚本。新桌面端清单是 `latest-v1.json`,CLI 清单是 -`linux-binaries-v1.json`。GitHub Latest 仍携带从 v0.2.19 原样保留的 -`latest.json` / `linux-binaries.json`,给还在跑 0.2.x 的客户端;镜像不再保留 -0.2.x 目录。完整规则见 [发布指南](../../docs/development/releasing.md)。 - -网页安装包文件名以 GitHub `latest-v1.json` 的 `manual_installers` 为准 -(Windows 是 `OpenBitFun_${version}_windows-x86_64-installer.exe`,macOS 是 -`OpenBitFun_${version}_{aarch64,x64}.dmg`)。不要再写死 `openbitfun-installer.exe`。 -镜像脚本每 10 分钟看一次 Latest:版本没变就什么都不拉,只清到最近 2 个版本目录。 - -`release-sync.cron` **就是这台机器的整份 root crontab**。`crontab` 该文件会 -替换所有 root cron。先备份,确认没有其它任务再装。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -test -d /srv/openbitfun-release -test -f /srv/openbitfun-release/downloads.json -touch /var/log/openbitfun-release-sync.log -chmod 644 /var/log/openbitfun-release-sync.log -crontab -l > /root/openbitfun-host-export/new-host.crontab.bak 2>/dev/null || true -crontab /root/repos/OpenBitFun/deploy/openbitfun-host/release-sync.cron -crontab -l -/root/repos/OpenBitFun/scripts/openbitfun-release-sync.sh -python3 -c "import json; print(json.load(open(\"/srv/openbitfun-release/downloads.json\"))[\"version\"])"' -``` - -`downloads.json` 的 `version` 必须等于 -`https://github.com/GCWing/OpenBitFun/releases/latest/download/latest-v1.json` 的 -`version`。日志里若再出现 `Failed to download openbitfun-installer.exe`,说明跑到了 -旧脚本,停下来改 cron,不要手工改清单。 - -稳定镜像跟随 GitHub `/releases/latest`,不按版本名是否包含 `beta` 分类。 -例如 `v1.0.0-beta` 是 `prerelease=false` 的 Latest,必须进入默认稳定镜像; -`OPENBITFUN_RELEASE_CHANNEL=beta` 读取的是独立的 `channel-v1-beta`。 - -#### 已有源站的 1.X 同步切换 - -2026-09-11 的故障来自部署未对齐:root cron 仍执行 -`/root/repos/BitFun/scripts/openbitfun-release-sync.sh`,读取兼容旧客户端的 -`latest.json` 得到 0.2.19,随后因 Relay 仓库名称校验失败退出。只更新 -OpenBitFun checkout 不会修改已有 crontab。 - -在仍运行的源站修复时,先备份当前 crontab、同步脚本与根清单,再核对: - -- cron 只执行 `/root/repos/OpenBitFun/scripts/openbitfun-release-sync.sh`,日志为 - `/var/log/openbitfun-release-sync.log`。只替换该任务行,保留其它任务。 -- 实际执行的脚本读取 `latest-v1.json` 和 `linux-binaries-v1.json`,并校验 - `ghcr.io/gcwing/openbitfun-relay-server`。不要放宽校验来兼容错配的新旧清单。 -- 脚本输出与 Nginx `/release/` alias 必须指向同一目录。当前 `lwb` 保留 - `/srv/bitfun-release` 的历史文件,以 `/srv/openbitfun-release` 软链接指向它; - Nginx 仍使用原 alias。迁移到新机时复制真实文件到新的标准目录,不能只复制 - 指向旧路径的软链接。 -- 手动执行一次脚本,等日志出现 `sync complete` 或 `nothing to fetch`,再检查 - 公网下载页、`downloads.json`、`latest-v1.json`、`linux-binaries-v1.json` - 及当前版本的平台下载链接。镜像只保留最近两个版本目录。 - `latest.json` 和 `linux-binaries.json` 是 0.2.x 客户端的 GitHub 兼容清单, - 脚本不得改写它们。 - -锁文件默认是 `/var/lock/openbitfun-release-sync.lock`,不要再指向 -`/root/repos/OpenBitFun-AutoUpdate/sync.lock`,也不要放进 `/srv/openbitfun-release` -(该目录由 Nginx `/release/` 对外提供)。 - -可选 beta: - -```bash -OPENBITFUN_RELEASE_CHANNEL=beta /root/repos/OpenBitFun/scripts/openbitfun-release-sync.sh -``` - -### 5. 官网 - -官网不在 OpenBitFun 里。源码是 `https://github.com/GCWing/OpenBitFun-Website`。 -`npm run build` 会清空 `dist/`,所以 Release 镜像绝不能放进 `dist/release`。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -WEBSITE_REV="$(cat /root/openbitfun-host-export/website.rev)" -test -n "$WEBSITE_REV" -if [ ! -d /root/repos/OpenBitFun-Website/.git ]; then - git clone https://github.com/GCWing/OpenBitFun-Website.git /root/repos/OpenBitFun-Website -fi -cd /root/repos/OpenBitFun-Website -git fetch origin -git checkout --detach "$WEBSITE_REV" -export NVM_DIR="$HOME/.nvm" -# shellcheck disable=SC1091 -. "$NVM_DIR/nvm.sh" -nvm use 20.20.2 -npm install -npm run build -test -f dist/index.html -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-openbit.fun.conf \ - /etc/nginx/sites-available/openbit.fun -ln -sfn /etc/nginx/sites-available/openbit.fun /etc/nginx/sites-enabled/openbit.fun -nginx -t -systemctl reload nginx -curl -fsS -o /dev/null -w "%{http_code}\n" \ - -H "Host: openbitfun.com" http://127.0.0.1/' -``` - -更新官网:在 Website 仓库拉代码后只跑 `npm run build`,不要动 `/srv/openbitfun-release`。 - -### 5.1 OpenBitFun Playbook - -Playbook 源码在 OpenBitFun 仓库的 `website/`。功能与设置的唯一人工维护数据源是 -`src/shared/interactive-capabilities/catalog.json`;网站只读取由它生成的 -`docs/interactive-capabilities/capabilities.json`。构建与上传从开发机执行;源站只保存 -不可变静态版本,不需要 Node 运行时。 - -```bash -pnpm run capabilities:check -pnpm run capabilities:test -pnpm run website:test -pnpm run website:build -PLAYBOOK_RELEASE="$(node -e 'const r=require("./website/dist/release.json");process.stdout.write(r.releaseId)')" -PLAYBOOK_SAMPLE_ID="$(node -e 'const c=require("./docs/interactive-capabilities/capabilities.json");process.stdout.write(c.capabilities[0].id)')" -test -n "$PLAYBOOK_RELEASE" -test -n "$PLAYBOOK_SAMPLE_ID" -ssh lwb "install -d -m 0755 /srv/openbitfun-playbook/releases/$PLAYBOOK_RELEASE" -rsync -a --delete website/dist/ \ - "lwb:/srv/openbitfun-playbook/releases/$PLAYBOOK_RELEASE/" -rsync -a deploy/openbitfun-host/nginx-playbook.openbitfun.com.conf \ - lwb:/tmp/nginx-playbook.openbitfun.com.conf -ssh lwb "set -eu -install -m 0644 /tmp/nginx-playbook.openbitfun.com.conf \ - /etc/nginx/sites-available/playbook.openbitfun.com -ln -sfn /srv/openbitfun-playbook/releases/$PLAYBOOK_RELEASE \ - /srv/openbitfun-playbook/current -ln -sfn /etc/nginx/sites-available/playbook.openbitfun.com \ - /etc/nginx/sites-enabled/playbook.openbitfun.com -nginx -t -systemctl reload nginx -curl --retry 5 --retry-delay 1 --retry-all-errors -fsS -o /dev/null \ - -H 'Host: playbook.openbitfun.com' http://127.0.0.1/ -curl --retry 5 --retry-delay 1 --retry-all-errors -fsS -o /dev/null \ - -H 'Host: playbook.openbitfun.com' \ - http://127.0.0.1/capabilities/$PLAYBOOK_SAMPLE_ID/ -curl --retry 5 --retry-delay 1 --retry-all-errors -fsS -o /dev/null \ - -H 'Host: playbook.openbitfun.com' \ - http://127.0.0.1/data/capabilities.json" -``` - -`systemctl reload` 返回时旧 worker 可能仍短暂接请求,所以源站验收必须带重试。 -最后通过公网检查首页、任一详情页和 `/data/capabilities.json`;若源站 Host 检查为 200、 -公网仍失败,应在云 WAF / DNS 增加该主机名,源站不要自行配置 443。 - -### 6. Relay - -必须先恢复两个 volume,再启动容器。先跑 `deploy.sh` 会建空卷,账号、同步和 -Pages 资产都会丢。不要在空库上用 `relay-admin` 新建用户来“代替”恢复。 - -当前生产 `.env` 只有镜像开关(`OPENBITFUN_USE_CN_MIRROR` 等)。新机用 -`OPENBITFUN_MIRROR=auto`,让 `deploy.sh` 按主机网络自己选。不要写死 -`--global-mirror`。不要 `cat` 旧 `.env`。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -EXPORT=/root/openbitfun-host-export -test -s "$EXPORT/relay-server_relay-db.tar.gz" -test -s "$EXPORT/relay-server_room-web.tar.gz" - -docker volume create relay-server_relay-db -docker volume create relay-server_room-web -docker run --rm \ - -v relay-server_relay-db:/data \ - -v "$EXPORT":/backup \ - alpine tar xzf /backup/relay-server_relay-db.tar.gz -C /data -docker run --rm \ - -v relay-server_room-web:/data \ - -v "$EXPORT":/backup \ - alpine tar xzf /backup/relay-server_room-web.tar.gz -C /data - -cd /root/repos/OpenBitFun/src/apps/relay-server -OPENBITFUN_MIRROR=auto bash deploy.sh -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-remote.openbit.fun.conf \ - /etc/nginx/sites-available/remote.openbit.fun -ln -sfn /etc/nginx/sites-available/remote.openbit.fun \ - /etc/nginx/sites-enabled/remote.openbit.fun -nginx -t -systemctl reload nginx - -curl -fsS http://127.0.0.1:9700/health -curl -fsS -o /dev/null -w "%{http_code}\n" \ - -H "Host: remote.openbit.fun" http://127.0.0.1/relay/health -docker exec openbitfun-relay /app/relay-admin --db /app/data/openbitfun_relay.db list-users' -``` - -`list-users` 必须能看到旧机已有账号(当前是 `bowen628`、`wgq@2012`)。 -若只有空表,停下来,不要 `add-user`。 - -### 7. MiniApp / Skin(搬迁,不是首次安装) - -不要跑市场手册里的「从 `market.env.example` 生成新 secret」。旧 -`market.env`、SQLite、artifacts 已经 rsync 过来。 - -1. 确认 `/etc/openbitfun-*-market/market.env` 权限仍是 `root:root` `0600`,不要打开文件。 -2. 确认 `/srv/openbitfun-*-market/{data,artifacts,backups}` 在。 -3. 专用 checkout 回到导出的 commit,再按对应手册 **只 recreate 容器**,不要 - 当绿场初始化。 -4. Skin 仍从 MiniApp 专用 checkout 的契约出发,不要用 `/root/repos/OpenBitFun` - 当 Skin 的运行 checkout。 -5. 按市场手册安装它们自己的 Nginx 与 backup timer。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -MINIAPP_REV="$(cat /root/openbitfun-host-export/miniapp.rev)" -SKIN_REV="$(cat /root/openbitfun-host-export/skin.rev)" -test -n "$MINIAPP_REV" -test -n "$SKIN_REV" -stat -c "%U:%G %a %n" /etc/openbitfun-miniapp-market/market.env \ - /etc/openbitfun-skin-market/market.env -test -f /srv/openbitfun-miniapp-market/data/market.sqlite -test -f /srv/openbitfun-skin-market/data/market.sqlite -git -C /srv/openbitfun-miniapp-market/app checkout --detach "$MINIAPP_REV" -git -C /srv/openbitfun-skin-market/app checkout --detach "$SKIN_REV" -test "$(git -C /srv/openbitfun-miniapp-market/app rev-parse HEAD)" = "$MINIAPP_REV" -test "$(git -C /srv/openbitfun-skin-market/app rev-parse HEAD)" = "$SKIN_REV"' -``` - -然后只按: - -- MiniApp:[../miniapp-market/README.md](../miniapp-market/README.md) 的构建 / - recreate / 验证,不要走「初次开放市场」生成新 OAuth。 -- Skin:[../skin-market/README.md](../skin-market/README.md) 同样只 recreate。 - -#### 从 BitFun 0.2.x 原地升级时的一次性数据转换 - -新服务只接受 `minOpenBitFunVersion`、`openbitfun.appearance`、 -`.openbitfun-appearance` 和 `openbitfun_relay.db`,运行时不保留旧字段或旧文件名回退。 -因此只能在旧容器停止后,先把数据库和 artifacts 复制到新的 -`/srv/openbitfun-*` 目录,再对**新副本**运行迁移工具。`--live-database` 是防误操作 -护栏;若目标仍指向旧生产库,工具会拒绝执行。 - -```bash -python3 /root/repos/OpenBitFun/deploy/openbitfun-host/migrate-market-data-v1.py \ - miniapp \ - --database /srv/openbitfun-miniapp-market/data/market.sqlite \ - --live-database /srv/bitfun-miniapp-market/data/market.sqlite - -python3 /root/repos/OpenBitFun/deploy/openbitfun-host/migrate-market-data-v1.py \ - skin \ - --database /srv/openbitfun-skin-market/data/market.sqlite \ - --artifacts /srv/openbitfun-skin-market/artifacts \ - --live-database /srv/bitfun-skin-market/data/market.sqlite \ - --live-artifacts /srv/bitfun-skin-market/artifacts -``` - -Skin 工具会重写包内 schema,重新计算包 SHA、大小和审核 bundle hash,并把旧扩展名 -文件移动到新 artifacts 目录内的 `migrated-bitfun-v1/`,以便人工回滚。运行后必须 -检查 SQLite `integrity_check`、确认活跃 `packages/` 中没有旧扩展名,再启动新容器。 -Relay 是零知识存储,不能在服务端改写加密设置内容;停止旧 Relay 后,用 SQLite -`.backup` 把卷内 `bitfun_relay.db` 复制为 `openbitfun_relay.db`,保留旧文件作为回滚 -副本。旧云设置由新版客户端明确选择“使用本地配置”覆盖,不能静默兼容解析。 - -### 8. New API - -这是改过的 `new-api` 镜像,**OpenBitFun clone 恢复不了**。旧机事实: - -- 镜像:`new-api:v1.0.0-rc.14-openbitfun-mod` -- 离线包:`/root/repos/new_api_bak/new-api-v1.0.0-rc.14-openbitfun-mod.tar` -- 数据:`/root/repos/new_api_bak/data` → 容器 `/data` -- 启动:`/root/repos/new_api_bak/start.sh`(宿主 `33292` → 容器 `3000`) - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -test -f /root/repos/new_api_bak/new-api-v1.0.0-rc.14-openbitfun-mod.tar -test -d /root/repos/new_api_bak/data -/root/repos/new_api_bak/load_image.sh -/root/repos/new_api_bak/start.sh -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-api.openbit.fun.conf \ - /etc/nginx/sites-available/api.openbit.fun -ln -sfn /etc/nginx/sites-available/api.openbit.fun \ - /etc/nginx/sites-enabled/api.openbit.fun -nginx -t -systemctl reload nginx -docker inspect --format "{{.State.Status}}" new-api' -``` - -没有 tar 和 data 就不要猜镜像、不要空库上线。 - -### 9. 一次性对齐本目录的 Nginx - -若前面分步已装过官网 / Relay / API vhost,这一节只用来核对文件是否与仓库一致。 -先 `nginx -t` 再 reload。市场 vhost 仍按市场手册安装,不要用本目录文件覆盖 -`market.openbitfun.com.conf`。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -rm -f /etc/nginx/sites-enabled/default -install -m 0644 \ - /root/repos/OpenBitFun/deploy/miniapp-market/nginx-default-server.conf \ - /etc/nginx/sites-available/00-default-server.conf -ln -sfn /etc/nginx/sites-available/00-default-server.conf \ - /etc/nginx/sites-enabled/00-default-server.conf -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-openbit.fun.conf \ - /etc/nginx/sites-available/openbit.fun -ln -sfn /etc/nginx/sites-available/openbit.fun /etc/nginx/sites-enabled/openbit.fun -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-playbook.openbitfun.com.conf \ - /etc/nginx/sites-available/playbook.openbitfun.com -ln -sfn /etc/nginx/sites-available/playbook.openbitfun.com \ - /etc/nginx/sites-enabled/playbook.openbitfun.com -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-remote.openbit.fun.conf \ - /etc/nginx/sites-available/remote.openbit.fun -ln -sfn /etc/nginx/sites-available/remote.openbit.fun \ - /etc/nginx/sites-enabled/remote.openbit.fun -install -m 0644 \ - /root/repos/OpenBitFun/deploy/openbitfun-host/nginx-api.openbit.fun.conf \ - /etc/nginx/sites-available/api.openbit.fun -ln -sfn /etc/nginx/sites-available/api.openbit.fun \ - /etc/nginx/sites-enabled/api.openbit.fun -nginx -t -systemctl reload nginx' -``` - -### 10. 切 DNS / WAF - -本机没有 443。把云 WAF / 负载均衡的源站指到新机器后,再跑公网验收。 - -## 整机验收 - -在源站本机用 `Host` 头打 80,不要依赖这台机器能否解析公网 DNS。 - -```bash -NEW_HOST=new-openbitfun -ssh "$NEW_HOST" 'set -eu -curl -fsS -o /dev/null -w "openbitfun.com/ %{http_code}\n" \ - -H "Host: openbitfun.com" http://127.0.0.1/ -python3 - </main`。不要默认 `reset --hard`,不要 `git clean`。 | -| 更新 Relay | 源码更新后 `cd src/apps/relay-server && OPENBITFUN_MIRROR=auto bash deploy.sh`。账号 volume 会留下。 | -| 更新 Release 镜像脚本 | 只改仓库里的 `scripts/openbitfun-release-sync.sh`。cron 已经跑这份文件。 | -| 更新官网 | 在 `OpenBitFun-Website` 拉代码,`source ~/.nvm/nvm.sh && nvm use 20.20.2 && npm run build`。 | -| 更新 Playbook | 在开发机校验能力契约并运行 `pnpm run website:build`,再按「OpenBitFun Playbook」使用 `dist/release.json` 的版本目录上传和切换 `current`。 | -| 更新市场 | 只用对应市场手册。 | - -更新 OpenBitFun 源码**不会**自动更新官网、New API 或市场容器。 diff --git a/deploy/openbitfun-host/nginx-api.openbit.fun.conf b/deploy/openbitfun-host/nginx-api.openbit.fun.conf deleted file mode 100644 index 6235a961dc..0000000000 --- a/deploy/openbitfun-host/nginx-api.openbit.fun.conf +++ /dev/null @@ -1,27 +0,0 @@ -server { - listen 80; - listen [::]:80; - - server_name api.openbit.fun api.openbitfun.com; - - # Allow larger payloads for AI streaming APIs (default nginx limit is 1m) - client_max_body_size 100m; - - location / { - proxy_pass http://127.0.0.1:33292; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - - # WebSocket / SSE support - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - # Streaming / long timeout - proxy_buffering off; - proxy_read_timeout 1200s; - proxy_send_timeout 1200s; - } -} diff --git a/deploy/openbitfun-host/nginx-openbit.fun.conf b/deploy/openbitfun-host/nginx-openbit.fun.conf deleted file mode 100644 index 58ca960989..0000000000 --- a/deploy/openbitfun-host/nginx-openbit.fun.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen 80; - listen [::]:80; - - server_name openbit.fun www.openbit.fun openbitfun.com www.openbitfun.com; - - root /root/repos/OpenBitFun-Website/dist; - index index.html; - - location / { - try_files $uri $uri/ /index.html; - } - - # Release mirror. Lives OUTSIDE the website dist because `npm run build` - # empties dist/ and would delete the mirrored installers and manifests. - # Written by scripts/openbitfun-release-sync.sh (cron, every 10 min). - # `^~` keeps the immutable-cache regex location below from matching these. - location ^~ /release/ { - alias /srv/openbitfun-release/; - autoindex off; - } - - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|mp4|webm|woff|woff2|ttf|eot)$ { - expires 30d; - add_header Cache-Control "public, immutable"; - } - - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; - gzip_min_length 1024; -} diff --git a/deploy/openbitfun-host/nginx-playbook.openbitfun.com.conf b/deploy/openbitfun-host/nginx-playbook.openbitfun.com.conf deleted file mode 100644 index 1d585f9b38..0000000000 --- a/deploy/openbitfun-host/nginx-playbook.openbitfun.com.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen 80; - listen [::]:80; - - server_name playbook.openbitfun.com; - - root /srv/openbitfun-playbook/current; - index index.html; - - add_header X-Content-Type-Options "nosniff" always; - add_header Referrer-Policy "strict-origin-when-cross-origin" always; - add_header X-Frame-Options "SAMEORIGIN" always; - - location / { - try_files $uri/index.html $uri =404; - } - - location = /data/capabilities.json { - expires 5m; - add_header Cache-Control "public, max-age=300"; - } - - location ~* \.(js|css|png|ico)$ { - expires 1h; - add_header Cache-Control "public, max-age=3600"; - } - - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml; - gzip_min_length 1024; -} diff --git a/deploy/openbitfun-host/release-sync.cron b/deploy/openbitfun-host/release-sync.cron deleted file mode 100644 index 80b8258354..0000000000 --- a/deploy/openbitfun-host/release-sync.cron +++ /dev/null @@ -1,6 +0,0 @@ -# This file is the entire root crontab for the OpenBitFun origin. -# Installing it replaces every root cron job. Back up `crontab -l` first. -# Install with: -# crontab /root/repos/OpenBitFun/deploy/openbitfun-host/release-sync.cron -# Requires /root/repos/OpenBitFun checked out and /srv/openbitfun-release created. -*/10 * * * * /root/repos/OpenBitFun/scripts/openbitfun-release-sync.sh >> /var/log/openbitfun-release-sync.log 2>&1 diff --git a/deploy/outbound-mail/README.md b/deploy/outbound-mail/README.md index 8c4651e1c4..28cb2d7bf0 100644 --- a/deploy/outbound-mail/README.md +++ b/deploy/outbound-mail/README.md @@ -10,9 +10,9 @@ auth → 私有 SMTP → Postfix → 收件方 MX:25 OpenDKIM ``` -本手册描述可复用的维护规则。生产实例的具体 IP、路径、已部署版本和回滚文件见 -服务器 `/etc/openbitfun-mail/README.md`。不要将 SMTP 密码、DKIM 私钥、验证码、 -认证令牌或生产 env 文件复制到仓库。 +本手册描述可复用的维护规则。实际 IP、路径、已部署版本和回滚文件只保存在你自己的 +root-only 配置中,不要写进仓库。不要将 SMTP 密码、DKIM 私钥、验证码、 +认证令牌或 env 文件复制到仓库。 ## 网络与发信身份 @@ -20,7 +20,7 @@ auth → 私有 SMTP → Postfix → 收件方 MX:25 - 认证容器使用同机专用 Docker 网桥的宿主机地址;只授权该容器的确切 IP。 - Postfix 仅监听 loopback 和该网桥,不监听公网网卡,不发布公网 Docker SMTP 端口。 - 出站 TCP 25 必须能连接收件方 MX。WAF 处理入站 HTTP(S),不代理出站 SMTP。 -- 允许整个自有域名的发件人,例如 `hello@openbitfun.com`、`support@openbitfun.com`。 +- 允许整个自有域名的发件人,例如 `hello@example.com`、`support@example.com`。 新增同域发件地址无需创建本地邮箱。回复能否被接收,仍取决于已有收信服务。 - `mynetworks` 限制调用方,发件地址规则限制可使用的域名;不能仅靠发件域名防止开放中继。 @@ -37,7 +37,7 @@ auth → 私有 SMTP → Postfix → 收件方 MX:25 SMTP_SECURITY=local SMTP_HOST=172.19.0.1 SMTP_PORT=25 -SMTP_USERNAME=hello@openbitfun.com +SMTP_USERNAME=hello@example.com SMTP_PASSWORD= SMTP_FROM_NAME=OpenBitFun ``` @@ -62,8 +62,8 @@ Ubuntu 可安装 `postfix opendkim opendkim-tools`。安装时先选择仅本地 `/etc/postfix/main.cf` 的关键项目: ```ini -myhostname = outbound.openbitfun.com -myorigin = openbitfun.com +myhostname = outbound.example.com +myorigin = example.com mydestination = relayhost = default_transport = smtp @@ -87,7 +87,7 @@ disable_vrfy_command = yes `/etc/postfix/allowed_sender_domains` 使用精确的域名匹配: ```text -/^[^@[:space:]]+@openbitfun[.]com$/ OK +/^[^@[:space:]]+@example[.]com$/ OK ``` 这是 `regexp:` 映射,修改后不运行 `postmap` 生成 hash 数据库,检查配置并 reload 即可。 @@ -112,7 +112,7 @@ OversignHeaders From ``` `PidFile` 必须与发行版 systemd 单元一致,否则可能出现进程已运行但服务一直停留在 -`activating`。签名表用 `*@openbitfun.com` 匹配整个域名。KeyTable 指向相应 selector +`activating`。签名表用 `*@example.com` 匹配整个域名。KeyTable 指向相应 selector 及私钥;InternalHosts 只列 loopback 和确切的认证容器地址。 私钥由 `opendkim-genkey -b 2048` 在服务器上生成,目录仅允许维护者/签名服务访问, @@ -125,14 +125,14 @@ OversignHeaders From | 记录 | 作用 | | --- | --- | | `outbound` A | 指向实际出站公网 IP,不接入 WAF | -| 该公网 IP 的 PTR | 在云厂商反向解析中指向 `outbound.openbitfun.com` | +| 该公网 IP 的 PTR | 在云厂商反向解析中指向 `outbound.example.com` | | 根域 TXT SPF | 在原有 SPF 中添加 `ip4:新IP`;保留仍在使用的发信商授权,不能新增第二条 SPF | | `selector._domainkey` TXT | 对应 OpenDKIM selector 的完整公钥 | | `_dmarc` TXT | 初始使用 `v=DMARC1; p=none`;验证全部合法发信源后再考虑更严格策略 | 现有 MX 和企业邮箱入口保持不变。只有发信服务,不需要新增指向本机的 MX。 修改 DNS 后同时检查权威服务器和公共递归解析。PTR、正向地址与 SMTP HELO 身份应匹配。 -QQ 官方说明其 SPF 缓存最长可达 12 小时,换 IP 必须提前发布授权; +部分邮件服务商会缓存 SPF,换 IP 必须提前发布授权; 不要因缓存拒收而放宽 SPF 为 `+all` 或关闭验证。 轮换 DKIM 时使用新 selector:生成新密钥、发布新公钥、确认解析与 @@ -166,7 +166,7 @@ journalctl --since '30 minutes ago' -t postfix/smtp -t postfix/smtpd -t postfix/ 测试只发给操作者明确授权的地址,不打印验证码或原始邮件正文。 失败重试使用新验证码,不能让已过期验证码重新生效。 -当前实例针对验证码将队列寿命设为 10 分钟、消息大小设为 1 MiB,并限制目标并发。 +当前示例针对验证码将队列寿命设为 10 分钟、消息大小设为 1 MiB,并限制目标并发。 这些属于业务参数;接入其他邮件类型前应评估队列寿命、退信处理和容量。 不要直接清空整个队列来“修复”投递,按 queue ID 处理已确认可丢弃的测试邮件。 @@ -180,9 +180,7 @@ journalctl --since '30 minutes ago' -t postfix/smtp -t postfix/smtpd -t postfix/ 代码版本重新创建认证容器;不回退数据库、不删除用户和令牌。 5. 回滚到外部 SMTP 只改变投递路径,必须明确记录仍使用外部提供商,不能报告为自建直投成功。 -官方参考: +参考: [Postfix 基础配置](https://www.postfix.org/BASIC_CONFIGURATION_README.html)、 [Postfix 中继限制](https://www.postfix.org/SMTPD_ACCESS_README.html)、 -[Postfix Milter](https://www.postfix.org/MILTER_README.html)、 -[QQ SPF 缓存说明](https://service.mail.qq.com/detail/122/72)、 -[华为云 PTR](https://support.huaweicloud.com/usermanual-dns/zh-cn_topic_0077500015.html)。 +[Postfix Milter](https://www.postfix.org/MILTER_README.html)。 diff --git a/deploy/relay-v1/README.md b/deploy/relay-v1/README.md index 7b93149d52..1d8fab795f 100644 --- a/deploy/relay-v1/README.md +++ b/deploy/relay-v1/README.md @@ -1,4 +1,7 @@ -# Official Relay v1 deployment +# Relay v1 self-hosted deployment + +This directory is a community self-deployment template. Example domains and +paths must be replaced with your own environment. The owner guide is [Relay Server](../../src/apps/relay-server/README.md). Use this independent Compose project for `/v/1.0.2/`. Keep the `/v/1.0.1/` Compose project @@ -7,7 +10,10 @@ container, image, database, assets, and proxy location: clients built for 1.0.1 and the two releases do not share a credential database. Deploy from a committed checkout at `/srv/openbitfun-relay-v1.0.2/app`. Set -`RELAY_GIT_COMMIT` to that checkout's verified full commit. Build mobile web +`RELAY_GIT_COMMIT` to that checkout's verified full commit. Set +`RELAY_PUBLIC_ORIGIN` and `RELAY_AUTH_ORIGIN` to your public Relay and auth +origins before running Compose; the checked-in values are `example.com` +placeholders. Build mobile web from the same checkout with `pnpm run build:mobile-web` and stage its `dist` contents into `/srv/openbitfun-relay-v1.0.2/static`. Create `data` and `assets` under that root owned by UID/GID 10001 before starting Compose. @@ -16,21 +22,23 @@ The Linux host network plus explicit `127.0.0.1:19702` listener lets the service verify the immediate proxy peer before trusting its overwritten forwarded IP. Do not publish this listener on a public interface. Install `nginx-http.conf` as `/etc/nginx/conf.d/relay-v1.0.2.conf` and include `nginx-location.conf` as `/etc/nginx/relay-v1.0.2-location.conf` in the existing remote server after the container passes -its health check. Keep the existing v1.0.1 includes. The new version uses independent admission zones. -The new location accepts the existing explicit WAF origin +its health check. [`nginx-relay.conf`](nginx-relay.conf) is a full generic +server-block example. Keep the existing v1.0.1 includes. The new version uses independent admission zones. +The new location accepts your explicit WAF origin ranges and loopback; direct origin requests from other peers receive 403. Forwarded client IPs are recursively resolved only for those trusted WAF peers. Keep the range list synchronized with the WAF control plane. Raise `worker_connections` to 8192 and retain a file descriptor limit of at least 16384; validate with `nginx -t` before a graceful reload. -Published Pages use the existing official Relay address: -`https://remote.openbitfun.com/v/1.0.2/p/{github_username}/{slug}`. -Compose sets this public base URL and the separate sign-in base URL -`https://auth.openbitfun.com/v/1.0.2`. Users do not configure domains. +Published Pages use your public Relay address: +`https://relay.example.com/v/1.0.2/p/{github_username}/{slug}`. +Compose derives this public base URL and the separate sign-in base URL +`https://auth.example.com/v/1.0.2` from `RELAY_PUBLIC_ORIGIN` and +`RELAY_AUTH_ORIGIN`. Users do not configure domains. Install the versioned Pages sign-in locations from -[`nginx-auth.openbitfun.com.conf`](../miniapp-market/nginx-auth.openbitfun.com.conf) -in the existing auth server as well. Keep its marketplace sign-in routes intact. +[`nginx-auth.conf`](../miniapp-market/nginx-auth.conf) +(template file name) in the existing auth server as well. Keep its marketplace sign-in routes intact. These locations forward only Page sign-in and GitHub start/poll endpoints to Relay, preserve the auth Host, and omit query strings from access logs. The Page callback and published content remain on the remote origin. @@ -109,7 +117,7 @@ retired only for as long as the edge announces it. A 1.0.x Relay persisted every realtime session message in `realtime_messages` and never pruned it: `log_bytes` was tracked per account but no code enforced a -ceiling, so the file grew with traffic forever. One production deployment +ceiling, so the file grew with traffic forever. A legacy deployment reached **38.6 GiB in six days** with 97 accounts (~6.4 GB/day, ~2.8 M rows, ~14.5 KB per encrypted row), while every other table stayed under a megabyte. 1.0.2 stores no session content and drops those tables at startup (see @@ -182,8 +190,8 @@ sqlite3 /srv/openbitfun-relay-v1.0.1/data/relay.db \ docker start openbitfun-relay-v1.0.1 ``` -or compact online first and swap inside the window, which is what turned a -38.6 GiB file into 7.15 GiB here: run +or compact online first and swap inside the window, which turned a +38.6 GiB file into 7.15 GiB in one legacy deployment: run `VACUUM INTO '/srv/.../data/relay-compact.db'` while the service keeps serving (a consistent snapshot; `VACUUM INTO` output is `journal_mode=delete` and keeps `auto_vacuum` of the source, so the window still has to set both), then stop the diff --git a/deploy/relay-v1/compose.yml b/deploy/relay-v1/compose.yml index f07bcdf608..d2331e4542 100644 --- a/deploy/relay-v1/compose.yml +++ b/deploy/relay-v1/compose.yml @@ -32,14 +32,15 @@ services: RELAY_DB_PATH: /app/data/relay.db RELAY_ROOM_WEB_DIR: /app/room-web RELAY_ASSET_STORE_MAX_BYTES: "1073741824" - RELAY_CORS_ALLOW_ORIGINS: https://remote.openbitfun.com,https://auth.openbitfun.com - RELAY_PAGE_PUBLIC_BASE_URL: https://remote.openbitfun.com/v/1.0.2 - RELAY_PAGE_AUTH_BASE_URL: https://auth.openbitfun.com/v/1.0.2 + # Replace the example origins with the public Relay and auth hosts. + RELAY_CORS_ALLOW_ORIGINS: "${RELAY_PUBLIC_ORIGIN:-https://relay.example.com},${RELAY_AUTH_ORIGIN:-https://auth.example.com}" + RELAY_PAGE_PUBLIC_BASE_URL: ${RELAY_PUBLIC_ORIGIN:-https://relay.example.com}/v/1.0.2 + RELAY_PAGE_AUTH_BASE_URL: ${RELAY_AUTH_ORIGIN:-https://auth.example.com}/v/1.0.2 RUST_LOG: info volumes: - - /srv/openbitfun-relay-v1.0.2/data:/app/data - - /srv/openbitfun-relay-v1.0.2/assets:/app/room-web - - /srv/openbitfun-relay-v1.0.2/static:/app/static:ro + - ${RELAY_DATA_ROOT:-/srv/openbitfun-relay-v1.0.2}/data:/app/data + - ${RELAY_DATA_ROOT:-/srv/openbitfun-relay-v1.0.2}/assets:/app/room-web + - ${RELAY_DATA_ROOT:-/srv/openbitfun-relay-v1.0.2}/static:/app/static:ro logging: driver: json-file options: diff --git a/deploy/relay-v1/nginx-http.conf b/deploy/relay-v1/nginx-http.conf index 038e2cb18e..9358999807 100644 --- a/deploy/relay-v1/nginx-http.conf +++ b/deploy/relay-v1/nginx-http.conf @@ -3,16 +3,14 @@ map $http_upgrade $relay_v102_connection_upgrade { default upgrade; '' close; } -# Same explicit Huawei WAF origin ranges as the existing market deployment. -# Refresh from the WAF control plane when its origin source ranges change. +# Replace the placeholder ranges with the egress ranges of your own reverse +# proxy or WAF. Loopback is trusted so health checks can reach the Relay. geo $realip_remote_addr $relay_v102_trusted_origin_peer { default 0; 127.0.0.1 1; ::1 1; - 190.92.193.0/24 1; - 159.138.94.0/24 1; - 101.44.169.0/24 1; - 2405:f080:110::/120 1; + 192.0.2.0/24 1; + 2001:db8::/32 1; } limit_conn_zone $binary_remote_addr zone=relay_v102_client_connections:10m; limit_conn_zone $server_name zone=relay_v102_global_connections:1m; diff --git a/deploy/relay-v1/nginx-location.conf b/deploy/relay-v1/nginx-location.conf index 86d5a4ecfd..0c4051775a 100644 --- a/deploy/relay-v1/nginx-location.conf +++ b/deploy/relay-v1/nginx-location.conf @@ -1,15 +1,14 @@ -# Include inside the existing remote.openbitfun.com server block. +# Include inside the Relay server block (see nginx-relay.conf). location = /v/1.0.2 { return 308 /v/1.0.2/; } location ^~ /v/1.0.2/ { - # Trust forwarded addresses only from the existing explicit WAF peers. + # Trust forwarded addresses only from your explicit proxy/WAF peers. # Recursive extraction selects the last non-trusted address, not a spoofed # client-supplied leftmost XFF entry. Relay receives one overwritten value. - set_real_ip_from 190.92.193.0/24; - set_real_ip_from 159.138.94.0/24; - set_real_ip_from 101.44.169.0/24; - set_real_ip_from 2405:f080:110::/120; + # Replace these documentation-only placeholders with your own ranges. + set_real_ip_from 192.0.2.0/24; + set_real_ip_from 2001:db8::/32; real_ip_header X-Forwarded-For; real_ip_recursive on; if ($relay_v102_trusted_origin_peer = 0) { return 403; } diff --git a/deploy/openbitfun-host/nginx-remote.openbit.fun.conf b/deploy/relay-v1/nginx-relay.conf similarity index 68% rename from deploy/openbitfun-host/nginx-remote.openbit.fun.conf rename to deploy/relay-v1/nginx-relay.conf index 798197f918..612c02380b 100644 --- a/deploy/openbitfun-host/nginx-remote.openbit.fun.conf +++ b/deploy/relay-v1/nginx-relay.conf @@ -1,21 +1,27 @@ +# Generic Relay vhost example. The `/relay/` and root locations target the +# non-versioned Relay listener on port 9700. For the versioned `/v/1.0.2/` +# listener, include `nginx-location.conf` in this server block and adjust the +# upstream ports in `compose.yml`. server { listen 80; listen [::]:80; - server_name remote.openbit.fun remote.openbitfun.com; + # Replace with the public hostname of your Relay deployment. + # Terminate TLS at your reverse proxy or WAF and forward plain HTTP here. + server_name relay.example.com; # ── Homepage static files (exact match, served before proxy) ── location = / { - root /root/repos/OpenBitFun/src/apps/relay-server/static/homepage; + root /srv/openbitfun-relay-v1.0.2/static/homepage; try_files /index.html =404; } location = /i18n.json { - root /root/repos/OpenBitFun/src/apps/relay-server/static/homepage; + root /srv/openbitfun-relay-v1.0.2/static/homepage; } location = /i18n.shared.json { - root /root/repos/OpenBitFun/src/apps/relay-server/static/homepage; + root /srv/openbitfun-relay-v1.0.2/static/homepage; } # ── Redirect /relay → /relay/ ── @@ -24,7 +30,7 @@ server { } # ── With /relay prefix: strip prefix, proxy to relay server ── - # For clients configured with https://remote.openbit.fun/relay + # For clients configured with https://relay.example.com/relay location /relay/ { proxy_pass http://127.0.0.1:9700/; proxy_set_header Host $host; @@ -44,7 +50,7 @@ server { } # ── Without prefix: proxy directly to relay server ── - # For clients configured with https://remote.openbit.fun + # For clients configured with https://relay.example.com location / { proxy_pass http://127.0.0.1:9700; proxy_set_header Host $host; diff --git a/deploy/relay-v1/nginx-retired-version.conf b/deploy/relay-v1/nginx-retired-version.conf index 220a4fa0e0..4764e8c62d 100644 --- a/deploy/relay-v1/nginx-retired-version.conf +++ b/deploy/relay-v1/nginx-retired-version.conf @@ -1,7 +1,7 @@ # Retirement answer for a Relay version that is being sunset. # # Install as /etc/nginx/relay-retired-location.conf (http context) and include it -# in the `remote.openbitfun.com` server block *instead of* a bare `return 410` +# in the Relay server block *instead of* a bare `return 410` # for the retired prefix, after the retired version's own Compose project has # been stopped. It is the edge-only form: it keeps working after the retired # container, image and volume are deleted, and it answers the same diff --git a/deploy/skin-market/README.md b/deploy/skin-market/README.md index 87bf586b1a..30a66e3f4f 100644 --- a/deploy/skin-market/README.md +++ b/deploy/skin-market/README.md @@ -1,9 +1,20 @@ -# OpenBitFun Skin market deployment +# OpenBitFun Skin market self-hosted deployment This directory deploys the Appearance package catalog exposed to users as the -**Skin market** at `https://market.openbitfun.com/skin/`. +**Skin market** at `https://market.example.com/skin/`. -It is intentionally isolated from the production MiniApp market: +This is a community self-deployment template. `$DEPLOY_HOST`, +`market.example.com`, and the `/srv/openbitfun-*` and `/etc/openbitfun-*` paths +are examples; replace them with your own SSH host, domains, and directories. +Set `DEPLOY_HOST` in the current shell before running the commands: + +```bash +DEPLOY_HOST=root@your-server +``` + +Official hosted-service configuration is not published in this repository. + +It is intentionally isolated from the MiniApp market deployment: | Resource | Skin market | | --- | --- | @@ -36,7 +47,7 @@ checkouts; do not recreate MiniApp from the Skin Compose project. 2. Do not read, copy or print `/etc/openbitfun-skin-market/market.env`. 3. Record the previous commit and verify a current SQLite backup before a backend or schema deployment. -4. Do not recreate or modify the MiniApp, Relay, API or website containers. +4. Do not recreate or modify other services running on the host. 5. Use `--force-with-lease` for the dedicated deploy ref; never unconditional force. 6. Run `nginx -t` before reload. Install only the market vhost changed by this @@ -72,7 +83,7 @@ git show --stat --oneline "$DEPLOY_COMMIT" Create only the dedicated roots; UID/GID `10002` owns live data, never secrets: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu install -d -m 0755 /srv/openbitfun-skin-market install -d -o 10002 -g 10002 -m 0750 \ /srv/openbitfun-skin-market/data /srv/openbitfun-skin-market/artifacts @@ -89,13 +100,13 @@ Create the environment with a controlled editor, using server; do not pass it as a command argument or paste it into logs: ```bash -ssh -t lwb 'umask 077; vi /etc/openbitfun-skin-market/market.env' -ssh lwb 'chmod 600 /etc/openbitfun-skin-market/market.env; \ +ssh -t "$DEPLOY_HOST" 'umask 077; vi /etc/openbitfun-skin-market/market.env' +ssh "$DEPLOY_HOST" 'chmod 600 /etc/openbitfun-skin-market/market.env; \ stat -c "%U:%G %a %n" /etc/openbitfun-skin-market/market.env' ``` Production identity verification should use -`https://market.openbitfun.com/miniapp/api/v1/me`. Public HTTPS avoids coupling +`https://market.example.com/miniapp/api/v1/me`. Public HTTPS avoids coupling the two independent Compose networks. Skin forwards either the Bearer Authorization header or the exact Skin session and CSRF aliases required for the request; it never proxies the browser's full Cookie header. @@ -105,7 +116,7 @@ start the timer until the Skin container has created a healthy UID-10002-owned database: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu install -m 0750 /srv/openbitfun-skin-market/app/deploy/skin-market/backup.sh \ /usr/local/sbin/openbitfun-skin-market-backup install -m 0750 /srv/openbitfun-skin-market/app/deploy/skin-market/restore-drill.sh \ @@ -123,7 +134,7 @@ Inspect the target and existing deployment first. On an initial install, the container inspect/health commands are expected not to find a container: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu git -C /srv/openbitfun-skin-market/app status --short git -C /srv/openbitfun-skin-market/app rev-parse HEAD docker inspect --format "{{.Config.Image}} {{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{end}}" openbitfun-skin-market 2>/dev/null || true @@ -135,8 +146,8 @@ For an existing deployment, save the rollback target and confirm or create today's backup before changing the checkout: ```bash -PREVIOUS_COMMIT="$(ssh lwb 'git -C /srv/openbitfun-skin-market/app rev-parse HEAD')" -ssh lwb 'set -eu +PREVIOUS_COMMIT="$(ssh "$DEPLOY_HOST" 'git -C /srv/openbitfun-skin-market/app rev-parse HEAD')" +ssh "$DEPLOY_HOST" 'set -eu if test -f /srv/openbitfun-skin-market/data/market.sqlite; then today="$(date -u +%F)" target="/srv/openbitfun-skin-market/backups/daily/${today}" @@ -152,7 +163,7 @@ fi' Send only the explicit commit to the dedicated ref: ```bash -if REMOTE_REF_COMMIT="$(ssh lwb 'git -C /srv/openbitfun-skin-market/app \ +if REMOTE_REF_COMMIT="$(ssh "$DEPLOY_HOST" 'git -C /srv/openbitfun-skin-market/app \ rev-parse refs/heads/skin-market-deploy 2>/dev/null')"; then DEPLOY_LEASE="refs/heads/skin-market-deploy:${REMOTE_REF_COMMIT}" else @@ -162,9 +173,9 @@ else fi git push \ --force-with-lease="${DEPLOY_LEASE}" \ - ssh://lwb/srv/openbitfun-skin-market/app \ + ssh://$DEPLOY_HOST/srv/openbitfun-skin-market/app \ "${DEPLOY_COMMIT}:refs/heads/skin-market-deploy" -ssh lwb "set -eu +ssh "$DEPLOY_HOST" "set -eu test -z \"\$(git -C /srv/openbitfun-skin-market/app status --porcelain)\" git -C /srv/openbitfun-skin-market/app checkout --detach '$DEPLOY_COMMIT' test \"\$(git -C /srv/openbitfun-skin-market/app rev-parse HEAD)\" = '$DEPLOY_COMMIT'" @@ -173,7 +184,7 @@ test \"\$(git -C /srv/openbitfun-skin-market/app rev-parse HEAD)\" = '$DEPLOY_CO Build while any existing container continues serving, then recreate only Skin: ```bash -ssh lwb "set -eu +ssh "$DEPLOY_HOST" "set -eu cd /srv/openbitfun-skin-market/app test \"\$(git rev-parse HEAD)\" = '$DEPLOY_COMMIT' export MARKET_GIT_COMMIT='$DEPLOY_COMMIT' @@ -185,7 +196,7 @@ docker compose -f deploy/skin-market/docker-compose.yml \ Wait for health and verify revision plus both network paths: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu for attempt in $(seq 1 45); do status="$(docker inspect --format \ "{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}" \ @@ -196,18 +207,18 @@ done docker inspect --format "{{json .State}}" openbitfun-skin-market exit 1' -DEPLOYED_COMMIT="$(ssh lwb 'docker inspect --format \ +DEPLOYED_COMMIT="$(ssh "$DEPLOY_HOST" 'docker inspect --format \ "{{index .Config.Labels \"org.opencontainers.image.revision\"}}" \ openbitfun-skin-market')" test "$DEPLOYED_COMMIT" = "$DEPLOY_COMMIT" -ssh lwb 'curl -fsS http://127.0.0.1:9720/skin/api/v1/health' +ssh "$DEPLOY_HOST" 'curl -fsS http://127.0.0.1:9720/skin/api/v1/health' ``` Create and drill the first backup only after the container is healthy, then enable the timer: ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu /usr/local/sbin/openbitfun-skin-market-backup today="$(date -u +%F)" /usr/local/sbin/openbitfun-skin-market-restore-drill \ @@ -218,33 +229,33 @@ systemctl enable --now openbitfun-skin-market-backup.timer' ## Nginx route The shared market vhost is owned in -`deploy/miniapp-market/nginx-market.openbitfun.com.conf`. It keeps MiniApp at -25 MiB and grants only `/skin/` the 100 MiB transport ceiling. Skin application -validation remains 96 MiB. Install this file only when its diff is part of the -target commit: +`deploy/miniapp-market/nginx-market.conf` (template file name). +It keeps MiniApp at 25 MiB and grants only `/skin/` the 100 MiB transport +ceiling. Skin application validation remains 96 MiB. Install this file only +when its diff is part of the target commit: -The trusted WAF CIDRs in `nginx-skin-market-http.conf` are an explicit trust +The trusted proxy ranges in `nginx-skin-market-http.conf` are an explicit trust boundary, not a generic proxy list. Before each deployment, compare them with -Huawei WAF's current `ShowSourceIp` response (or the console's copied source-IP -list) and the origin firewall allowlist. Stop if any of the three sets differ. +your reverse proxy or WAF provider's current egress source-IP list and the +origin firewall allowlist. Stop if any of the sets differ. ```bash -ssh lwb 'set -eu +ssh "$DEPLOY_HOST" 'set -eu install -m 0644 \ /srv/openbitfun-skin-market/app/deploy/skin-market/nginx-skin-market-http.conf \ /etc/nginx/conf.d/skin-market.conf install -m 0644 \ - /srv/openbitfun-skin-market/app/deploy/miniapp-market/nginx-market.openbitfun.com.conf \ - /etc/nginx/sites-available/market.openbitfun.com.conf + /srv/openbitfun-skin-market/app/deploy/miniapp-market/nginx-market.conf \ + /etc/nginx/sites-available/market.example.com.conf nginx -t systemctl reload nginx curl -fsS http://127.0.0.1:9720/skin/api/v1/health' -curl -fsS https://market.openbitfun.com/skin/api/v1/health -curl -fsS https://market.openbitfun.com/skin/ >/dev/null +curl -fsS https://market.example.com/skin/api/v1/health +curl -fsS https://market.example.com/skin/ >/dev/null ``` -The domain and wildcard TLS certificate already cover this path; no new DNS -record is needed. Verify any upstream WAF body-size policy before publishing a +Point your domain's DNS and TLS certificate at this host. If a WAF or load +balancer terminates TLS, verify its body-size policy before publishing a package near the 96 MiB application limit. ## Rollback diff --git a/deploy/skin-market/backup.sh b/deploy/skin-market/backup.sh index 670b81b5c3..457a606b05 100755 --- a/deploy/skin-market/backup.sh +++ b/deploy/skin-market/backup.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -readonly MARKET_ROOT="/srv/openbitfun-skin-market" +readonly MARKET_ROOT="${MARKET_ROOT:-/srv/openbitfun-skin-market}" readonly DATA_ROOT="${MARKET_ROOT}/data" readonly ARTIFACT_ROOT="${MARKET_ROOT}/artifacts" readonly BACKUP_ROOT="${MARKET_ROOT}/backups" @@ -11,9 +11,10 @@ readonly TODAY="$(date -u +%F)" readonly WEEK="$(date -u +%G-W%V)" readonly DAILY_TARGET="${DAILY_ROOT}/${TODAY}" readonly DATABASE="${DATA_ROOT}/market.sqlite" +readonly SKIN_MARKET_UID="${SKIN_MARKET_UID:-10002}" -if [[ "${MARKET_ROOT}" != "/srv/openbitfun-skin-market" ]]; then - echo "Unexpected backup root" >&2 +if [[ "${MARKET_ROOT}" != /* || "${MARKET_ROOT}" == "/" ]]; then + echo "MARKET_ROOT must be an absolute path below /" >&2 exit 1 fi @@ -22,8 +23,8 @@ if [[ ! -f "${DATABASE}" ]]; then echo "Skin market database does not exist; refusing to create an empty backup source" >&2 exit 1 fi -if [[ "$(stat -c %u "${DATABASE}")" != "10002" ]]; then - echo "Skin market database must be owned by runtime UID 10002" >&2 +if [[ "$(stat -c %u "${DATABASE}")" != "${SKIN_MARKET_UID}" ]]; then + echo "Skin market database must be owned by runtime UID ${SKIN_MARKET_UID}" >&2 exit 1 fi if [[ "$(sqlite3 "${DATABASE}" "PRAGMA quick_check;")" != "ok" ]]; then diff --git a/deploy/skin-market/docker-compose.yml b/deploy/skin-market/docker-compose.yml index 2ad9a42ad5..8672584048 100644 --- a/deploy/skin-market/docker-compose.yml +++ b/deploy/skin-market/docker-compose.yml @@ -18,15 +18,15 @@ services: ports: - "127.0.0.1:9720:9720" env_file: - - /etc/openbitfun-skin-market/market.env + - ${SKIN_MARKET_ENV_FILE:-/etc/openbitfun-skin-market/market.env} environment: SKIN_MARKET_BIND: 0.0.0.0:9720 SKIN_MARKET_DATABASE_PATH: /app/data/market.sqlite SKIN_MARKET_ARTIFACT_DIR: /app/artifacts SKIN_MARKET_WEB_DIR: /app/web volumes: - - /srv/openbitfun-skin-market/data:/app/data - - /srv/openbitfun-skin-market/artifacts:/app/artifacts + - ${SKIN_MARKET_ROOT:-/srv/openbitfun-skin-market}/data:/app/data + - ${SKIN_MARKET_ROOT:-/srv/openbitfun-skin-market}/artifacts:/app/artifacts tmpfs: - /tmp:rw,noexec,nosuid,nodev,size=64m mem_limit: 1g diff --git a/deploy/skin-market/market.env.example b/deploy/skin-market/market.env.example index 26b71abb78..44bcd0573c 100644 --- a/deploy/skin-market/market.env.example +++ b/deploy/skin-market/market.env.example @@ -1,5 +1,5 @@ -SKIN_MARKET_PUBLIC_BASE_URL=https://market.openbitfun.com/skin -SKIN_MARKET_IDENTITY_ME_URL=https://market.openbitfun.com/miniapp/api/v1/me +SKIN_MARKET_PUBLIC_BASE_URL=https://market.example.com/skin +SKIN_MARKET_IDENTITY_ME_URL=https://market.example.com/miniapp/api/v1/me SKIN_MARKET_DOWNLOAD_HASH_SECRET=replace-with-at-least-32-random-characters SKIN_MARKET_PUBLIC_BROWSE=true RUST_LOG=openbitfun_skin_market=info,tower_http=info diff --git a/deploy/skin-market/nginx-skin-market-http.conf b/deploy/skin-market/nginx-skin-market-http.conf index a4f9dc6a3b..18d9f1424d 100644 --- a/deploy/skin-market/nginx-skin-market-http.conf +++ b/deploy/skin-market/nginx-skin-market-http.conf @@ -1,12 +1,11 @@ -# Loaded in Nginx's http context. Keep these networks synchronized with both -# the Huawei WAF control-plane source-IP list and the origin firewall. XFF is -# considered only when the direct peer belongs to this explicit set. +# Loaded in Nginx's http context. Replace the placeholder ranges with the +# egress ranges of your own reverse proxy or WAF, and keep them synchronized +# with the origin firewall. XFF is considered only when the direct peer belongs +# to this explicit set. geo $skin_market_trusted_waf_peer { default 0; - 190.92.193.0/24 1; - 159.138.94.0/24 1; - 101.44.169.0/24 1; - 2405:f080:110::/120 1; + 192.0.2.0/24 1; + 2001:db8::/32 1; } map "$skin_market_trusted_waf_peer:$http_x_forwarded_for" $skin_market_client_address { diff --git a/deploy/skin-market/restore-drill.sh b/deploy/skin-market/restore-drill.sh index fdf09559df..bf569ba407 100755 --- a/deploy/skin-market/restore-drill.sh +++ b/deploy/skin-market/restore-drill.sh @@ -1,11 +1,17 @@ #!/usr/bin/env bash set -euo pipefail -readonly BACKUP_ROOT="/srv/openbitfun-skin-market/backups" +readonly MARKET_ROOT="${MARKET_ROOT:-/srv/openbitfun-skin-market}" +readonly BACKUP_ROOT="${MARKET_ROOT}/backups" readonly SOURCE="${1:-}" +if [[ "${MARKET_ROOT}" != /* || "${MARKET_ROOT}" == "/" ]]; then + echo "MARKET_ROOT must be an absolute path below /" >&2 + exit 2 +fi + if [[ -z "${SOURCE}" || "${SOURCE}" != "${BACKUP_ROOT}/"* || ! -d "${SOURCE}" ]]; then - echo "Usage: $0 /srv/openbitfun-skin-market/backups/{daily|weekly}/" >&2 + echo "Usage: $0 ${BACKUP_ROOT}/{daily|weekly}/" >&2 exit 2 fi diff --git a/docs/development/releasing.md b/docs/development/releasing.md index 13fb1d4194..0cfa292078 100644 --- a/docs/development/releasing.md +++ b/docs/development/releasing.md @@ -215,8 +215,8 @@ The beta invocation writes below `/release/beta` and intentionally skips the stable-only CLI and Relay floating manifests. Production cron must run this in-repo script from the OpenBitFun checkout. Do not -create a detached copy. Host paths, Nginx, and the rest of the origin restore -steps live in [`deploy/openbitfun-host/README.md`](../../deploy/openbitfun-host/README.md). +create a detached copy. Host-specific Nginx and restore paths belong to your own +deployment and are not published here. The sync resolves the exact release directory from the updater manifest once; Relay and Linux metadata use that same directory to avoid mixed-version reads when GitHub's latest-release pointer changes. Publication also compares the diff --git a/scripts/linux-binaries-manifest.test.mjs b/scripts/linux-binaries-manifest.test.mjs index be980d0e7c..c3439f6146 100644 --- a/scripts/linux-binaries-manifest.test.mjs +++ b/scripts/linux-binaries-manifest.test.mjs @@ -479,15 +479,11 @@ test('pruning keeps the two newest SemVer releases and drops a newer-looking bet fs.rmSync(temp, { recursive: true, force: true }); }); -test('openbitfun sync lock and cron use the in-repo script, not a server-only copy', () => { +test('openbitfun sync uses the in-repo script and an overridable lock', () => { const syncScript = fs.readFileSync( path.join(repoRoot, 'scripts/openbitfun-release-sync.sh'), 'utf8' ); - const cronFile = fs.readFileSync( - path.join(repoRoot, 'deploy/openbitfun-host/release-sync.cron'), - 'utf8' - ); assert.match( syncScript, /OPENBITFUN_RELEASE_SYNC_LOCK/, @@ -503,16 +499,6 @@ test('openbitfun sync lock and cron use the in-repo script, not a server-only co /LOCK_FILE="\/root\/repos\/OpenBitFun-AutoUpdate\/sync\.lock"/, 'a hardcoded AutoUpdate lock forces every new host to recreate a server-only tree' ); - assert.match( - cronFile, - /\/root\/repos\/OpenBitFun\/scripts\/openbitfun-release-sync\.sh/, - 'installed crontab must invoke the OpenBitFun checkout, not a detached copy' - ); - assert.doesNotMatch( - cronFile, - /OpenBitFun-AutoUpdate/, - 'the crontab file must not revive the server-only AutoUpdate copy' - ); assert.match( syncScript, /LOCK_FILE="\$\{OPENBITFUN_RELEASE_SYNC_LOCK:-\/var\/lock\/openbitfun-release-sync\.lock\}"/, diff --git a/scripts/openbitfun-release-sync.sh b/scripts/openbitfun-release-sync.sh index 4ff569e177..607d952d34 100755 --- a/scripts/openbitfun-release-sync.sh +++ b/scripts/openbitfun-release-sync.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# sync-release.sh — Mirror OpenBitFun release assets from GitHub to openbitfun.com. +# sync-release.sh — Mirror OpenBitFun release assets from GitHub to a download mirror. # # Flow: # 1. Fetch the selected channel's latest-v1.json from GitHub @@ -19,7 +19,7 @@ # new host only needs this repository, not a detached AutoUpdate copy: # */10 * * * * /root/repos/OpenBitFun/scripts/openbitfun-release-sync.sh \ # >> /var/log/openbitfun-release-sync.log 2>&1 -# Host restore: deploy/openbitfun-host/README.md +# Host-specific paths and mirror configuration belong to your deployment. # # Optional immediate trigger. The release workflow POSTs to # ${OPENBITFUN_SYNC_WEBHOOK_URL} once assets are published (see the "Request diff --git a/scripts/product-identity-audit.mjs b/scripts/product-identity-audit.mjs index 66ec728e93..3e996e89a6 100644 --- a/scripts/product-identity-audit.mjs +++ b/scripts/product-identity-audit.mjs @@ -27,8 +27,7 @@ const productIdentityOwner = 'src/crates/contracts/core-types/src/product_identi const retiredIdentityDataBoundaryFiles = new Set([ 'OPENBITFUN_LEGACY_DATA_MIGRATION_IMPLEMENTATION_PLAN.md', 'OPENBITFUN_LEGACY_DATA_MIGRATION_INVENTORY.md', - 'deploy/openbitfun-host/README.md', - 'deploy/openbitfun-host/migrate-market-data-v1.py', + 'deploy/market-data-migration/migrate-market-data-v1.py', // Offline recovery must recognize the pre-rename assistant data location. 'scripts/recovery/repair-session-storage.py', 'scripts/recovery/repair-session-storage.test.py', @@ -54,7 +53,7 @@ const retiredIdentityDataBoundaryPrefixes = Object.freeze([ ]); const noncanonicalIdentityDataBoundaryFiles = new Set([ 'OPENBITFUN_LEGACY_DATA_MIGRATION_INVENTORY.md', - 'deploy/openbitfun-host/migrate-market-data-v1.py', + 'deploy/market-data-migration/migrate-market-data-v1.py', ]); // Published external GitHub identifiers that embed the retired token. These are diff --git a/scripts/product-identity-audit.test.mjs b/scripts/product-identity-audit.test.mjs index 3a698f65e3..f7d458d464 100644 --- a/scripts/product-identity-audit.test.mjs +++ b/scripts/product-identity-audit.test.mjs @@ -149,7 +149,7 @@ test('limits retired identity data to the one-time production migration boundary assert.deepEqual( violationsFor( `RETIRED_VERSION_FIELDS = ("${retiredField}",)`, - 'deploy/openbitfun-host/migrate-market-data-v1.py', + 'deploy/market-data-migration/migrate-market-data-v1.py', ), [], ); diff --git a/src/apps/miniapp-market-server/README.md b/src/apps/miniapp-market-server/README.md index 61d41beb10..bd7bba45ad 100644 --- a/src/apps/miniapp-market-server/README.md +++ b/src/apps/miniapp-market-server/README.md @@ -7,12 +7,12 @@ > [`src/crates/services/miniapp-market-service/`](../../crates/services/miniapp-market-service/README.md),稳定领域类型在 > `src/crates/contracts/product-domains/src/miniapp/market.rs`。修改后端并 > 提交明确 Git commit 后,按照 -> [生产部署手册](../../../deploy/miniapp-market/README.md)重建同一个容器。 +> [部署手册](../../../deploy/miniapp-market/README.md)重建同一个容器。 ## 给 AI Agent 的执行约束 1. 先阅读仓库根目录 `AGENTS.md`、本文件和 - [生产部署手册](../../../deploy/miniapp-market/README.md)。 + [部署手册](../../../deploy/miniapp-market/README.md)。 2. 遵守分层边界:入口只装配服务;SQLite、文件、OAuth 和 HTTP 实现在 Services;纯 DTO、状态机和策略放在 product-domains。 3. REST 前缀固定为 `/miniapp/api/v1`。列表和错误 envelope 是公开契约, @@ -39,7 +39,7 @@ | `../../crates/services/miniapp-market-service/src/retention.rs` | 草稿、驳回和撤回文件保留策略 | | `../../crates/services/miniapp-market-service/migrations/` | 编号 SQLite migration | | `../../crates/contracts/product-domains/src/miniapp/market.rs` | DTO、投稿状态机和市场领域事实 | -| `../../../deploy/miniapp-market/` | Compose、Nginx、备份和生产 Runbook | +| `../../../deploy/miniapp-market/` | Compose、Nginx、备份和部署 Runbook | ## 本地运行 @@ -72,21 +72,21 @@ cargo run -p openbitfun-miniapp-market-server ## 环境变量 -生产示例见 `../../../deploy/miniapp-market/market.env.example`。实际生产值只 -存在服务器的 `/etc/openbitfun-miniapp-market/market.env`。 +示例环境变量见 `../../../deploy/miniapp-market/market.env.example`。实际值只 +应存在服务器的 `/etc/openbitfun-miniapp-market/market.env`。 | 变量 | 作用 | | --- | --- | | `MARKET_BIND` | 服务监听地址;生产容器内为 `0.0.0.0:9710` | -| `MARKET_PUBLIC_BASE_URL` | 公开 base;生产为 `https://market.openbitfun.com/miniapp` | +| `MARKET_PUBLIC_BASE_URL` | 公开 base;例如 `https://market.example.com/miniapp` | | `MARKET_DATABASE_PATH` | SQLite 文件 | | `MARKET_ARTIFACT_DIR` | 内容寻址包和截图目录 | | `MARKET_WEB_DIR` | 构建后的网页目录 | -| `MARKET_GITHUB_CALLBACK_URL` | 可选 OAuth 回调地址;未设置时保留旧 public base 派生地址,官方 Compose 使用统一 auth 地址 | +| `MARKET_GITHUB_CALLBACK_URL` | 可选 OAuth 回调地址;未设置时由 `MARKET_PUBLIC_BASE_URL` 派生,桌面登录页和完成页使用该 URL 的 origin | | `MARKET_GITHUB_CLIENT_ID` | GitHub OAuth App client ID | | `MARKET_GITHUB_CLIENT_SECRET` | GitHub OAuth App secret | | `MARKET_SESSION_SECRET` | 会话签名 secret,生产至少 24 字符并应使用强随机值 | -| `MARKET_ADMIN_GITHUB_IDS` | 逗号分隔的 GitHub 数字 ID | +| `MARKET_ADMIN_GITHUB_IDS` | 逗号分隔的 GitHub 数字 ID;留空表示没有管理员 | | `MARKET_PUBLIC_BROWSE` | 是否向匿名用户开放目录 | | `MARKET_WEB_SUBMISSIONS_ENABLED` | 是否允许 Web Cookie 会话投稿;默认及生产为 `false`,Desktop Bearer 投稿不受影响 | | `RUST_LOG` | 英文 JSON 日志过滤器 | @@ -96,9 +96,10 @@ cargo run -p openbitfun-miniapp-market-server `GET /miniapp/api/v1/config` 核对实际的 `webSubmissionsEnabled`,不能只根据 env 文件内容判断已经生效。 -固定生产 OAuth callback 是: - -`https://auth.openbitfun.com/api/v1/auth/github/callback` +统一登录部署时,在 `market.env` 中设置 OAuth callback,例如 +`MARKET_GITHUB_CALLBACK_URL=https://auth.example.com/api/v1/auth/github/callback`。 +桌面登录页和完成页会使用该 URL 的 origin;未设置时使用 +`MARKET_PUBLIC_BASE_URL` 的 origin。 ## 修改后的最小验证 @@ -145,4 +146,4 @@ MARKET_GIT_COMMIT=local-verification \ 生产 Docker 镜像包含这个 Rust binary 和 `src/miniapp-market-web/dist/`。前端、后端或两者更新都使用同一条精确 commit 发布链路。详见 -[生产部署手册](../../../deploy/miniapp-market/README.md)。 +[部署手册](../../../deploy/miniapp-market/README.md)。 diff --git a/src/crates/services/miniapp-market-service/README.md b/src/crates/services/miniapp-market-service/README.md index b723f1046b..9e81e91fb8 100644 --- a/src/crates/services/miniapp-market-service/README.md +++ b/src/crates/services/miniapp-market-service/README.md @@ -8,7 +8,7 @@ 1. 先阅读仓库根 `AGENTS.md`、上级 `src/crates/services/AGENTS.md`、 [Server README](../../../apps/miniapp-market-server/README.md) 和 - [生产部署手册](../../../../deploy/miniapp-market/README.md)。 + [部署手册](../../../../deploy/miniapp-market/README.md)。 2. 本 crate 负责具体 SQLite、文件存储、GitHub OAuth、包校验和市场 HTTP 路由。纯 DTO、状态机和策略属于 `../../contracts/product-domains/src/miniapp/market.rs`。 @@ -135,7 +135,7 @@ yank、上传和 migration 变化不能只测试成功路径。 此 crate 被 `openbitfun-miniapp-market-server` 编译进与网页相同的 Docker 镜像。 不要在生产服务器直接执行 `cargo run`,不要手工替换 binary,也不要直接编辑 SQLite/artifacts。完整流程见 -[生产部署手册](../../../../deploy/miniapp-market/README.md)。 +[部署手册](../../../../deploy/miniapp-market/README.md)。 ## 邮箱验证码登录 diff --git a/src/crates/services/miniapp-market-service/src/auth.rs b/src/crates/services/miniapp-market-service/src/auth.rs index ef74c0ee5c..d3bc65b269 100644 --- a/src/crates/services/miniapp-market-service/src/auth.rs +++ b/src/crates/services/miniapp-market-service/src/auth.rs @@ -291,17 +291,19 @@ impl AuthService { "Sign-in is busy. Please try again shortly.", )); } + let auth_base_url = self.config.auth_base_url(); let authorization_url = if all_methods { let ticket = self .create_login_flow(&mut transaction, Some(&transaction_id), "/miniapp/") .await?; - format!("https://auth.openbitfun.com/sign-in#ticket={ticket}") + format!("{auth_base_url}/sign-in#ticket={ticket}") } else { + let complete_url = format!("{auth_base_url}/complete"); self.create_oauth_flow_in_transaction( &mut transaction, "desktop", Some(&transaction_id), - "https://auth.openbitfun.com/complete", + &complete_url, ) .await? }; @@ -835,7 +837,9 @@ pub(super) fn safe_return_to(value: &str) -> String { { return FALLBACK.to_string(); } - let Ok(base) = Url::parse("https://market.openbitfun.com/") else { + // Only absolute paths reach this point, so the origin is irrelevant. Use a + // reserved host instead of coupling the validator to a deployment hostname. + let Ok(base) = Url::parse("https://market.invalid/") else { return FALLBACK.to_string(); }; let Ok(target) = base.join(value) else { diff --git a/src/crates/services/miniapp-market-service/src/config.rs b/src/crates/services/miniapp-market-service/src/config.rs index 34bed21b9f..caf17417d7 100644 --- a/src/crates/services/miniapp-market-service/src/config.rs +++ b/src/crates/services/miniapp-market-service/src/config.rs @@ -51,11 +51,8 @@ impl MarketConfig { "MARKET_SESSION_SECRET must contain at least 24 characters" )); } - let admin_github_ids = env::var("MARKET_ADMIN_GITHUB_IDS") - .unwrap_or_else(|_| "24753352".to_string()) - .split(',') - .filter_map(|value| value.trim().parse::().ok()) - .collect(); + let admin_github_ids = + parse_admin_github_ids(&env::var("MARKET_ADMIN_GITHUB_IDS").unwrap_or_default()); let public_browse = env::var("MARKET_PUBLIC_BROWSE") .map(|value| matches!(value.as_str(), "1" | "true" | "TRUE" | "yes")) .unwrap_or(true); @@ -88,6 +85,32 @@ impl MarketConfig { .clone() .unwrap_or_else(|| format!("{}/api/v1/auth/github/callback", self.public_base_url)) } + + /// Public origin that serves the shared sign-in and completion pages. + /// + /// Prefer the callback origin when configured, so a deployment can keep the + /// auth facade on its own hostname. Otherwise the market origin is used. + pub fn auth_base_url(&self) -> String { + self.github_callback_url + .as_deref() + .and_then(origin_of) + .or_else(|| origin_of(&self.public_base_url)) + .unwrap_or_else(|| self.public_base_url.trim_end_matches('/').to_string()) + } +} + +fn origin_of(raw: &str) -> Option { + let mut url = url::Url::parse(raw).ok()?; + url.set_path(""); + url.set_query(None); + url.set_fragment(None); + Some(url.as_str().trim_end_matches('/').to_string()) +} + +fn parse_admin_github_ids(raw: &str) -> HashSet { + raw.split(',') + .filter_map(|value| value.trim().parse::().ok()) + .collect() } fn non_empty_env(key: &str) -> Option { @@ -96,3 +119,35 @@ fn non_empty_env(key: &str) -> Option { .map(|value| value.trim().to_string()) .filter(|value| !value.is_empty()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn admin_ids_are_empty_without_an_explicit_deployment_setting() { + assert!(parse_admin_github_ids("").is_empty()); + assert!(parse_admin_github_ids(" , ").is_empty()); + } + + #[test] + fn admin_ids_parse_comma_separated_values() { + assert_eq!( + parse_admin_github_ids(" 42, 0,not-a-number,7 "), + HashSet::from([42, 0, 7]) + ); + } + + #[test] + fn origin_of_strips_path_query_and_fragment() { + assert_eq!( + origin_of("https://auth.example.com/api/v1/auth/github/callback?x=1#frag").as_deref(), + Some("https://auth.example.com") + ); + assert_eq!( + origin_of("http://127.0.0.1:9710/miniapp").as_deref(), + Some("http://127.0.0.1:9710") + ); + assert_eq!(origin_of("not a url"), None); + } +} diff --git a/src/crates/services/miniapp-market-service/src/email_auth.rs b/src/crates/services/miniapp-market-service/src/email_auth.rs index 717e960110..ae4d5f6681 100644 --- a/src/crates/services/miniapp-market-service/src/email_auth.rs +++ b/src/crates/services/miniapp-market-service/src/email_auth.rs @@ -433,9 +433,10 @@ impl AuthService { return_to, .. } => (session_token, return_to), - CompletedOAuth::Desktop { session_token, .. } => { - (session_token, "https://auth.openbitfun.com/complete".into()) - } + CompletedOAuth::Desktop { session_token, .. } => ( + session_token, + format!("{}/complete", self.config.auth_base_url()), + ), }; let grant = random_token(32); let now = Utc::now().timestamp(); @@ -489,7 +490,9 @@ mod tests { database_path: dir.path().join("db"), artifact_dir: dir.path().join("artifacts"), web_dir: dir.path().into(), - github_callback_url: None, + github_callback_url: Some( + "https://auth.openbitfun.com/api/v1/auth/github/callback".into(), + ), github_client_id: Some("id".into()), github_client_secret: Some("secret".into()), session_secret: "test-only-session-secret-at-least-24".into(), diff --git a/src/crates/services/miniapp-market-service/src/routes.rs b/src/crates/services/miniapp-market-service/src/routes.rs index 4f3a08b2f9..922d3ebca6 100644 --- a/src/crates/services/miniapp-market-service/src/routes.rs +++ b/src/crates/services/miniapp-market-service/src/routes.rs @@ -587,11 +587,11 @@ fn complete_login_response( csrf_token, expires_at, } => { + let complete_url = format!("{}/complete", state.config.auth_base_url()); let mut response = if json { - Json(serde_json::json!({"redirectUrl": "https://auth.openbitfun.com/complete"})) - .into_response() + Json(serde_json::json!({"redirectUrl": complete_url})).into_response() } else { - Redirect::to("https://auth.openbitfun.com/complete").into_response() + Redirect::to(&complete_url).into_response() }; state.auth.append_web_session_cookies( response.headers_mut(), diff --git a/src/miniapp-market-web/README.md b/src/miniapp-market-web/README.md index a5dc03f17f..5ed686ecb7 100644 --- a/src/miniapp-market-web/README.md +++ b/src/miniapp-market-web/README.md @@ -4,14 +4,14 @@ `https://market.openbitfun.com/miniapp/`。 > 最短结论:修改这个目录里的网页,完成检查并提交 Git commit 后,按照 -> [生产部署手册](../../deploy/miniapp-market/README.md)重建并重启 +> [部署手册](../../deploy/miniapp-market/README.md)重建并重启 > `openbitfun-miniapp-market` 容器。网页和 Rust 后端在同一个 Docker 镜像中, > 不要单独把 `dist/` 上传到服务器。 ## 给 AI Agent 的执行约束 1. 先阅读仓库根目录的 `AGENTS.md`、本文件和 - [生产部署手册](../../deploy/miniapp-market/README.md)。 + [部署手册](../../deploy/miniapp-market/README.md)。 2. 只修改任务要求涉及的文件;保留工作区里不属于本任务的改动。 3. `/miniapp/` 是固定的 Vite base,`/miniapp/api/v1` 是固定的 API 前缀。 修改它们会同时影响 Nginx、OAuth callback、桌面客户端和生产链接,不能 @@ -195,7 +195,7 @@ pnpm run theme:color-audit:all - 前后端一起改:只发布一个包含同一 Git commit 的镜像。 完整的备份、精确 commit 发布、健康检查和回滚命令见 -[生产部署手册](../../deploy/miniapp-market/README.md)。 +[部署手册](../../deploy/miniapp-market/README.md)。 GitHub sign-in uses `https://auth.openbitfun.com/sign-in`; desktop completion uses its standalone `/complete` page without marketplace navigation. The page diff --git a/src/web-ui/src/flow_chat/components/ModelSelector.tsx b/src/web-ui/src/flow_chat/components/ModelSelector.tsx index 0d71f32045..bdffcc41f9 100644 --- a/src/web-ui/src/flow_chat/components/ModelSelector.tsx +++ b/src/web-ui/src/flow_chat/components/ModelSelector.tsx @@ -1336,36 +1336,6 @@ export const ModelSelector: React.FC = ({ const smartView = isNativeModelSelection && routing.available && (smartPreviewScope === modelSelectionScopeKey || (!poolId && routing.mode === 'smart')); const smartModeDescription = !routing.available ? t('modelSelector.routing.notOpen') : routing.status?.issue ? t('modelSelector.routing.configurationIssue') : t('modelSelector.modes.smartSummary'); - const handleRoutingMode = async (mode: 'manual' | 'smart', keepSmartView = false) => { - try { - if (mode === 'smart' && !routing.available) return false; - // Inspect unavailable smart mode without changing the host's active strategy. - if (mode === 'smart' && (!routing.status || !routing.status.ready)) { - setSmartPreviewScope(modelSelectionScopeKey); - closePanel(true); - return false; - } - if (mode === 'smart' && poolId && !await handleSelectModel('primary')) return false; - if (mode === 'smart' && !currentModelMode) { - manualModelRef.current = { scopeKey: modelSelectionScopeKey, modelId: currentNativeModelId }; - setRecentManualModel(modelSelectionScopeKey, currentNativeModelId); - } - const selected = routing.status ? await routing.select(mode) : mode === 'manual'; - if (selected && deviceSurfaceScope.isCurrent() && modelSelectionScopeRef.current === modelSelectionScopeKey) { - setSmartPreviewScope(keepSmartView ? modelSelectionScopeKey : null); - closePanel(true); - } - return selected; - } - catch (error) { - if (deviceSurfaceScope.isCurrent()) { - notificationService.error(t('modelSelector.routing.saveFailed')); - log.warn('Failed to update model routing strategy', { error }); - void routing.refresh(); - } - return false; - } - }; const currentModelMode = isNativeModelSelection && poolId ? 'pool' : isNativeModelSelection && routing.mode === 'smart' ? 'smart' : null; const settingsModelMode = smartView ? 'smart' : currentModelMode; // Configuration previews do not change the host's active selection. @@ -1614,9 +1584,7 @@ export const ModelSelector: React.FC = ({ activeSession?.workspacePath, acpClientId, currentMode, - currentModelMode, poolId, - currentNativeModelId, defaultModels, disabled, externalSelection, @@ -1624,7 +1592,6 @@ export const ModelSelector: React.FC = ({ loading, modelSelectionScopeKey, persistSharedModeDefault, - isNativeModelSelection, routing.pending, reasoningLoading, recentPresetForModel, @@ -1635,13 +1602,45 @@ export const ModelSelector: React.FC = ({ activeSession?.workspaceId, ]); - const handleSelectModelFromMenu = async (modelId: string) => { + const handleRoutingMode = useCallback(async (mode: 'manual' | 'smart', keepSmartView = false) => { + try { + if (mode === 'smart' && !routing.available) return false; + // Inspect unavailable smart mode without changing the host's active strategy. + if (mode === 'smart' && (!routing.status || !routing.status.ready)) { + setSmartPreviewScope(modelSelectionScopeKey); + closePanel(true); + return false; + } + if (mode === 'smart' && poolId && !await handleSelectModel('primary')) return false; + if (mode === 'smart' && !currentModelMode) { + manualModelRef.current = { scopeKey: modelSelectionScopeKey, modelId: currentNativeModelId }; + setRecentManualModel(modelSelectionScopeKey, currentNativeModelId); + } + const selected = routing.status ? await routing.select(mode) : mode === 'manual'; + if (selected && deviceSurfaceScope.isCurrent() && modelSelectionScopeRef.current === modelSelectionScopeKey) { + setSmartPreviewScope(keepSmartView ? modelSelectionScopeKey : null); + closePanel(true); + } + return selected; + } + catch (error) { + if (deviceSurfaceScope.isCurrent()) { + notificationService.error(t('modelSelector.routing.saveFailed')); + log.warn('Failed to update model routing strategy', { error }); + void routing.refresh(); + } + return false; + } + }, [closePanel, currentModelMode, currentNativeModelId, deviceSurfaceScope, handleSelectModel, modelSelectionScopeKey, poolId, routing, t]); + + const handleSelectModelFromMenu = useCallback(async (modelId: string) => { if (isNativeModelSelection && routing.mode === 'smart' && !await handleRoutingMode('manual')) return false; const selected = await handleSelectModel(modelId); if (modelSelectionScopeRef.current !== modelSelectionScopeKey) return false; if (selected && hasSettingsPanel) { setSmartPreviewScope(null); closePanel(true); } return selected; - }; + }, [closePanel, handleRoutingMode, handleSelectModel, hasSettingsPanel, isNativeModelSelection, + modelSelectionScopeKey, routing.mode]); const handleConfigureRoleModel = useCallback(async (role: ModelRole, modelId: string) => { if (!canConfigureNativeDefaults || disabled || loading || reasoningLoading