ci(deploy): deploy images over ssh from gitea actions

This commit is contained in:
2026-07-07 15:02:02 +08:00
parent 9cb9534459
commit e699ff13b3
8 changed files with 290 additions and 62 deletions
+13 -29
View File
@@ -1,12 +1,14 @@
# 自动构建与自动重启流程
# 自动构建与自动重启流程(旧 Git Hook 方案)
本文档说明当前项目通过 Git remote + `post-receive` hook 实现自动部署、自动重启的流程。当前服务器端运行方式已经容器化,核心文件为 [.githooks/post-receive](../.githooks/post-receive)、[Dockerfile](../Dockerfile) 和 [docker-compose.yml](../docker-compose.yml)。
本文档记录旧的 Git remote + `post-receive` hook 部署流程,仅作为回滚参考。当前推荐方案已迁移为 Gitea Actions 构建镜像并通过 SSH 部署,见 [Gitea Actions SSH 部署流程](./gitea-actions-ssh-deploy.md)。
旧方案核心文件为 [.githooks/post-receive](../.githooks/post-receive)、[Dockerfile](../Dockerfile) 和 [docker-compose.yml](../docker-compose.yml)。
服务器默认仍会本地构建 Docker 镜像;如果服务器工作树中存在 `.deploy.env` 且配置 `COZSWEET_DEPLOY_IMAGE_SOURCE=pull`,则会改为从镜像仓库拉取由 Gitea Actions 构建好的镜像。
## 部署入口
## 部署入口
当前涉及两个服务器 remote
旧方案涉及两个服务器 remote
| 环境 | Git remote | 推送分支 | 宿主机端口 | 容器端口 | 部署脚本 |
| --- | --- | --- | --- | --- | --- |
@@ -20,48 +22,30 @@ test root@43.106.13.130:/root/cozsweet-repos/test
production root@43.106.13.130:/root/cozsweet-repos/main
```
常用发布入口:
```bash
# 发布测试环境
./scripts/release/pre_release_web.sh
# 发布生产环境
./scripts/release/release_web.sh
```
也可以只执行推送脚本:
```bash
# 推送 test remote 的 test 分支
./scripts/deploy/deploy_web_test.sh
# 推送 production remote 的 main 分支
./scripts/deploy/deploy_web.sh
```
当前日常发布入口已经改为推送 Gitea 分支并触发 Actions,详见 [Gitea Actions SSH 部署流程](./gitea-actions-ssh-deploy.md)。`scripts/deploy/*` 已改为推送 `gitea` remote,不再推送服务器 remote。旧方案如果需要手动触发,需要直接操作对应服务器仓库。
## 本地发布流程
测试环境发布流程:
测试环境发布流程(脚本迁移前)
1. 进入 test worktree`cozsweet-frontend-nextjs.worktrees/cozsweet-nextjs-test`
2. 确认当前分支。
3. 执行 `git rebase dev`,把 `dev` 的最新代码变基到 `test` 分支。
4. 复制测试环境图标到 `public/`
5. 复制 `env-example/.env.local.example``.env.local`
6. 执行 `scripts/deploy/deploy_web_test.sh`
7. `deploy_web_test.sh` 推送 `test` remote 的 `test` 分支。
6. 执行旧版 `scripts/deploy/deploy_web_test.sh`
7. 旧版 `deploy_web_test.sh` 推送 `test` remote 的 `test` 分支。
8. 推送成功后尝试清除 Cloudflare CDN 缓存。
生产环境发布流程:
生产环境发布流程(脚本迁移前)
1. 进入 main worktree`cozsweet-frontend-nextjs.worktrees/cozsweet-nextjs-main`
2. 确认当前分支。
3. 执行 `git rebase dev`,把 `dev` 的最新代码变基到 `main` 分支。
4. 复制生产环境图标到 `public/`
5. 复制 `env-example/.env.production.example``.env.production`
6. 执行 `scripts/deploy/deploy_web.sh`
7. `deploy_web.sh` 强制推送 `production` remote 的 `main` 分支。
6. 执行旧版 `scripts/deploy/deploy_web.sh`
7. 旧版 `deploy_web.sh` 强制推送 `production` remote 的 `main` 分支。
8. 推送成功后尝试清除 Cloudflare CDN 缓存。
## 服务器端 post-receive 流程