Build and Push Multi-Arch Docker Image / build-arch (amd64, linux/amd64, amd64) (push) Failing after 3m41s
Build and Push Multi-Arch Docker Image / build-arch (arm64, linux/arm64, arm64) (push) Failing after 5m38s
Build and Push Multi-Arch Docker Image / merge-manifests (push) Skipped
将多架构构建切换到 amd64 和 arm64 Runner, 并明确 master、main 分支及版本标签的 latest 镜像规则。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
99 lines
3.0 KiB
YAML
99 lines
3.0 KiB
YAML
name: Build and Push Multi-Arch Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: git.openlocalpdf.com
|
|
IMAGE_NAME: ${{ gitea.repository }}
|
|
|
|
jobs:
|
|
build-arch:
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- platform: linux/amd64
|
|
runner: amd64 # 香港 runner,原生编译
|
|
arch: amd64
|
|
- platform: linux/arm64
|
|
runner: arm64 # 本机 runner,原生编译
|
|
arch: arm64
|
|
|
|
runs-on: ${{ matrix.runner }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Extract Docker metadata for platform
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
flavor: |
|
|
suffix=-${{ matrix.arch }},onlatest=true
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=raw,value=latest,enable=${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/main' || startsWith(gitea.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: amd64
|
|
steps:
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Extract Docker metadata for manifest list
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=raw,value=latest,enable=${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/main' || startsWith(gitea.ref, 'refs/tags/v') }}
|
|
|
|
- name: Create and push multi-arch manifest
|
|
env:
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
for tag in ${TAGS}; do
|
|
echo "Creating manifest for $tag..."
|
|
docker buildx imagetools create -t "$tag" \
|
|
"${tag}-amd64" \
|
|
"${tag}-arm64"
|
|
docker buildx imagetools inspect "$tag"
|
|
done |