From cdc9a7c94bd4dd99c89c33d60b0b8054acb456f7 Mon Sep 17 00:00:00 2001 From: "3371392206@qq.com" <3371392206@qq.com> Date: Thu, 27 Aug 2026 10:43:19 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20GitHub=20Actions=20D?= =?UTF-8?q?ocker=20=E5=8F=91=E5=B8=83=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 Gitea→GitHub 镜像 + GitHub 镜像仓库场景准备 Docker 镜像 自动构建和发布流程。 触发条件: - push tag v* (release 时打 tag 自动触发) - workflow_dispatch (手动触发,可在 GitHub UI 测试) 构建: - 多平台:linux/amd64 + linux/arm64 - 通过 QEMU + Buildx 跨架构构建 - 推送到 ghcr.io//volcano-engine-tts-ui - 双标签:语义版本 + 短 commit hash - OCI labels 包含 version 和 revision 与之前 version 包配合: workflow 用 git describe --tags --always --dirty 算 VERSION (commit hash 类似),通过 --build-arg 传给 Dockerfile, Dockerfile 用 -ldflags 注入到 version.Version / version.Commit 两个变量。最终 /health 端点返回构建时注入的真实版本信息。 前置条件(用户需自行完成): 1. GitHub 建镜像仓库 2. Gitea 配置 Push Mirror 到 GitHub(开启 Sync Tags) 3. 仓库设为 Public(否则 GHCR 镜像默认 private) --- .github/workflows/docker.yml | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..bc3a061 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,65 @@ +name: Docker Publish + +on: + push: + tags: + - 'v*' + workflow_dispatch: # 允许手动触发测试 + +env: + REGISTRY: ghcr.io + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # 拉完整历史,git describe 能取到 tag + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract version from git + id: version + run: | + echo "version=$(git describe --tags --always --dirty)" >> "$GITHUB_OUTPUT" + echo "commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=sha,format=short + labels: | + org.opencontainers.image.version=${{ steps.version.outputs.version }} + org.opencontainers.image.revision=${{ steps.version.outputs.commit }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ steps.version.outputs.version }} + COMMIT=${{ steps.version.outputs.commit }}