138 lines
5.0 KiB
Markdown
138 lines
5.0 KiB
Markdown
# Deploy Platform
|
||
|
||
项目运维平台。
|
||
|
||
## Scripts
|
||
|
||
```bash
|
||
npm install
|
||
make build
|
||
make up
|
||
npm run dev
|
||
npm run build
|
||
npm run lint
|
||
npm run test
|
||
```
|
||
|
||
## Docs
|
||
|
||
- [UI 设计规范](./docs/liquid-glass-admin-ui-guideline.md)
|
||
- [第一版开发内容](./docs/v1-development-scope.md)
|
||
- [模块化开发规范](./docs/modular-development-guideline.md)
|
||
|
||
## Standalone Deploy
|
||
|
||
构建后可一键运行 `dist` 和 `deploy` API:
|
||
|
||
```bash
|
||
npm run deploy:run
|
||
```
|
||
|
||
已有 `dist` 时直接启动:
|
||
|
||
```bash
|
||
npm run deploy:serve
|
||
```
|
||
|
||
默认地址:`http://127.0.0.1:29200`。
|
||
|
||
也可以用 Makefile 一键运行:
|
||
|
||
```bash
|
||
make up
|
||
```
|
||
|
||
部署模板和 TAT 脚本见 `deploy/README.md`。
|
||
|
||
## 数据资源
|
||
|
||
- API:`GET /deploy/api/hyapp/resources?remote=1`
|
||
- 链路:Tencent TAT -> deploy 机器
|
||
- MySQL、Redis、MQ:腾讯云托管资源
|
||
- 业务服务器配置:优先 SSH,失败后 TAT 兜底
|
||
- 前端状态:TAT 未返回前保持加载
|
||
- 禁止:生产 SQL/Mongo 查询入口
|
||
|
||
## 微服务
|
||
|
||
- 列表:`GET /deploy/api/hyapp/discover?remote=1`
|
||
- 详情 YAML:`GET /deploy/api/hyapp/discover?remote=1&includeConfig=1`
|
||
- 链路:Tencent TAT -> deploy 机器 `43.164.75.199` -> SSH 业务机器
|
||
- 数据来源:SSH 读取 systemd、Docker、镜像、资源、日志和配置
|
||
- YAML 入口:列表右侧三点、详情配置区
|
||
- 禁止:静态假数据兜底展示运行态
|
||
|
||
## 测试 Server
|
||
|
||
这里的测试 server 指 HyApp 后端测试机 testbox,不是生产业务机。
|
||
|
||
- 测试机:`43.165.195.39` / `10.11.0.2`
|
||
- CVM 实例:`lhins-q0m38zc6`
|
||
- 区域:`ap-jakarta`
|
||
- 根目录:`/opt/hyapp-server-test`
|
||
- 代码目录:`/opt/hyapp-server-test/source`
|
||
- 部署脚本:`/opt/hyapp-server-test/bin/deploy.sh`
|
||
- 自动更新 timer:`hyapp-server-test-deploy.timer`
|
||
- 部署完成标记:`/opt/hyapp-server-test/.deployed_commit`
|
||
- 后台前端:`http://1.14.164.2:7001/`
|
||
|
||
当前测试机不走生产镜像仓库,也不摘 CLB。部署模式是测试机自己拉取远端 `test` 分支,`hyapp-server-test-deploy.timer` 每分钟触发一次部署检查;部署成功且 Compose 服务全部 healthy 后,才写入 `.deployed_commit`。
|
||
|
||
平台里的“测试服务”页面通过 deploy-platform API 调用 `deploy/tencent_tat/hyapp_testbox_config.py`,再通过 Tencent TAT 到测试机执行固定动作。页面不开放任意 shell:
|
||
|
||
- `GET /deploy/api/hyapp/testbox/status`:读取 test 分支、远端 test commit、已部署 commit、timer 和服务状态。
|
||
- `GET /deploy/api/hyapp/testbox/configs`:读取测试机服务 YAML,默认脱敏密钥字段。
|
||
- `POST /deploy/api/hyapp/testbox/service`:固定服务操作 `update/start/stop/restart`。
|
||
- `POST /deploy/api/hyapp/testbox/timer`:固定 timer 操作 `start/stop/restart/status`。
|
||
- `POST /deploy/api/hyapp/testbox/config`:写入单个服务配置,先备份旧文件,可选保存后重启。
|
||
- `GET /deploy/api/hyapp/testbox/migrations`:只列出 `source/server/admin/migrations/*.sql`。
|
||
- `POST /deploy/api/hyapp/testbox/migrations/apply`:只执行测试机仓库里的 migration 文件。
|
||
|
||
本地或 deploy-platform 机器上确认状态:
|
||
|
||
```bash
|
||
curl -fsS "http://127.0.0.1:29200/deploy/api/hyapp/testbox/status?services=gateway-service,room-service,admin-server"
|
||
```
|
||
|
||
直接走脚本确认状态:
|
||
|
||
```bash
|
||
python3 deploy/tencent_tat/hyapp_testbox_config.py status \
|
||
--env-file /opt/hy-app-monitor/.env \
|
||
--services gateway-service,room-service,admin-server
|
||
```
|
||
|
||
## 测试 Server 日志 Debug
|
||
|
||
先看平台状态,再看测试机日志。
|
||
|
||
1. 在“测试服务”页面刷新,确认 `test 分支`、`已部署 commit`、`远端 commit`、`timerState`、服务 `state/health/restartCount`。
|
||
2. 如果页面或 API 报错,先看 deploy-platform 自身日志:
|
||
|
||
```bash
|
||
journalctl -u hyapp-deploy-platform -n 200 --no-pager
|
||
docker logs --tail=200 -f hyapp-deploy-platform
|
||
```
|
||
|
||
3. 如果 TAT 到测试机成功但服务异常,登录测试机或通过腾讯云 TAT 执行同等只读命令:
|
||
|
||
```bash
|
||
ssh root@43.165.195.39
|
||
|
||
systemctl status hyapp-server-test-deploy.timer --no-pager
|
||
journalctl -u hyapp-server-test-deploy.timer -n 100 --no-pager
|
||
journalctl -u hyapp-server-test-deploy.service -n 200 --no-pager
|
||
|
||
cd /opt/hyapp-server-test/source
|
||
docker compose -p hyapp-test -f docker-compose.yml -f /opt/hyapp-server-test/docker-compose.testbox.yml ps
|
||
docker compose -p hyapp-test -f docker-compose.yml -f /opt/hyapp-server-test/docker-compose.testbox.yml logs --tail=200 -f gateway-service
|
||
docker inspect gateway-service
|
||
|
||
git -C /opt/hyapp-server-test/source status
|
||
git -C /opt/hyapp-server-test/source rev-parse HEAD
|
||
git -C /opt/hyapp-server-test/source ls-remote origin refs/heads/test
|
||
cat /opt/hyapp-server-test/.deployed_commit
|
||
```
|
||
|
||
如果 `/opt/hyapp-server-test/docker-compose.testbox.yml` 不存在,去掉第二个 `-f`。Debug 时优先查具体异常服务的 Compose 日志,例如 `room-service`、`wallet-service`、`admin-server`。配置问题先通过页面查看脱敏 YAML;需要保存配置时必须补齐真实密钥,包含 `***` 的配置禁止保存。
|