Merge pull request #2009 from seefs001/fix/ci

feat: matrix ci
This commit is contained in:
Seefs
2025-10-11 13:11:09 +08:00
committed by GitHub
2 changed files with 32 additions and 100 deletions

View File

@@ -42,6 +42,9 @@ jobs:
echo "VERSION=$VERSION" >> $GITHUB_ENV echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Publishing version: $VERSION for ${{ matrix.arch }}" echo "Publishing version: $VERSION for ${{ matrix.arch }}"
- name: Normalize GHCR repository
run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -64,7 +67,7 @@ jobs:
with: with:
images: | images: |
calciumion/new-api calciumion/new-api
ghcr.io/${{ github.repository }} ghcr.io/${{ env.GHCR_REPOSITORY }}
- name: Build & push single-arch (to both registries) - name: Build & push single-arch (to both registries)
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
@@ -75,8 +78,8 @@ jobs:
tags: | tags: |
calciumion/new-api:alpha-${{ matrix.arch }} calciumion/new-api:alpha-${{ matrix.arch }}
calciumion/new-api:${{ steps.version.outputs.value }}-${{ matrix.arch }} calciumion/new-api:${{ steps.version.outputs.value }}-${{ matrix.arch }}
ghcr.io/${{ github.repository }}:alpha-${{ matrix.arch }} ghcr.io/${{ env.GHCR_REPOSITORY }}:alpha-${{ matrix.arch }}
ghcr.io/${{ github.repository }}:${{ steps.version.outputs.value }}-${{ matrix.arch }} ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ steps.version.outputs.value }}-${{ matrix.arch }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
@@ -96,6 +99,9 @@ jobs:
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Normalize GHCR repository
run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Determine alpha version - name: Determine alpha version
id: version id: version
run: | run: |
@@ -133,13 +139,13 @@ jobs:
- name: Create & push manifest (GHCR - alpha) - name: Create & push manifest (GHCR - alpha)
run: | run: |
docker buildx imagetools create \ docker buildx imagetools create \
-t ghcr.io/${GITHUB_REPOSITORY}:alpha \ -t ghcr.io/${GHCR_REPOSITORY}:alpha \
ghcr.io/${GITHUB_REPOSITORY}:alpha-amd64 \ ghcr.io/${GHCR_REPOSITORY}:alpha-amd64 \
ghcr.io/${GITHUB_REPOSITORY}:alpha-arm64 ghcr.io/${GHCR_REPOSITORY}:alpha-arm64
- name: Create & push manifest (GHCR - versioned alpha) - name: Create & push manifest (GHCR - versioned alpha)
run: | run: |
docker buildx imagetools create \ docker buildx imagetools create \
-t ghcr.io/${GITHUB_REPOSITORY}:${VERSION} \ -t ghcr.io/${GHCR_REPOSITORY}:${VERSION} \
ghcr.io/${GITHUB_REPOSITORY}:${VERSION}-amd64 \ ghcr.io/${GHCR_REPOSITORY}:${VERSION}-amd64 \
ghcr.io/${GITHUB_REPOSITORY}:${VERSION}-arm64 ghcr.io/${GHCR_REPOSITORY}:${VERSION}-arm64

View File

@@ -1,41 +1,26 @@
name: Publish Docker image (Multi Registries, native amd64+arm64) name: Publish Docker image (Multi Registries)
on: on:
push: push:
tags: tags:
- '*' - '*'
jobs: jobs:
build_single_arch: push_to_registries:
name: Build & push (${{ matrix.arch }}) [native] name: Push Docker image to multiple registries
strategy: runs-on: ubuntu-latest
fail-fast: false
matrix:
include:
- arch: amd64
platform: linux/amd64
runner: ubuntu-latest
- arch: arm64
platform: linux/arm64
runner: ubuntu-24.04-arm64
runs-on: ${{ matrix.runner }}
permissions: permissions:
packages: write packages: write
contents: read contents: read
steps: steps:
- name: Check out (shallow) - name: Check out the repo
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Resolve tag & write VERSION - name: Save version info
run: | run: |
git fetch --tags --force --depth=1 git describe --tags > VERSION
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "$TAG" > VERSION - name: Set up QEMU
echo "Building tag: $TAG for ${{ matrix.arch }}" 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
@@ -46,14 +31,14 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR - name: Log in to the Container registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (labels) - name: Extract metadata (tags, labels) for Docker
id: meta id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
@@ -61,70 +46,11 @@ jobs:
calciumion/new-api calciumion/new-api
ghcr.io/${{ github.repository }} ghcr.io/${{ github.repository }}
- name: Build & push single-arch (to both registries) - name: Build and push Docker images
uses: docker/build-push-action@v6 uses: docker/build-push-action@v5
with: with:
context: . context: .
platforms: ${{ matrix.platform }} platforms: linux/amd64,linux/arm64
push: true push: true
tags: | tags: ${{ steps.meta.outputs.tags }}
calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }} labels: ${{ steps.meta.outputs.labels }}
calciumion/new-api:latest-${{ matrix.arch }}
ghcr.io/${{ github.repository }}:${{ env.TAG }}-${{ matrix.arch }}
ghcr.io/${{ github.repository }}:latest-${{ matrix.arch }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false
create_manifests:
name: Create multi-arch manifests (Docker Hub + GHCR)
needs: [build_single_arch]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Extract tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create & push manifest (Docker Hub - version)
run: |
docker buildx imagetools create \
-t calciumion/new-api:${TAG} \
calciumion/new-api:${TAG}-amd64 \
calciumion/new-api:${TAG}-arm64
- name: Create & push manifest (Docker Hub - latest)
run: |
docker buildx imagetools create \
-t calciumion/new-api:latest \
calciumion/new-api:latest-amd64 \
calciumion/new-api:latest-arm64
# ---- GHCR ----
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create & push manifest (GHCR - version)
run: |
docker buildx imagetools create \
-t ghcr.io/${GITHUB_REPOSITORY}:${TAG} \
ghcr.io/${GITHUB_REPOSITORY}:${TAG}-amd64 \
ghcr.io/${GITHUB_REPOSITORY}:${TAG}-arm64
- name: Create & push manifest (GHCR - latest)
run: |
docker buildx imagetools create \
-t ghcr.io/${GITHUB_REPOSITORY}:latest \
ghcr.io/${GITHUB_REPOSITORY}:latest-amd64 \
ghcr.io/${GITHUB_REPOSITORY}:latest-arm64