From 2ae0a0336699c8b8d3ac1d36974a874cf617d0fb Mon Sep 17 00:00:00 2001 From: kuekhaoyang Date: Sun, 12 Jul 2026 01:38:19 +0800 Subject: [PATCH] ci build Docker architectures natively --- .github/workflows/docker-publish.yml | 89 ++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 9badab7..7ffad71 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -14,8 +14,10 @@ concurrency: cancel-in-progress: true jobs: - publish: + prepare: runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.value }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -27,8 +29,22 @@ jobs: VERSION="$(node -p "require('./package.json').version")" echo "value=$VERSION" >> "$GITHUB_OUTPUT" - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + build: + needs: prepare + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-latest + platform: linux/amd64 + artifact: amd64 + - runner: ubuntu-24.04-arm + platform: linux/arm64 + artifact: arm64 + runs-on: ${{ matrix.runner }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -39,14 +55,67 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push multi-architecture image + - name: Build and push architecture image by digest + id: build uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64,linux/arm64 + platforms: ${{ matrix.platform }} push: true - tags: | - kuekhaoyang/kvideo:${{ steps.version.outputs.value }} - kuekhaoyang/kvideo:latest - cache-from: type=gha - cache-to: type=gha,mode=max + outputs: type=image,name=kuekhaoyang/kvideo,push-by-digest=true,name-canonical=true,push=true + cache-from: type=gha,scope=${{ matrix.artifact }} + cache-to: type=gha,mode=max,scope=${{ matrix.artifact }} + + - name: Export digest + shell: bash + env: + DIGEST: ${{ steps.build.outputs.digest }} + run: | + mkdir -p /tmp/digests + touch "/tmp/digests/${DIGEST#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digest-${{ matrix.artifact }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + needs: + - prepare + - build + runs-on: ubuntu-latest + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + pattern: digest-* + path: /tmp/digests + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create and push multi-architecture tags + working-directory: /tmp/digests + shell: bash + env: + VERSION: ${{ needs.prepare.outputs.version }} + run: | + docker buildx imagetools create \ + --tag "kuekhaoyang/kvideo:$VERSION" \ + --tag "kuekhaoyang/kvideo:latest" \ + $(printf 'kuekhaoyang/kvideo@sha256:%s ' *) + + - name: Inspect published image + env: + VERSION: ${{ needs.prepare.outputs.version }} + run: docker buildx imagetools inspect "kuekhaoyang/kvideo:$VERSION"