diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9709ad7..b4dc684 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,8 +14,19 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build-and-push: - runs-on: ubuntu-latest + build-arch: + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-latest + arch: amd64 + - platform: linux/arm64 + runner: [self-hosted, linux, arm64] + arch: arm64 + + runs-on: ${{ matrix.runner }} permissions: contents: read packages: write @@ -24,9 +35,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -37,7 +45,45 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker + - name: Extract Docker metadata for platform + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + suffix=-${{ matrix.arch }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/v') }} + + - name: Build and push by architecture + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: ${{ matrix.platform }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + merge-manifests: + needs: build-arch + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata for manifest list id: meta uses: docker/metadata-action@v5 with: @@ -48,14 +94,12 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/v') }} - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - platforms: linux/amd64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + - name: Create and push multi-arch manifest + run: | + for tag in ${{ steps.meta.outputs.tags }}; do + echo "Creating manifest for $tag..." + docker buildx imagetools create -t "$tag" \ + "${tag}-amd64" \ + "${tag}-arm64" + docker buildx imagetools inspect "$tag" + done diff --git a/README.md b/README.md index 2dd2b31..04f50f2 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,10 @@ docker build -t webman:8.2 . ### GitHub Actions 自动构建与发布 -已配置 `.github/workflows/build.yml`。每次推送到 `master` / `main` 或推送 tag(如 `v1.0.0`)时,GitHub Actions 会自动通过 QEMU + Buildx 构建多架构镜像(`linux/amd64` 与 `linux/arm64`),并发布到 GitHub Container Registry (GHCR): +已配置 `.github/workflows/build.yml`。采用**混合原生双架构矩阵构建**: +- **`linux/amd64`**:由 GitHub 云端 `ubuntu-latest` 原生构建 +- **`linux/arm64`**:由组织 Self-Hosted ARM Runner 原生硬件全速构建 +- 自动合并生成多架构 Manifest 并发布到 GitHub Container Registry (GHCR): -- **Registry**: `ghcr.io/567ai/webman-docker:latest`(或对应 tag 如 `:v1.0.0`) +- **Registry**: `ghcr.io/ai567-com/webman-docker:latest`(或对应 tag 如 `:v1.0.0`) - 无论是在 x86_64 服务器、云主机还是本地 Apple Silicon / ARM 设备上,Docker 都会自动拉取匹配本机架构的镜像运行。