docs: 新增 CI/CD 方案(deploy/ci-cd.md): main 推送经 Gitea Actions 自动部署

只写方案, 不落地(workflow 以代码块形式放在文档里, 避免没有 runner 时
push 触发一直挂在"等待 runner")。

要点(都基于本机实测 + 1.27.3 源码):
- runner 必须是"宿主上的 act_runner 二进制 + host 模式": 离线环境下容器模式
  既拉不到 job 镜像, 镜像里也没有 python3/git/docker CLI; host 模式下 job 直接
  以 ymy 在宿主执行, 路径/工具全现成
- 工作流不写 uses:: DEFAULT_ACTIONS_URL 默认指向 github.com, 离线拿不到
  actions/checkout; 同步代码用 run: 里的 git
- 免凭据: 从 /srv/gitea/git/repositories/course-team/tjhlp-gitea.git 直接 fetch
  (实测 git -c safe.directory 对本机 git 无效, 必须写进配置文件)
- 部署逻辑放 deploy/scripts/auto-deploy.sh(可版本化/可手工跑), workflow 只做
  "同步到 github.sha + 调脚本"; build.py 失败不碰容器, 验证失败自动回滚
- 落地步骤分 4 阶段: 下载 runner(需一次外网) -> 部署克隆 -> sudo 装 systemd
  单元并注册(仓库级 runner, API 已确认存在) -> 先 workflow_dispatch 手动跑通
  再打开 push 触发 + main 分支保护
- 明确写出 host 模式的安全含义(等价 root)、待落地确认项(host 标签语法/fork PR
  审批等)与备选方案(cron 轮询)

deploy/README.md 快速索引加一行指向该文档。
This commit is contained in:
2026-09-13 16:59:39 +08:00
parent b60e5e9f1e
commit a65970303f
2 changed files with 480 additions and 0 deletions
+1
View File
@@ -35,6 +35,7 @@
| **恢复**(含演练) | §6 | `sudo ./scripts/restore.sh <时间戳> --apply` |
| **升级** Gitea / PostgreSQL | §7 | 备份 → 改 `.env` → `up -d` |
| 改首页 / 中文术语 / 去 Gitea 化 | [`../customization/README.md`](../customization/README.md) | `python3 customization/build.py` → `docker compose restart gitea` |
| main 推送后自动部署(方案) | [`ci-cd.md`](ci-cd.md) | Gitea Actions + 宿主 act_runner(host 模式) |
| 出问题了 | §12 | — |
| 退回二进制部署 | §9 | `docker compose down && sudo systemctl start gitea` |