93 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Standalone Deployment Templates
本目录集中维护生产 CVM 的 systemd + Docker 模板。`hyapp-server` 不再保留根部署目录HyApp 后端服务和当前 `deploy-platform` 自身的部署模板都在这里维护。
## Deploy Platform Runtime
- 镜像:`deploy-platform`
- 容器:`hyapp-deploy-platform`
- systemd unit`hyapp-deploy-platform`
- 监听端口:`29200`
- 健康检查:`http://127.0.0.1:29200/deploy/api/health`
同源接口:
- `GET /deploy/api/health`
- `POST /deploy/api/edgeone/purge-url`
- `GET /deploy/api/hyapp/inventory`
- `GET /deploy/api/hyapp/plan?services=gateway-service,room-service`
- `GET /deploy/api/hyapp/discover?services=gateway-service&remote=0`
- `GET /deploy/api/hyapp/discover?services=user-service&remote=1`
- `GET /deploy/api/hyapp/discover?services=user-service&remote=1&includeConfig=1`
- `GET /deploy/api/hyapp/resources?remote=1`
- `POST /deploy/api/hyapp/deploy`
- `POST /deploy/api/hyapp/admin-server/deploy`
- `POST /deploy/api/hyapp/restart`
- `GET /deploy/api/hyapp/testbox/status`
- `POST /deploy/api/hyapp/testbox/service`
- `POST /deploy/api/hyapp/testbox/timer`
- `POST /deploy/api/hyapp/testbox/config`
- `GET /deploy/api/hyapp/testbox/migrations`
- `POST /deploy/api/hyapp/testbox/migrations/apply`
`discover?remote=1`TAT -> deploy `43.164.75.199` -> SSH 业务机器。`resources?remote=1`TAT -> deploy业务服务器配置 SSH 失败后 TAT 兜底;不开放 SQL/Mongo 查询入口。`deploy``restart` 是真实操作接口,必须在 JSON body 中显式传入 `confirmed: true`。联调和验收使用 `dryRun: true`
## Build Image
在发布机执行:
```bash
cd /opt/deploy/sources/deploy-platform
TAG="$(date -u +%Y%m%d%H%M%S)-$(git rev-parse --short HEAD)"
REGISTRY="10.2.1.3:18082/hyapp"
docker build -t "$REGISTRY/deploy-platform:$TAG" .
docker push "$REGISTRY/deploy-platform:$TAG"
```
## Install On Target Host
```bash
sudo mkdir -p /etc/hyapp/deploy-platform
sudo cp deploy/standalone/docker/deploy-platform.env.example /etc/hyapp/deploy-platform/docker.env
sudo vi /etc/hyapp/deploy-platform/docker.env
sudo cp deploy/standalone/systemd/hyapp-deploy-platform.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now hyapp-deploy-platform
sudo systemctl status hyapp-deploy-platform
curl -fsS http://127.0.0.1:29200/deploy/api/health
```
`docker.env` 保存镜像、容器名、停止等待时间和 deploy API 需要的运行时配置。腾讯云凭据不写入镜像;需要执行远端 discover 或 EdgeOne 刷新时,通过 `docker.env` 注入 `TENCENTCLOUD_SECRET_ID``TENCENTCLOUD_SECRET_KEY``TENCENTCLOUD_REGION`,或通过 `TENCENT_ENV_FILE` 指向挂载到容器内的凭据文件。
## HyApp Service Templates
`hyapp-server/deploy/standalone` 迁入的模板:
- `systemd/hyapp-*-service.service`:后端 Go 服务 systemd unit。
- `systemd/hyapp-admin-server.service``systemd/hyapp-admin-platform.service`:后台服务和后台前端 unit。
- `docker/*-service.env.example``docker/admin-*.env.example`:每个服务一份 Docker 运行参数示例。
这些模板只管理业务容器,不安装或重启 MySQL、Redis、MQ。生产 MySQL、Redis、MQ 继续使用腾讯云托管资源,服务配置里的 endpoint 和密钥由发布系统渲染到目标机 `/etc/hyapp/<service>/config.yaml`
`gateway-service` 为例:
```bash
sudo mkdir -p /etc/hyapp/gateway-service
sudo cp deploy/standalone/docker/gateway-service.env.example /etc/hyapp/gateway-service/docker.env
sudo cp /opt/deploy/sources/hyapp-server/services/gateway-service/configs/config.tencent.example.yaml /etc/hyapp/gateway-service/config.yaml
sudo vi /etc/hyapp/gateway-service/docker.env
sudo vi /etc/hyapp/gateway-service/config.yaml
sudo cp deploy/standalone/systemd/hyapp-gateway-service.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now hyapp-gateway-service
sudo systemctl status hyapp-gateway-service
sudo docker inspect --format '{{json .State.Health}}' hyapp-gateway-service
```
模板默认使用 `--network=host`,容器直接监听项目约定的 `13xxx` 端口。`room-service` 多实例必须配置唯一 `node_id`,且 `advertise_addr` 必须是实例私网地址,不能写内网 CLB 地址。
HyApp 后端滚动发布通过 `deploy/tencent_tat/hyapp_tat_deploy.py` 执行inventory 使用 `deploy/tencent_tat/hyapp-services.inventory.prod.example.json` 作为模板。