docs: 添加自动部署方案到 README

功能:
- Gitea Webhook + 更新脚本方案
- 自动拉取代码、构建镜像、重启容器
- 健康检查确认更新成功

作者: 小白 🐶
This commit is contained in:
2026-03-14 22:27:37 +08:00
parent 657a3440b9
commit 1b41e28499
3 changed files with 484 additions and 0 deletions

100
README.md
View File

@@ -631,6 +631,106 @@ volumes:
---
## 自动部署 🔄
> Gitea 仓库提交后自动更新 Docker 容器
### 方案对比
| 方案 | 复杂度 | 说明 |
|------|--------|------|
| **方案 1: Webhook + 脚本** | ⭐ 简单 | 推荐,实现快、依赖少 |
| **方案 2: Gitea Actions** | ⭐⭐⭐ 中等 | 功能强大,需要配置 Runner |
| **方案 3: Watchtower** | ⭐⭐ 简单 | 自动监控镜像更新 |
### 推荐方案Webhook + 脚本
#### 架构流程
```
开发者推送代码 → Gitea 触发 Webhook → 更新脚本执行
→ 拉取代码 → 构建镜像 → 重启容器 → 健康检查
```
#### 1. 更新脚本
```bash
#!/bin/bash
# /www/wwwroot/pit-router/auto-update.sh
set -e
cd /www/wwwroot/pit-router
# 拉取最新代码
git fetch origin && git reset --hard origin/main
# 重建并启动
docker-compose down
docker-compose build --no-cache
docker-compose up -d
# 健康检查
sleep 10
curl -sf http://localhost:1999/health && echo "✅ 更新成功"
```
#### 2. Webhook 服务
```python
# /www/wwwroot/pit-router/webhook-server.py
from flask import Flask, request, jsonify
import hmac, hashlib, subprocess
app = Flask(__name__)
SECRET = 'your-webhook-secret'
@app.route('/webhook/pit-router', methods=['POST'])
def handle():
# 验证签名
sig = request.headers.get('X-Gitea-Signature', '')
expected = 'sha256=' + hmac.new(SECRET.encode(), request.data, hashlib.sha256).hexdigest()
if not hmac.compare_digest(sig, expected):
return {'error': 'Invalid signature'}, 401
# 执行更新
result = subprocess.run(['/www/wwwroot/pit-router/auto-update.sh'], capture_output=True)
return {'status': 'success' if result.returncode == 0 else 'error'}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)
```
#### 3. 配置 Gitea Webhook
```bash
curl -X POST "http://localhost:3000/api/v1/repos/yunxiafei/pit-router/hooks" \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"type": "gitea",
"config": {
"url": "http://localhost:5001/webhook/pit-router",
"content_type": "json",
"secret": "your-webhook-secret"
},
"events": ["push"],
"active": true
}'
```
### 实施清单
- [ ] 创建 `auto-update.sh` 脚本
- [ ] 创建 `webhook-server.py` 服务
- [ ] 配置 systemd 服务
- [ ] 配置 Gitea Webhook
- [ ] 测试自动更新
**预计时间**30 分钟
---
## 相关项目
- [PIT Channel 插件](http://1.14.58.157:3000/yunxiafei/PIT_Channel) - OpenClaw Channel 插件(智队中枢客户端)