refactor(infra): 重构为 no-push 本地构建部署模式
Some checks failed
CI / quality-go (push) Failing after 3s
CI / quality-proto (push) Failing after 2s
CI / quality-ts (push) Failing after 47s
CI / deploy (push) Has been skipped

- 删除 6 个分散 workflow(ci-ts/ci-go/ci-proto/ci-py/docker/deploy)
- 合并为单个 ci.yml:3 个 quality job 并行 + deploy job 串行
- 全部使用官方镜像(node:22-alpine/golang:1.22-alpine/bufbuild/buf/docker:25-git)
- deploy job 用 DooD 模式挂载 /var/run/docker.sock
- docker-compose.deploy.yml 改用 build: 替代 image:(no-push)
- 新增 docker-compose.tools.yml 一次性预拉所有 CI 镜像
- 支持 workflow_dispatch 指定 commit_sha 回滚
- 更新 project_rules §15 与 cicd-runbook.md 为 no-push 模式
- 新增设计文档 docs/superpowers/specs/2026-07-08-cicd-no-push-local-build-design.md
This commit is contained in:
SpecialX
2026-07-08 17:12:57 +08:00
parent a1d7fcfd71
commit 68ddff1065
12 changed files with 613 additions and 812 deletions

View File

@@ -1,60 +0,0 @@
name: CI Go
# 参考实现E:\Desktop\CICD\.gitea\workflows\ci.yml
# Go 服务分两阶段:
# - quality: golang:1.22-alpine 容器(不需要 docker
# - docker-build: dockerreg.eazygame.cn/node-with-docker:22 + setup-go需要 docker 命令)
# 详见 docs/standards/cicd-runbook.md §10、project_rules §15.7
on:
push:
branches: [main]
paths:
- 'services/api-gateway/**'
- 'services/push-gateway/**'
- 'packages/shared-go/**'
- 'go.work'
- '.github/workflows/ci-go.yml'
pull_request:
branches: [main]
paths:
- 'services/api-gateway/**'
- 'services/push-gateway/**'
- 'packages/shared-go/**'
- 'go.work'
- '.github/workflows/ci-go.yml'
jobs:
quality:
runs-on: ubuntu-latest
container: golang:1.22-alpine
defaults:
run:
working-directory: services/api-gateway
steps:
- uses: actions/checkout@v4
- name: Download deps
run: go mod download
- name: Vet
run: go vet ./...
- name: Build
run: go build ./...
- name: Test
run: go test ./... -v -coverprofile=coverage.out
docker-build:
runs-on: ubuntu-latest
container: dockerreg.eazygame.cn/node-with-docker:22
needs: quality
steps:
- uses: actions/checkout@v4
- name: Build api-gateway
run: |
docker build \
-t edu/api-gateway:ci \
-f services/api-gateway/Dockerfile \
services/api-gateway

View File

@@ -1,25 +0,0 @@
name: CI Proto
on:
push:
branches: [main]
paths:
- 'packages/shared-proto/**'
pull_request:
branches: [main]
paths:
- 'packages/shared-proto/**'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1
- name: buf lint
working-directory: packages/shared-proto
run: buf lint
- name: buf breaking
if: github.event_name == 'pull_request'
working-directory: packages/shared-proto
run: buf breaking --against .git#branch=main,subdir=packages/shared-proto

View File

@@ -1,33 +0,0 @@
name: CI Python
on:
push:
branches: [main]
paths:
- 'services/data-ana/**'
- 'services/ai/**'
- 'packages/shared-py/**'
- 'pyproject.toml'
pull_request:
branches: [main]
paths:
- 'services/data-ana/**'
- 'services/ai/**'
- 'packages/shared-py/**'
- 'pyproject.toml'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: astral-sh/setup-uv@v3
- name: Install
run: uv sync
- name: Lint (ruff)
run: uv run ruff check .
- name: Test
run: uv run pytest

View File

@@ -1,98 +0,0 @@
name: CI TypeScript
# 参考实现E:\Desktop\CICD\.gitea\workflows\ci.yml
# 关键配置container: dockerreg.eazygame.cn/node-with-docker:22带 docker 的 node 22
# 详见 docs/standards/cicd-runbook.md §10、project_rules §15.7
on:
push:
branches: [main]
paths:
- 'services/classes/**'
- 'apps/**'
- 'packages/**'
- 'scripts/**'
- 'package.json'
- 'pnpm-workspace.yaml'
- 'tsconfig.base.json'
- '.github/workflows/ci-ts.yml'
pull_request:
branches: [main]
paths:
- 'services/classes/**'
- 'apps/**'
- 'packages/**'
- 'scripts/**'
- 'package.json'
- 'pnpm-workspace.yaml'
- 'tsconfig.base.json'
- '.github/workflows/ci-ts.yml'
env:
SKIP_ENV_VALIDATION: '1'
NEXT_TELEMETRY_DISABLED: '1'
jobs:
quality:
runs-on: ubuntu-latest
container: dockerreg.eazygame.cn/node-with-docker:22
steps:
- uses: actions/checkout@v4
- name: Install pnpm
run: npm install -g pnpm@9
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm -r run lint
continue-on-error: true # P1: ESLint 9 flat config 迁移未完成
- name: Typecheck
run: pnpm -r run typecheck
- name: Test
run: pnpm -r run test
continue-on-error: true # P1: 部分服务无 test 脚本
- name: Build
run: pnpm -r run build
arch-scan:
runs-on: ubuntu-latest
container: dockerreg.eazygame.cn/node-with-docker:22
needs: quality
steps:
- uses: actions/checkout@v4
- name: Install pnpm
run: npm install -g pnpm@9
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: arch:scan
run: pnpm run arch:scan
- name: Verify arch.db committed
run: |
if git diff --quiet -- scripts/arch-scan/arch.db; then
echo "arch.db up to date"
else
echo "::warning::arch.db 未同步,请运行 pnpm run arch:scan 并提交"
fi
docker-build:
runs-on: ubuntu-latest
container: dockerreg.eazygame.cn/node-with-docker:22
needs: quality
strategy:
matrix:
service:
- { name: classes, dockerfile: services/classes/Dockerfile, context: . }
- { name: teacher-portal, dockerfile: apps/teacher-portal/Dockerfile, context: . }
steps:
- uses: actions/checkout@v4
- name: Build ${{ matrix.service.name }}
run: |
docker build \
-t edu/${{ matrix.service.name }}:ci \
-f ${{ matrix.service.dockerfile }} \
${{ matrix.service.context }}

197
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,197 @@
name: CI
# CI/CD 一体化流水线no-push 本地构建部署)
# 设计文档docs/superpowers/specs/2026-07-08-cicd-no-push-local-build-design.md
#
# 流程:
# PR 触发:仅跑 3 个 quality job并行
# push main 触发quality job 全绿后跑 deploy job本地 build + compose up
# workflow_dispatch支持指定 commit_sha 回滚
#
# 不依赖任何自建镜像,全部使用官方镜像
# 不推送镜像到 registry构建即部署
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
commit_sha:
description: '回滚到指定 commit留空则部署当前 HEAD'
required: false
default: ''
env:
SKIP_ENV_VALIDATION: '1'
NEXT_TELEMETRY_DISABLED: '1'
jobs:
# ===== TypeScript 质量检查 =====
quality-ts:
runs-on: ubuntu-latest
container: node:22-alpine
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit_sha || github.ref }}
- name: Install pnpm
run: npm install -g pnpm@9
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm -r run lint
continue-on-error: true # P1: ESLint 9 flat config 迁移未完成
- name: Typecheck
run: pnpm -r run typecheck
- name: Test
run: pnpm -r run test
continue-on-error: true # P1: 部分服务无 test 脚本
- name: Build
run: pnpm -r run build
# ===== Go 质量检查 =====
quality-go:
runs-on: ubuntu-latest
container: golang:1.22-alpine
defaults:
run:
working-directory: services/api-gateway
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit_sha || github.ref }}
- name: Download deps
run: go mod download
- name: Vet
run: go vet ./...
- name: Build
run: go build ./...
- name: Test
run: go test ./... -v -coverprofile=coverage.out
# ===== Proto 契约检查 =====
quality-proto:
runs-on: ubuntu-latest
container: bufbuild/buf:latest
defaults:
run:
working-directory: packages/shared-proto
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit_sha || github.ref }}
fetch-depth: 0 # buf breaking 需要对比分支
- name: buf lint
run: buf lint
- name: buf breaking
if: github.event_name == 'pull_request'
run: buf breaking --against .git#branch=main,subdir=packages/shared-proto
# ===== 部署(仅 push main 或手动触发)=====
deploy:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: [quality-ts, quality-go, quality-proto]
runs-on: ubuntu-latest
container: docker:25-git
options: --volume /var/run/docker.sock:/var/run/docker.sock
environment:
name: production
env:
DEPLOY_DIR: /opt/edu
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit_sha || github.ref }}
- name: Setup deploy dir
run: |
# 同步整个仓库到部署目录的 repo/ 子目录
# compose 文件中 build.context 指向 ./repo/services/... 或 ./repo
mkdir -p ${{ env.DEPLOY_DIR }}/repo
cp -a $GITHUB_WORKSPACE/. ${{ env.DEPLOY_DIR }}/repo/
cp infra/docker-compose.deploy.yml ${{ env.DEPLOY_DIR }}/docker-compose.yml
# 确保 .env 存在(首次部署需人工创建)
if [ ! -f ${{ env.DEPLOY_DIR }}/.env ]; then
echo "::error::部署目录缺少 .env 文件,请参考 infra/deploy.env.example 创建"
exit 1
fi
- name: Deploy services (local build, no push)
run: |
cd ${{ env.DEPLOY_DIR }}
echo "=== 构建并启动服务 ==="
# --build 使用本地 Dockerfile 构建,不拉取 registry
# build.context 在 compose 中指向 ./repo/...(相对于 /opt/edu/
docker compose up -d --build --remove-orphans
- name: Wait for health
run: |
echo "等待服务健康..."
sleep 10
for i in 1 2 3 4 5 6 7 8 9 10; do
FAIL=0
echo "[尝试 $i] 检查 api-gateway..."
if ! wget -q --spider http://localhost:8080/healthz 2>/dev/null; then
echo " api-gateway 未就绪"
FAIL=1
fi
echo "[尝试 $i] 检查 classes..."
if ! wget -q --spider http://localhost:3001/healthz 2>/dev/null; then
echo " classes 未就绪"
FAIL=1
fi
echo "[尝试 $i] 检查 teacher-portal..."
if ! wget -q --spider http://localhost:3000/ 2>/dev/null; then
echo " teacher-portal 未就绪"
FAIL=1
fi
if [ $FAIL -eq 0 ]; then
echo "✅ 所有服务健康"
exit 0
fi
sleep 6
done
echo "::error::服务健康检查失败"
echo "=== 容器状态 ==="
cd ${{ env.DEPLOY_DIR }} && docker compose ps
echo "=== api-gateway 日志 ==="
docker compose logs --tail=50 api-gateway
echo "=== classes 日志 ==="
docker compose logs --tail=50 classes
echo "=== teacher-portal 日志 ==="
docker compose logs --tail=50 teacher-portal
exit 1
- name: Summary
if: always()
run: |
echo "### 部署结果" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- 触发事件:\`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "- 部署 commit\`${{ github.event.inputs.commit_sha || github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "- 部署目录:\`${{ env.DEPLOY_DIR }}\`" >> $GITHUB_STEP_SUMMARY
echo "- 部署方式本地构建no-push" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cd ${{ env.DEPLOY_DIR }} && docker compose ps >> $GITHUB_STEP_SUMMARY 2>&1 || true

View File

@@ -1,145 +0,0 @@
name: Deploy
# 参考实现E:\Desktop\CICD\.gitea\workflows\ci.yml
# 关键配置container: dockerreg.eazygame.cn/node-with-docker:22job 内执行 docker compose
# 部署到服务器
# 触发条件main 分支 docker.yml 完成后 自动,或手动 workflow_dispatch
# 部署方式Runner 直接执行 docker composeRunner 跑在服务器上)
#
# 前置条件(一次性配置):
# 1. 服务器上已安装 Gitea Actions Runner标签为 'ubuntu-latest'
# 2. 服务器上已存在 /opt/edu/docker-compose.deploy.yml由 SRE AI 首次部署)
# 3. 服务器上已存在 /opt/edu/.env含生产 JWT_SECRET 等)
# 4. 服务器 Docker 已登录 Gitea Container Registry
# docker login git.eazygame.cn -u <user> -p <token>
# 5. MySQL + Redis 已在服务器 Docker 中运行3306/6379
# 详见 docs/standards/cicd-runbook.md §10、project_rules §15.7
on:
workflow_dispatch:
inputs:
image_tag:
description: '镜像 tag默认 latest'
required: false
default: 'latest'
rollback:
description: '回滚到上一版本(跳过 pull'
type: boolean
required: false
default: false
workflow_run:
workflows: ['Docker Build & Push']
types: [completed]
branches: [main]
permissions:
contents: read
env:
DEPLOY_DIR: /opt/edu
REGISTRY: git.eazygame.cn
IMAGE_TAG: ${{ github.event.inputs.image_tag || 'latest' }}
jobs:
deploy:
# 仅在 docker.yml 成功后触发,或手动触发
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
container: dockerreg.eazygame.cn/node-with-docker:22
environment:
name: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup deploy dir
run: |
sudo mkdir -p ${{ env.DEPLOY_DIR }}
sudo chown -R $(id -u):$(id -g) ${{ env.DEPLOY_DIR }}
- name: Sync compose file
run: |
cp infra/docker-compose.deploy.yml ${{ env.DEPLOY_DIR }}/docker-compose.yml
# 确保 .env 存在(首次部署需人工创建)
if [ ! -f ${{ env.DEPLOY_DIR }}/.env ]; then
echo "::error::部署目录缺少 .env 文件,请参考 infra/deploy.env.example 创建"
exit 1
fi
- name: Login to Gitea Container Registry
run: |
# 使用预存的 ~/.docker/config.json首次部署时人工 docker login
# 或使用 secrets 注入
if [ -n "${{ secrets.GITEA_REGISTRY_TOKEN }}" ]; then
echo "${{ secrets.GITEA_REGISTRY_TOKEN }}" | \
docker login ${{ env.REGISTRY }} -u ${{ secrets.GITEA_REGISTRY_USER }} --password-stdin
fi
- name: Pull images
if: ${{ github.event.inputs.rollback != 'true' }}
run: |
cd ${{ env.DEPLOY_DIR }}
export IMAGE_TAG=${{ env.IMAGE_TAG }}
docker compose pull
continue-on-error: true # 首次部署可能无旧镜像
- name: Deploy services
run: |
cd ${{ env.DEPLOY_DIR }}
export IMAGE_TAG=${{ env.IMAGE_TAG }}
docker compose up -d --remove-orphans
- name: Wait for health
run: |
echo "等待服务健康..."
sleep 10
for i in 1 2 3 4 5 6 7 8 9 10; do
FAIL=0
echo "[尝试 $i] 检查 api-gateway..."
if ! curl -sf http://localhost:8080/healthz > /dev/null; then
echo " api-gateway 未就绪"
FAIL=1
fi
echo "[尝试 $i] 检查 classes..."
if ! curl -sf http://localhost:3001/healthz > /dev/null; then
echo " classes 未就绪"
FAIL=1
fi
echo "[尝试 $i] 检查 teacher-portal..."
if ! curl -sf http://localhost:3000/ > /dev/null; then
echo " teacher-portal 未就绪"
FAIL=1
fi
if [ $FAIL -eq 0 ]; then
echo "✅ 所有服务健康"
exit 0
fi
sleep 6
done
echo "::error::服务健康检查失败"
echo "=== 容器状态 ==="
cd ${{ env.DEPLOY_DIR }} && docker compose ps
echo "=== api-gateway 日志 ==="
docker compose logs --tail=50 api-gateway
echo "=== classes 日志 ==="
docker compose logs --tail=50 classes
exit 1
- name: Summary
if: always()
run: |
echo "### 部署结果" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- 镜像 tag\`${{ env.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
echo "- 部署目录:\`${{ env.DEPLOY_DIR }}\`" >> $GITHUB_STEP_SUMMARY
echo "- 回滚模式:${{ github.event.inputs.rollback || 'false' }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cd ${{ env.DEPLOY_DIR }} && docker compose ps >> $GITHUB_STEP_SUMMARY 2>&1 || true

View File

@@ -1,92 +0,0 @@
name: Docker Build & Push
# 参考实现E:\Desktop\CICD\.gitea\workflows\ci.yml
# 关键配置container: dockerreg.eazygame.cn/node-with-docker:22job 内执行 docker build/push
# 触发条件main 分支推送 或 打 v* tag
# 镜像推送到 Gitea Container Registry: git.eazygame.cn/xiner/edu/<service>:<tag>
# 详见 docs/standards/cicd-runbook.md §10、project_rules §15.7
on:
push:
branches: [main]
paths:
- 'services/api-gateway/**'
- 'services/classes/**'
- 'apps/teacher-portal/**'
- 'packages/shared-proto/**'
- '.github/workflows/docker.yml'
tags:
- 'v*'
permissions:
packages: write
contents: read
env:
REGISTRY: git.eazygame.cn
OWNER: xiner
REPO_LOWER: edu
jobs:
build-push:
runs-on: ubuntu-latest
container: dockerreg.eazygame.cn/node-with-docker:22
strategy:
matrix:
service:
- { name: api-gateway, dockerfile: services/api-gateway/Dockerfile, context: ./services/api-gateway }
- { name: classes, dockerfile: services/classes/Dockerfile, context: . }
- { name: teacher-portal, dockerfile: apps/teacher-portal/Dockerfile, context: . }
steps:
- uses: actions/checkout@v4
# 登录 Gitea Container Registry
# GITHUB_TOKEN 由 Gitea Actions 自动注入,对应仓库写权限
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
# 生成镜像 tag
# main 分支latest + git-sha
# v* tagv<version> + latest
- name: Extract metadata
id: meta
run: |
TAGS="${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.REPO_LOWER }}/${{ matrix.service.name }}:latest"
SHA_TAG="${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.REPO_LOWER }}/${{ matrix.service.name }}:sha-${GITHUB_SHA::7}"
TAGS="$TAGS,$SHA_TAG"
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
TAGS="$TAGS,${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.REPO_LOWER }}/${{ matrix.service.name }}:v${VERSION}"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "Resolved tags: $TAGS"
- name: Build and push ${{ matrix.service.name }}
run: |
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.meta.outputs.tags }}"
TAG_ARGS=""
for tag in "${TAG_ARRAY[@]}"; do
TAG_ARGS="$TAG_ARGS -t $tag"
done
docker build \
$TAG_ARGS \
-f ${{ matrix.service.dockerfile }} \
${{ matrix.service.context }}
for tag in "${TAG_ARRAY[@]}"; do
echo "Pushing $tag..."
docker push $tag
done
- name: Summary
run: |
echo "### Docker 镜像已推送" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "服务:\`${{ matrix.service.name }}\`" >> $GITHUB_STEP_SUMMARY
echo "镜像标签:" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY