ci: switch prod deploy to server-side git pull and go build
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
本文档用于 `wx_service` 在宝塔服务器上的自动化发布:
|
||||
- 触发:`main` 分支 push 或手动触发
|
||||
- 流程:GitHub Actions 构建二进制 -> SSH 上传到服务器 -> 远程发布脚本重启并健康检查
|
||||
- 流程:GitHub Actions SSH 触发服务器发布脚本 -> 服务器 git pull + go build -> 重启并健康检查
|
||||
- 特点:不依赖 Docker
|
||||
|
||||
## 1. 服务器约定
|
||||
@@ -13,7 +13,7 @@
|
||||
- 进程端口:`8080`
|
||||
- 反向代理:宝塔 Nginx -> `127.0.0.1:8080`
|
||||
|
||||
> 远程脚本:`scripts/ops/deploy_binary.sh`
|
||||
> 远程脚本:`scripts/ops/deploy_from_source.sh`(内部调用 `scripts/ops/deploy_binary.sh`)
|
||||
|
||||
## 2. GitHub Secrets
|
||||
|
||||
@@ -37,16 +37,18 @@
|
||||
- `/www/wwwroot/wx_service/.env`
|
||||
- `/www/wwwroot/wx_service/dist/.env`
|
||||
3. 开放 `8080` 本地监听,并由 Nginx 反代
|
||||
4. 第一次执行会自动尝试创建 `systemd` 服务 `wx_service`
|
||||
4. 服务器无需 Docker;第一次执行会自动安装 Go 1.23.6(若缺失)并尝试创建 `systemd` 服务 `wx_service`
|
||||
|
||||
## 5. 发布行为
|
||||
|
||||
每次发布会执行:
|
||||
|
||||
1. GitHub Actions 构建 Linux 二进制
|
||||
2. 上传到服务器 `/tmp/wx_service-<commit_sha>`
|
||||
3. 远程脚本执行:
|
||||
1. GitHub Actions 通过 SSH 调用服务器发布脚本
|
||||
2. 服务器执行:
|
||||
- `git fetch` + `git reset --hard <commit_sha>`(同步代码)
|
||||
- 安装/校验 Go 1.23.6
|
||||
- `go mod download` + `go build`
|
||||
3. 远程发布脚本继续执行:
|
||||
- 备份旧二进制到 `/www/wwwroot/wx_service/backups/`
|
||||
- 原子替换 `dist/wx_service`
|
||||
- 重启服务
|
||||
@@ -55,7 +57,7 @@
|
||||
|
||||
## 6. 手动发布(应急)
|
||||
|
||||
在服务器执行:
|
||||
在服务器执行(仅二进制手动发布场景):
|
||||
|
||||
```bash
|
||||
cd /www/wwwroot/wx_service
|
||||
@@ -86,3 +88,19 @@ systemctl restart wx_service
|
||||
pkill -f /www/wwwroot/wx_service/dist/wx_service
|
||||
su -s /bin/bash - www -c "cd /www/wwwroot/wx_service/dist && nohup ./wx_service >> /www/wwwlogs/wx_service.stdout.log 2>&1 &"
|
||||
```
|
||||
|
||||
|
||||
## 8. 手动发布(从源码构建)
|
||||
|
||||
```bash
|
||||
cd /www/wwwroot/wx_service
|
||||
APP_DIR=/www/wwwroot/wx_service \
|
||||
DIST_DIR=/www/wwwroot/wx_service/dist \
|
||||
DEPLOY_REF=main \
|
||||
RELEASE_ID=manual-$(date +%Y%m%d%H%M%S) \
|
||||
GO_VERSION=1.23.6 \
|
||||
SERVICE_NAME=wx_service \
|
||||
RUN_USER=www RUN_GROUP=www \
|
||||
PORT=8080 \
|
||||
bash scripts/ops/deploy_from_source.sh
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user