ci: 启用混合原生双架构构建 (GitHub构建amd64, 自建ARM节点构建arm64)

This commit is contained in:
Antigravity committed 2026-09-19 15:45:41 +08:00
1 parent 081ae5a903
commit 88b4f97a26
2 files changed
+66 -19

No files matched your search

+61 -17
View File
@@ -14,8 +14,19 @@ env:
IMAGE_NAME: ${{ github.repository }} IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
build-and-push: build-arch:
runs-on: ubuntu-latest 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: permissions:
contents: read contents: read
packages: write packages: write
@@ -24,9 +35,6 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -37,7 +45,45 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} 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 id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
@@ -48,14 +94,12 @@ jobs:
type=semver,pattern={{major}}.{{minor}} 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') }} 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 - name: Create and push multi-arch manifest
uses: docker/build-push-action@v5 run: |
with: for tag in ${{ steps.meta.outputs.tags }}; do
context: . echo "Creating manifest for $tag..."
file: ./Dockerfile docker buildx imagetools create -t "$tag" \
platforms: linux/amd64 "${tag}-amd64" \
push: true "${tag}-arm64"
tags: ${{ steps.meta.outputs.tags }} docker buildx imagetools inspect "$tag"
labels: ${{ steps.meta.outputs.labels }} done
cache-from: type=gha
cache-to: type=gha,mode=max
+5 -2
View File
@@ -19,7 +19,10 @@ docker build -t webman:8.2 .
### GitHub Actions 自动构建与发布 ### 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 都会自动拉取匹配本机架构的镜像运行。 - 无论是在 x86_64 服务器、云主机还是本地 Apple Silicon / ARM 设备上,Docker 都会自动拉取匹配本机架构的镜像运行。