mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 18:10:30 +08:00
119 lines
3.7 KiB
Markdown
119 lines
3.7 KiB
Markdown
# Gitea CI/CD 配置指南
|
||
|
||
## 1. Gitea Actions Runner 注册
|
||
|
||
### 1.1 部署 Runner
|
||
|
||
```bash
|
||
# 从 Gitea 管理后台获取 runner 注册令牌
|
||
# 位置:站点管理 -> 运行 Actions -> 创建 Runner
|
||
|
||
# 创建 runner 数据目录
|
||
mkdir -p /opt/gitea-runner
|
||
cd /opt/gitea-runner
|
||
|
||
# 下载 act runner
|
||
curl -sL https://gitea.com/gitea/act_runner/releases/latest/download/act_runner-linux-amd64 -o act_runner
|
||
chmod +x act_runner
|
||
|
||
# 注册 runner(替换 TOKEN 和 GITEA_URL)
|
||
./act_runner register \
|
||
--instance https://gitea.craftlabs.cn \
|
||
--token <REGISTRATION_TOKEN> \
|
||
--name craftlabs-runner \
|
||
--labels ubuntu-latest:docker://node:20-bookworm
|
||
|
||
# 以服务方式运行
|
||
./act_runner daemon &
|
||
```
|
||
|
||
### 1.2 Runner 标签说明
|
||
|
||
| 标签 | 用途 | 对应的 workflow `runs-on` |
|
||
|------|------|--------------------------|
|
||
| `ubuntu-latest` | 通用构建和测试 | `ubuntu-latest` |
|
||
|
||
## 2. 配置 Gitea Secrets
|
||
|
||
在 Gitea 仓库 Settings -> Secrets 中添加:
|
||
|
||
| Secret 名称 | 说明 |
|
||
|-------------|------|
|
||
| `GITEA_REGISTRY_TOKEN` | Gitea Container Registry 访问令牌 |
|
||
| `GITEA_REGISTRY_USER` | Registry 用户名 |
|
||
| `DB_PASSWORD` | PostgreSQL 数据库密码 |
|
||
| `PLATFORM_JWT_SECRET` | JWT 签名密钥(至少 32 字符)|
|
||
| `WEBHOOK_TOKEN` | Webhook x-bitanswer-token |
|
||
|
||
## 3. 推送仓库到 Gitea
|
||
|
||
```bash
|
||
# 添加 Gitea 远程仓库
|
||
git remote add gitea https://gitea.craftlabs.cn/craftlabs/authorization-sdk.git
|
||
|
||
# 推送到 Gitea
|
||
git push -u gitea develop
|
||
|
||
# 推送到 Gitea 并设为主分支
|
||
git push gitea develop:main
|
||
```
|
||
|
||
## 4. CI 流程说明
|
||
|
||
### 4.1 提交触发
|
||
|
||
| Workflow | 触发条件 | 运行内容 |
|
||
|----------|---------|---------|
|
||
| `ci-java` | push/PR to main/develop | Maven verify + Native 编译 |
|
||
| `ci-platform` | push/PR to main/develop (services/web) | Maven verify + npm build |
|
||
| `ci-security` | push/PR to main/develop | Trivy 漏洞扫描 + npm audit |
|
||
| `deploy` | push to main | 构建 Docker 镜像 → Gitea Registry → docker-compose 部署 |
|
||
|
||
### 4.2 手动触发
|
||
|
||
| Workflow | 触发方式 |
|
||
|----------|---------|
|
||
| `sdk-release-checksums` | 仓库 Actions 页面手动触发 |
|
||
| `deploy` | 仓库 Actions 页面手动触发 |
|
||
|
||
## 5. 部署架构
|
||
|
||
```text
|
||
┌─────────────────────────────────┐
|
||
│ Gitea 仓库(craftsupport.cn) │
|
||
│ push main → Gitea Actions │
|
||
└──────────┬──────────────────────┘
|
||
│ 触发
|
||
┌──────────▼──────────────────────┐
|
||
│ Self-Hosted Runner │
|
||
│ ├── mvn package → Docker build │
|
||
│ ├── npm build → Docker build │
|
||
│ └── docker compose up -d │
|
||
└──────────┬──────────────────────┘
|
||
│ 部署
|
||
┌──────────▼──────────────────────┐
|
||
│ 部署主机(生产环境) │
|
||
│ ├── PostgreSQL 15 │
|
||
│ ├── delivery-platform-api:8080 │
|
||
│ ├── license-webhook-ingress:8081│
|
||
│ └── delivery-platform-ui:80 │
|
||
└─────────────────────────────────┘
|
||
```
|
||
|
||
## 6. 环境变量要求
|
||
|
||
部署时需确保以下环境变量已设置:
|
||
|
||
```bash
|
||
# 数据库
|
||
SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/craftlabs_platform
|
||
SPRING_DATASOURCE_USERNAME=craftlabs
|
||
SPRING_DATASOURCE_PASSWORD=<实际密码>
|
||
|
||
# JWT
|
||
PLATFORM_JWT_SECRET=<至少32字符随机密钥>
|
||
|
||
# Webhook
|
||
CRAFTLABS_WEBHOOK_EXPECTED_TOKEN=<与比特控制台一致>
|
||
```
|