构建并推送 Docker 镜像 (AMD64 & ARM64) / merge-manifests (push) Canceled after 0s
构建并推送 Docker 镜像 (AMD64 & ARM64) / build-arch (amd64, linux/amd64, amd64) (push) Canceled after 26m13s
构建并推送 Docker 镜像 (AMD64 & ARM64) / build-arch (arm64, linux/arm64, arm64) (push) Canceled after 26m10s
78 lines
2.3 KiB
YAML
78 lines
2.3 KiB
YAML
name: 构建并推送 Docker 镜像 (AMD64 & ARM64)
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY_HOST: git.openlocalpdf.com
|
|
IMAGE_REPO: ${{ gitea.repository }} # gitea/项目名,若项目名有大写需改为下方 tr 方案
|
|
|
|
jobs:
|
|
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:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: 设置 Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: 登录 Gitea 镜像仓库
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY_HOST }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: 构建并推送(单架构)
|
|
run: |
|
|
IMAGE_REPO=$(echo "${REGISTRY_HOST}/${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
TAGS="-t ${IMAGE_REPO}:latest-${{ matrix.arch }}"
|
|
if [[ "${{ gitea.ref }}" =~ ^refs/tags/ ]]; then
|
|
TAGS="${TAGS} -t ${IMAGE_REPO}:${{ gitea.ref_name }}-${{ matrix.arch }}"
|
|
fi
|
|
docker buildx build \
|
|
--platform linux/${{ matrix.arch }} \
|
|
${TAGS} \
|
|
--push \
|
|
-f Dockerfile .
|
|
|
|
merge-manifests:
|
|
needs: build-arch
|
|
runs-on: amd64
|
|
steps:
|
|
- name: 登录 Gitea 镜像仓库
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY_HOST }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- 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 |