From c4518c3e28994135ab4d557591bfb4f3a8a39854 Mon Sep 17 00:00:00 2001 From: Antigravity Date: Thu, 22 Oct 2026 15:31:10 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E9=87=87=E7=94=A8=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E5=8F=8C=20Runner=20=E7=9F=A9=E9=98=B5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E4=B8=8E=20imagetools=20=E5=90=88=E5=B9=B6=E5=A4=9A=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 分别在 amd64 和 arm64 原生 runner 上并行构建 - 分别生成 -amd64 与 -arm64 架构镜像 - 通过 merge-manifests 任务合并为统一的多架构 manifest 清单 --- .gitea/workflows/docker-build.yml | 79 +++++++++++++++++++------------ 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index d64671a..c457ec4 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -9,45 +9,66 @@ on: - 'v*' workflow_dispatch: +env: + REGISTRY_HOST: git.openlocalpdf.com + IMAGE_REPO: ${{ gitea.repository }} # gitea/项目名,若项目名有大写需改为下方 tr 方案 + jobs: - build-and-push: - runs-on: ubuntu-latest + build-arch: + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: amd64 # 香港,原生 + arch: amd64 + - platform: linux/arm64 + runner: arm64 # 本机,原生 + arch: arm64 + runs-on: ${{ matrix.runner }} steps: - - name: 检出源码 - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: 设置 QEMU 跨架构仿真 (支持 ARM64 与 AMD64) - uses: docker/setup-qemu-action@v3 - with: - platforms: linux/amd64,linux/arm64 - - - name: 设置 Docker Buildx 构建器 + - name: 设置 Docker Buildx uses: docker/setup-buildx-action@v3 - - name: 登录 Gitea 镜像仓库 (Container Registry) + - name: 登录 Gitea 镜像仓库 run: | - # 提取 Gitea 主机名及端口 (去除协议头) - REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed -e 's|^[^/]*//||' -e 's|/.*$||') - echo "登录镜像仓库: ${REGISTRY_HOST}" - echo "${{ secrets.GITHUB_TOKEN }}" | docker login "${REGISTRY_HOST}" -u "${{ gitea.actor }}" --password-stdin + echo "${{ secrets.GITHUB_TOKEN }}" | docker login "${{ env.REGISTRY_HOST }}" \ + -u "${{ gitea.actor }}" --password-stdin - - name: 构建并推送多架构镜像 (linux/amd64, linux/arm64) + - name: 构建并推送(单架构) run: | - REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed -e 's|^[^/]*//||' -e 's|/.*$||') - # 镜像名称在 Docker 中必须全部小写 IMAGE_REPO=$(echo "${REGISTRY_HOST}/${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]') - - # 组装镜像标签 - TAG_ARGS="-t ${IMAGE_REPO}:latest" + TAGS="-t ${IMAGE_REPO}:latest-${{ matrix.arch }}" if [[ "${{ gitea.ref }}" =~ ^refs/tags/ ]]; then - VERSION_TAG="${{ gitea.ref_name }}" - TAG_ARGS="${TAG_ARGS} -t ${IMAGE_REPO}:${VERSION_TAG}" + TAGS="${TAGS} -t ${IMAGE_REPO}:${{ gitea.ref_name }}-${{ matrix.arch }}" fi - - echo "开始使用 Buildx 构建多架构镜像 (linux/amd64, linux/arm64)..." docker buildx build \ - --platform linux/amd64,linux/arm64 \ - ${TAG_ARGS} \ + --platform linux/${{ matrix.arch }} \ + ${TAGS} \ --push \ - . - echo "多架构镜像推送完成!" + -f Dockerfile . + + merge-manifests: + needs: build-arch + runs-on: amd64 + steps: + - name: 登录 Gitea 镜像仓库 + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login "${{ env.REGISTRY_HOST }}" \ + -u "${{ gitea.actor }}" --password-stdin + + - name: 合并多架构 manifest + run: | + IMAGE_REPO=$(echo "${REGISTRY_HOST}/${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]') + TAGS="latest" + if [[ "${{ gitea.ref }}" =~ ^refs/tags/ ]]; then + TAGS="${TAGS} ${{ gitea.ref_name }}" + fi + for tag in ${TAGS}; do + docker buildx imagetools create -t "${IMAGE_REPO}:${tag}" \ + "${IMAGE_REPO}:${tag}-amd64" \ + "${IMAGE_REPO}:${tag}-arm64" + docker buildx imagetools inspect "${IMAGE_REPO}:${tag}" + done \ No newline at end of file