ci(infra): 完整 CI/CD 流水线配置

- ci-ts.yml: lint/typecheck/test/build + arch-scan + docker-build(classes + teacher-portal)

- ci-go.yml: vet/build/test + docker-build(api-gateway)

- ci-proto.yml: buf lint + buf breaking(本地 .git 比较)

- docker.yml: main/tag 触发,构建推送 3 服务镜像到 Gitea Registry

- deploy.yml: workflow_dispatch + workflow_run 触发,Runner 直接 docker compose 部署,含健康检查与回滚

- 所有 workflow runs-on: ubuntu-latest 匹配 actrunner 标签
This commit is contained in:
SpecialX
2026-07-08 15:13:53 +08:00
parent 4a0893ef52
commit 3b88e9cca5
5 changed files with 306 additions and 12 deletions

84
.github/workflows/docker.yml vendored Normal file
View File

@@ -0,0 +1,84 @@
name: Docker Build & Push
# 触发条件main 分支推送 或 打 v* tag
# 镜像推送到 Gitea Container Registry: git.eazygame.cn/xiner/edu/<service>:<tag>
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
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
- uses: docker/setup-buildx-action@v3
# 登录 Gitea Container Registry
# GITHUB_TOKEN 由 Gitea Actions 自动注入,对应仓库写权限
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 生成镜像 tag
# main 分支latest + git-sha
# v* tagv<version> + latest
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.REPO_LOWER }}/${{ matrix.service.name }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix={{branch}}-,enable={{is_default_branch}}
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=ref,event=branch
- name: Build and push ${{ matrix.service.name }}
uses: docker/build-push-action@v5
with:
context: ${{ matrix.service.context }}
file: ${{ matrix.service.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- 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