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

This commit is contained in:
2026-07-07 15:02:02 +08:00
parent 6867b165a1
commit 75bc817a59
8 changed files with 290 additions and 62 deletions
+6 -23
View File
@@ -1,6 +1,6 @@
# Docker 镜像持续构建与发布
本文档说明 Gitea Actions 中 Docker 镜像构建发布 workflow 的使用方式。对应脚本为 [.gitea/workflows/docker-image.yml](../.gitea/workflows/docker-image.yml)。
本文档说明 Gitea Actions 中 Docker 镜像构建发布与 SSH 部署 workflow 的使用方式。对应脚本为 [.gitea/workflows/docker-image.yml](../.gitea/workflows/docker-image.yml)。
## 职责划分
@@ -9,7 +9,7 @@
| Workflow | 触发时机 | 职责 |
| --- | --- | --- |
| `.gitea/workflows/ci.yml` | `dev``main``test` push / PR | 安装依赖、Lint、单元测试、Next.js 构建 |
| `.gitea/workflows/docker-image.yml` | `main``test` push / 手动触发 | 构建 Docker 镜像推送到镜像仓库 |
| `.gitea/workflows/docker-image.yml` | `main``test` push / 手动触发 | 构建 Docker 镜像推送到镜像仓库,并通过 SSH 部署 |
这样可以避免所有开发分支都发布镜像,也能让代码检查失败时不污染镜像仓库。
@@ -90,36 +90,19 @@ docker image ls | grep cozsweet-web
## 部署服务器拉取镜像
部署服务器需要先登录镜像仓库:
当前推荐由 Gitea Actions 通过 SSH 登录部署服务器并执行部署脚本,不再依赖服务器 Git remote 的 `post-receive` hook。完整说明见 [Gitea Actions SSH 部署流程](./gitea-actions-ssh-deploy.md)。
如果需要在服务器上手动验证镜像拉取,可先登录镜像仓库:
```bash
docker login REGISTRY_HOST
```
然后在部署服务器工作树中创建 `.deploy.env`
```bash
cp env-example/.deploy.env.example .deploy.env
```
配置示例:
```env
COZSWEET_DEPLOY_IMAGE_SOURCE=pull
COZSWEET_REGISTRY_IMAGE=gitea.banlv-ai.com/admin/cozsweet-web
```
`post-receive` 会根据当前分支和 commit 自动拉取:
Actions 部署时会根据当前分支和 commit 自动拉取
```bash
gitea.banlv-ai.com/admin/cozsweet-web:test-<short_sha>
gitea.banlv-ai.com/admin/cozsweet-web:prod-<short_sha>
```
如果需要改用 latest tag,可以在服务器 `.deploy.env` 中显式设置:
```env
COZSWEET_REMOTE_IMAGE_TAG=prod-latest
```
推荐优先使用默认的 `<env>-<short_sha>` 精确 tag,这样发布和回滚都更可控。