# Tencent TAT Deployment 本目录包含两类 TAT 发布入口: - `deploy_platform_tat_deploy.py`:发布当前 `deploy-platform` 前端项目。 - `hyapp_tat_deploy.py`:发布 HyApp 后端 Go 微服务,读取真实 systemd、Docker、镜像、资源、日志和 YAML。 - `hyapp_data_resources.py`:数据资源状态。TAT -> deploy;业务服务器配置 SSH 失败后 TAT 兜底。 两者使用同一套 TAT/CLB 滚动部署模型:可选 CLB 摘流,TAT 远端更新 `docker.env` 镜像并重启 systemd unit,健康恢复后恢复权重。 ## Deploy Platform 脚本只操作以下对象: - `hyapp-deploy-platform` systemd unit - `hyapp-deploy-platform` Docker 容器 - `/etc/hyapp/deploy-platform/docker.env` ## Prerequisites 1. 目标机已安装 Tencent TAT agent。 2. 目标机已安装 `deploy/standalone/systemd/hyapp-deploy-platform.service`。 3. 目标机已准备 `/etc/hyapp/deploy-platform/docker.env`。 4. 发布机安装腾讯云 SDK: ```bash python3 -m pip install tencentcloud-sdk-python ``` 凭据通过环境变量或 `--env-file` 提供: ```bash export TENCENTCLOUD_SECRET_ID="..." export TENCENTCLOUD_SECRET_KEY="..." export TENCENTCLOUD_REGION="me-saudi-arabia" ``` ## Inventory ```bash cp deploy/tencent-tat/inventory.prod.example.json deploy/tencent-tat/deploy-platform.inventory.prod.json vi deploy/tencent-tat/deploy-platform.inventory.prod.json ``` 必须替换: - `hosts.deploy-platform-1.instance_id` - `hosts.deploy-platform-1.private_ip` - 如果前面挂 CLB,把 `clb.enabled` 改成 `true`,并设置真实 `load_balancer_id` / `listener_ids`。 ## Commands 只看计划,不执行远端动作: ```bash python3 deploy/tencent-tat/deploy_platform_tat_deploy.py plan \ --inventory deploy/tencent-tat/deploy-platform.inventory.prod.json \ --services deploy-platform ``` 发现目标机当前状态: ```bash python3 deploy/tencent-tat/deploy_platform_tat_deploy.py discover \ --env-file /opt/hy-app-monitor/.env \ --inventory deploy/tencent-tat/deploy-platform.inventory.prod.json \ --services deploy-platform ``` 滚动更新镜像: ```bash python3 deploy/tencent-tat/deploy_platform_tat_deploy.py deploy \ --env-file /opt/hy-app-monitor/.env \ --inventory deploy/tencent-tat/deploy-platform.inventory.prod.json \ --services deploy-platform \ --tag 20260514-1800 \ --yes ``` 只重启,不改镜像: ```bash python3 deploy/tencent-tat/deploy_platform_tat_deploy.py restart \ --env-file /opt/hy-app-monitor/.env \ --inventory deploy/tencent-tat/deploy-platform.inventory.prod.json \ --services deploy-platform \ --yes ``` ## Failure Boundary 如果启用 CLB,脚本会先把当前实例权重改为 `0`,TAT 重启成功并通过 Docker health 后再恢复权重。重启或健康检查失败时,脚本停止后续步骤,已经摘流的实例保持权重 `0`,需要人工确认后恢复。 ## HyApp Services 平台后续接服务端执行器时,直接调用当前仓库内的 HyApp 微服务发布脚本: ```bash python3 deploy/tencent-tat/hyapp_tat_deploy.py plan \ --inventory deploy/tencent-tat/hyapp-services.inventory.prod.example.json \ --services gateway-service,room-service,user-service ``` 读取真实运行态和配置 YAML: ```bash python3 deploy/tencent-tat/hyapp_tat_deploy.py discover \ --env-file /opt/hy-app-monitor/.env \ --inventory deploy/tencent-tat/hyapp-services.inventory.prod.json \ --services gateway-service \ --include-config ``` 生产使用时复制成真实 inventory: ```bash cp deploy/tencent-tat/hyapp-services.inventory.prod.example.json deploy/tencent-tat/hyapp-services.inventory.prod.json vi deploy/tencent-tat/hyapp-services.inventory.prod.json ``` 数据资源状态只读查询: ```bash python3 deploy/tencent-tat/hyapp_data_resources.py resources \ --env-file /opt/hy-app-monitor/.env \ --inventory deploy/tencent-tat/hyapp-services.inventory.prod.json ``` 规则: - MySQL、Redis、MQ 是腾讯云托管资源。 - 读取入口固定为 TAT -> deploy。 - 业务服务器配置优先 SSH;SSH 失败后 TAT 兜底。 - 只读 `/etc/hyapp//config.yaml`、`docker.env`、systemd active。 - 不执行 SQL/Mongo 查询,不修改 MySQL、Redis、MQ。 ## HyApp Testbox 测试机部署不走生产镜像仓库,也不摘 CLB。当前模式是测试机自己拉取远端 `test` 分支: - 后端测试机:`43.165.195.39` / `10.11.0.2`,实例 `lhins-q0m38zc6`。 - 代码目录:`/opt/hyapp-server-test/source`。 - 部署脚本:`/opt/hyapp-server-test/bin/deploy.sh`。 - 自动轮询:`hyapp-server-test-deploy.timer`,每分钟检查一次 `test` 分支。 - 成功条件:Compose 服务全部 healthy 后才写入 `/opt/hyapp-server-test/.deployed_commit`。 - 后台前端:广州机 `172.16.0.10:7001`,公网 `http://1.14.164.2:7001/`。 测试机 Go 服务 YAML 通过只读 TAT 接口读取: ```bash python3 deploy/tencent-tat/hyapp_testbox_config.py configs \ --env-file /opt/hy-app-monitor/.env \ --services gateway-service,room-service,admin-server ``` 默认返回会遮罩 `secret`、`password`、`token`、`key` 等字段;确实需要原始值时,服务端必须显式设置 `HYAPP_TESTBOX_CONFIG_ALLOW_RAW=1`,并在 API 请求里带 `raw=1`。 测试服务后台还使用同一个脚本封装固定动作,不开放任意 shell: - `status`:读取 test 分支、已部署 commit、timer 和服务状态。 - `service --operation update|start|stop|restart`:对 Compose 服务或 `admin-server` systemd 执行固定操作。 - `timer --operation start|stop|restart|status`:控制 `hyapp-server-test-deploy.timer`。 - `write-config --service --content-base64 `:写配置前备份旧文件,可选 `--restart`。 - `migrations` / `migrations-apply`:只列出或执行 `source/server/admin/migrations/*.sql`,不接收页面手写 SQL。