refactor(server): 拆分 cmd/mini 与 cmd/web 两个部署入口
小程序接口(lunar.neatcn.com)与商业版 Web(kepo.net)此前共用一个 二进制,导致小程序域名暴露商业后台与 Stripe Webhook,商业站点也 暴露了许愿树等小程序接口。现拆为两个入口: - cmd/mini:微信登录、生辰档案、许愿树、百科、版本号 - cmd/web:邮箱登录、commerce、报告/订单、/admin 后台、商业前端 静态托管与 SPA 回退 - internal/app 承载共用启动与路由注册;图片资源移至 internal/assets CI:server-deploy.yml 改构建 cmd/mini 并随包移除后台静态资源; 新增 web-deploy.yml 构建 cmd/web + web-commercial 前端,发布 web-v* Release;deploy-watch.sh 支持 TAG_PREFIX/ASSET_NAME 变量; 新增 deploy-web.sh(systemd 版)与 kepo 一次性配置文档 .gitea/docs/PULL_DEPLOY_WEB.md。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
28309e0257
commit
12fa2b0d19
@@ -0,0 +1,137 @@
|
||||
# kepo.net 商业版 Web 拉取式部署配置(一次性)
|
||||
|
||||
> 安全原则同 [PULL_DEPLOY.md](./PULL_DEPLOY.md):CI 只构建、不部署;任何 AI 与流水线都不允许 SSH 到服务器执行命令。
|
||||
> 部署由 kepo 服务器本地定时任务轮询 Gitea Release 自动完成。
|
||||
> 本文档所有操作均由管理员本人在服务器终端执行,不依赖 AI 远程执行。
|
||||
|
||||
## 架构
|
||||
|
||||
```
|
||||
push main → Gitea Actions 构建 cmd/web + web-commercial 前端 → web-deploy.tar.gz 发布为 web-v* Release
|
||||
↓
|
||||
kepo 服务器 cron(每分钟)运行 deploy-watch.sh(TAG_PREFIX=web-v)→ 发现新 release → HTTPS 拉取
|
||||
↓
|
||||
deploy-web.sh 原子切换 + systemctl restart lunar-web + 健康检查(失败自动回滚)
|
||||
↓
|
||||
Cloudflare (HTTPS 终结) → kepo 源站 :8080 lunar-web systemd 服务
|
||||
```
|
||||
|
||||
## 与小程序接口部署的差异
|
||||
|
||||
| | lunar.neatcn.com | kepo.net |
|
||||
|---|---|---|
|
||||
| 二进制 | `cmd/mini` | `cmd/web` |
|
||||
| Release 前缀 | `server-v*` | `web-v*` |
|
||||
| 部署包 | `deploy.tar.gz` | `web-deploy.tar.gz` |
|
||||
| 运行方式 | Docker 容器 | systemd 服务 `lunar-web` |
|
||||
| 部署目录 | `/opt/lunar/production` | `/opt/lunar-web/production` |
|
||||
|
||||
## 一次性安装步骤(按序执行)
|
||||
|
||||
### 1. 准备目录与脚本
|
||||
|
||||
```bash
|
||||
mkdir -p /opt/lunar-web/{production,scripts,backups}
|
||||
# 从仓库复制脚本(任选其一):
|
||||
# git clone 后 cp .gitea/scripts/{deploy-watch.sh,deploy-web.sh} /opt/lunar-web/scripts/
|
||||
# 或直接下载原始文件写入
|
||||
chmod +x /opt/lunar-web/scripts/*.sh
|
||||
```
|
||||
|
||||
### 2. 生产环境变量
|
||||
|
||||
写入 `/opt/lunar-web/production/.env`,权限 `600`:
|
||||
|
||||
```ini
|
||||
SERVER_ENV=production
|
||||
SERVER_PORT=8080
|
||||
PUBLIC_BASE_URL=https://kepo.net
|
||||
WEB_APP_URL=https://kepo.net
|
||||
CORS_ORIGINS=https://kepo.net,https://www.kepo.net
|
||||
|
||||
DB_TYPE=mysql
|
||||
DB_HOST=<数据库地址>
|
||||
DB_PORT=3306
|
||||
DB_USER=<用户名>
|
||||
DB_PASSWORD=<密码>
|
||||
DB_NAME=lunar_web # 建议与小程序库分开;若暂时共用,填 lunar
|
||||
|
||||
JWT_SECRET=<强随机值,至少32位>
|
||||
ADMIN_PASSWORD=<后台登录密码>
|
||||
|
||||
SMTP_HOST=smtp.qq.com
|
||||
SMTP_PORT=465
|
||||
SMTP_USERNAME=<QQ邮箱>
|
||||
SMTP_PASSWORD=<SMTP授权码>
|
||||
SMTP_FROM_EMAIL=z@kepo.net
|
||||
SMTP_TLS_MODE=implicit
|
||||
|
||||
STRIPE_SECRET_KEY=
|
||||
STRIPE_WEBHOOK_SECRET=
|
||||
BINANCE_PAY_API_KEY=
|
||||
BINANCE_PAY_SECRET_KEY=
|
||||
BINANCE_PAY_WEBHOOK_PUBLIC_KEY=
|
||||
```
|
||||
|
||||
> kepo 侧不需要 `MINI_APP_ID` / `MINI_APP_SECRET` / `WECHAT_PAY_*`;
|
||||
> lunar 侧则不需要 SMTP / Stripe / Binance 变量。
|
||||
|
||||
### 3. systemd 服务
|
||||
|
||||
`/etc/systemd/system/lunar-web.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Lunar Commercial Web (kepo.net)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/opt/lunar-web/production/current
|
||||
EnvironmentFile=/opt/lunar-web/production/.env
|
||||
ExecStart=/opt/lunar-web/production/current/bin/server
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable lunar-web
|
||||
# 首次启动前需要先手工放一版部署包,或等待第一次 Release 拉取
|
||||
```
|
||||
|
||||
### 4. 定时拉取任务
|
||||
|
||||
crontab(`crontab -e`)添加:
|
||||
|
||||
```cron
|
||||
* * * * * TAG_PREFIX=web-v ASSET_NAME=web-deploy.tar.gz \
|
||||
STATE_FILE=/opt/lunar-web/production/.last-deployed-release \
|
||||
DEPLOY_SCRIPT=/opt/lunar-web/scripts/deploy-web.sh \
|
||||
LOG_FILE=/opt/lunar-web/deploy-watch.log \
|
||||
/opt/lunar-web/scripts/deploy-watch.sh
|
||||
```
|
||||
|
||||
首次运行后会自动部署最新 `web-v*` Release。日志:`/opt/lunar-web/deploy-watch.log`。
|
||||
|
||||
### 5. Cloudflare 回源
|
||||
|
||||
kepo.net 已走 Cloudflare。确认回源指向本机 8080(或 Nginx 反代到 8080)。
|
||||
服务只监听 `127.0.0.1` 或由防火墙限制 8080 仅本机访问。
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
curl -s http://127.0.0.1:8080/api/version # 应返回 version/buildTime/commitSha
|
||||
curl -s -o /dev/null -w '%{http_code}' https://kepo.net/
|
||||
curl -s -o /dev/null -w '%{http_code}' https://kepo.net/admin/
|
||||
```
|
||||
|
||||
## 注意
|
||||
|
||||
- **数据库**:短期内两边共用 `lunar` 库(后台 `/admin` 在 kepo 侧统一查看订单与小程序数据)。后续如需分离,新建 `lunar_web` 库并改 `DB_NAME`。
|
||||
- **回滚**:`deploy-web.sh` 健康检查失败会自动恢复 `current.old`;也可手动 `systemctl restart lunar-web`。
|
||||
- **小程序端**:部署包结构不变(`deploy/bin/server`),doc79 上的 watcher 无需改动。
|
||||
Reference in New Issue
Block a user