From 5d31cc8bbe52b121f4bcab0bf75a820969933afb Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 9 May 2025 21:20:31 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E7=9A=84tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 54 +++++++++++++++++------------- docker-compose.yml | 4 +-- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 605d838c..36c7604f 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,10 +6,9 @@ on: - main - classical - dev - - new_knowledge tags: - - 'v*' - workflow_dispatch: + - "v*.*.*" + - "v*" jobs: build-and-push: @@ -20,6 +19,11 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Clone maim_message run: git clone https://github.com/MaiM-with-u/maim_message maim_message @@ -29,6 +33,8 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + with: + buildkitd-flags: --debug - name: Login to Docker Hub uses: docker/login-action@v3 @@ -36,20 +42,18 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Determine Image Tags - id: tags - run: | - if [[ "${{ github.ref }}" == refs/tags/* ]]; then - echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:${{ github.ref_name }},${{ secrets.DOCKERHUB_USERNAME }}/maimbot:latest" >> $GITHUB_OUTPUT - elif [ "${{ github.ref }}" == "refs/heads/main" ]; then - echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:main,${{ secrets.DOCKERHUB_USERNAME }}/maimbot:main-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT - elif [ "${{ github.ref }}" == "refs/heads/classical" ]; then - echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:classical,${{ secrets.DOCKERHUB_USERNAME }}/maimbot:classical-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT - elif [ "${{ github.ref }}" == "refs/heads/dev" ]; then - echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:dev,${{ secrets.DOCKERHUB_USERNAME }}/maimbot:dev-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT - elif [ "${{ github.ref }}" == "refs/heads/new_knowledge" ]; then - echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:knowledge,${{ secrets.DOCKERHUB_USERNAME }}/maimbot:knowledge-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT - fi + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - name: Build and Push Docker Image uses: docker/build-push-action@v5 @@ -57,10 +61,14 @@ jobs: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 - tags: ${{ steps.tags.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }} push: true - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache,mode=max - labels: | - org.opencontainers.image.created=${{ steps.tags.outputs.date_tag }} - org.opencontainers.image.revision=${{ github.sha }} \ No newline at end of file + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:buildcache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:buildcache,mode=max + labels: ${{ steps.meta.outputs.labels }} + provenance: true + sbom: true + build-args: | + BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') + VCS_REF=${{ github.sha }} + outputs: type=image,push=true \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 000d00c3..363fafc2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: - maim_bot core: container_name: maim-bot-core - image: sengokucola/maimbot:main - # image: infinitycat/maimbot:main + image: sengokucola/maibot:main + # image: infinitycat/maibot:main environment: - TZ=Asia/Shanghai # - EULA_AGREE=35362b6ea30f12891d46ef545122e84a # 同意EULA From 3323c8dc498984cb938fc16f531dff05e8c5bc21 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 9 May 2025 21:42:00 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0docker-compose?= =?UTF-8?q?=E7=9A=84tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 363fafc2..2392f707 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,11 @@ services: - maim_bot core: container_name: maim-bot-core - image: sengokucola/maibot:main - # image: infinitycat/maibot:main + image: sengokucola/maibot:latest + # image: infinitycat/maibot:latest + # dev + # image: sengokucola/maibot:dev + # image: infinitycat/maibot:dev environment: - TZ=Asia/Shanghai # - EULA_AGREE=35362b6ea30f12891d46ef545122e84a # 同意EULA From 835efd5daae12ef268bb016d9e12f8e9a184fc9c Mon Sep 17 00:00:00 2001 From: infinitycat Date: Sat, 10 May 2025 01:41:56 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84Docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=A4=9A=E5=B9=B3=E5=8F=B0=E6=94=AF=E6=8C=81=E5=92=8C?= =?UTF-8?q?=E6=91=98=E8=A6=81=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 129 +++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 27 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 36c7604f..3fce193b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -10,20 +10,58 @@ on: - "v*.*.*" - "v*" +env: + REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/maibot + jobs: - build-and-push: + prepare: runs-on: ubuntu-latest - env: - DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USERNAME }} - DATE_TAG: $(date -u +'%Y-%m-%dT%H-%M-%S') + outputs: + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + bake-file: ${{ steps.meta.outputs.bake-file }} steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + build: + runs-on: ubuntu-latest + needs: prepare + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + - linux/386 + - linux/loong64 + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Clone maim_message run: git clone https://github.com/MaiM-with-u/maim_message maim_message @@ -31,6 +69,9 @@ jobs: - name: Clone lpmm run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: @@ -42,33 +83,67 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot - tags: | - type=ref,event=branch - type=ref,event=tag - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - - - name: Build and Push Docker Image + - name: Build and push by digest + id: build uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - push: true - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:buildcache - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:buildcache,mode=max - labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ matrix.platform }} + labels: ${{ needs.prepare.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }} + cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max provenance: true sbom: true build-args: | BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') VCS_REF=${{ github.sha }} - outputs: type=image,push=true \ No newline at end of file + outputs: type=image,push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p ${{ runner.temp }}/digests + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - prepare + - build + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${{ needs.prepare.outputs.tags }}") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + tags_json='${{ needs.prepare.outputs.tags }}' + first_tag=$(echo $tags_json | jq -r '.tags[0]') + docker buildx imagetools inspect $first_tag \ No newline at end of file From de1c36f8e8ee64dd0ea2abaca8782ab99b56f211 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Sat, 10 May 2025 01:46:17 +0800 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=E5=9C=A8Docker=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=94=AF=E6=8C=81=EF=BC=8C=E4=BB=A5=E4=BE=BF?= =?UTF-8?q?=E4=BA=8E=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 3fce193b..097fdac3 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -91,6 +91,7 @@ jobs: file: ./Dockerfile platforms: ${{ matrix.platform }} labels: ${{ needs.prepare.outputs.labels }} + tags: ${{ env.REGISTRY_IMAGE }}:${{ github.sha }}-${{ env.PLATFORM_PAIR }} cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }} cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max provenance: true From 4fc33278c98e9cf0d97b5a238f9ed69198de8bbf Mon Sep 17 00:00:00 2001 From: infinitycat Date: Sat, 10 May 2025 01:51:09 +0800 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=E7=B2=BE=E7=AE=80Docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 097fdac3..fb3d4938 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -48,10 +48,6 @@ jobs: platform: - linux/amd64 - linux/arm64 - - linux/arm/v7 - - linux/arm/v6 - - linux/386 - - linux/loong64 steps: - name: Prepare run: | @@ -91,7 +87,7 @@ jobs: file: ./Dockerfile platforms: ${{ matrix.platform }} labels: ${{ needs.prepare.outputs.labels }} - tags: ${{ env.REGISTRY_IMAGE }}:${{ github.sha }}-${{ env.PLATFORM_PAIR }} + tags: ${{ env.REGISTRY_IMAGE }} cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }} cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max provenance: true From f96fffe16eb8981f2c7f657effd1b503cdfadc0c Mon Sep 17 00:00:00 2001 From: infinitycat Date: Sat, 10 May 2025 02:00:59 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0Docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=A0=87=E7=AD=BE=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index fb3d4938..7ea9d86e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -136,8 +136,16 @@ jobs: - name: Create manifest list and push working-directory: ${{ runner.temp }}/digests run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${{ needs.prepare.outputs.tags }}") \ - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + # 确保至少有一个默认标签 + TAGS="-t ${{ env.REGISTRY_IMAGE }}:latest" + + # 如果 meta 输出的标签不为空,则使用它们 + if [ -n "${{ needs.prepare.outputs.tags }}" ]; then + TAGS=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${{ needs.prepare.outputs.tags }}") + fi + + echo "Using tags: ${TAGS}" + docker buildx imagetools create ${TAGS} $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) - name: Inspect image run: | From 5ad1993fee7d127b1af776e5816497169be24e14 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Sat, 10 May 2025 02:11:26 +0800 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96Docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E6=A0=87=E7=AD=BE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E9=BB=98=E8=AE=A4=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 7ea9d86e..a2e4cfc8 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -149,6 +149,20 @@ jobs: - name: Inspect image run: | - tags_json='${{ needs.prepare.outputs.tags }}' - first_tag=$(echo $tags_json | jq -r '.tags[0]') - docker buildx imagetools inspect $first_tag \ No newline at end of file + # 使用默认标签 + DEFAULT_TAG="${{ env.REGISTRY_IMAGE }}:latest" + + # 尝试从 prepare 输出中获取标签 + if [ -n "${{ needs.prepare.outputs.tags }}" ]; then + TAGS_JSON='${{ needs.prepare.outputs.tags }}' + FIRST_TAG=$(echo $TAGS_JSON | jq -r '.tags[0]') + if [ -n "$FIRST_TAG" ] && [ "$FIRST_TAG" != "null" ]; then + echo "使用从 metadata 获取的标签: $FIRST_TAG" + docker buildx imagetools inspect $FIRST_TAG + exit 0 + fi + fi + + # 如果没有标签或提取失败,使用默认标签 + echo "使用默认标签: $DEFAULT_TAG" + docker buildx imagetools inspect $DEFAULT_TAG \ No newline at end of file From 606b89c99b233426d90d3289418eec0476e5e27f Mon Sep 17 00:00:00 2001 From: infinitycat Date: Sat, 10 May 2025 02:37:46 +0800 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84Docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9EAMD64=E5=92=8CARM64=E6=9E=B6=E6=9E=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E5=A4=9A=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E6=B8=85=E5=8D=95=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 217 +++++++++++++++-------------- 1 file changed, 109 insertions(+), 108 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index a2e4cfc8..ba56b0c2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -10,50 +10,13 @@ on: - "v*.*.*" - "v*" -env: - REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/maibot - jobs: - prepare: + build-amd64: + name: Build AMD64 Image runs-on: ubuntu-latest - outputs: - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - bake-file: ${{ steps.meta.outputs.bake-file }} + env: + DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USERNAME }} steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY_IMAGE }} - tags: | - type=ref,event=branch - type=ref,event=tag - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - - build: - runs-on: ubuntu-latest - needs: prepare - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - - linux/arm64 - steps: - - name: Prepare - run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - - name: Checkout code uses: actions/checkout@v4 with: @@ -65,9 +28,6 @@ jobs: - name: Clone lpmm run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: @@ -79,50 +39,61 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push by digest - id: build + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Build and Push AMD64 Docker Image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile - platforms: ${{ matrix.platform }} - labels: ${{ needs.prepare.outputs.labels }} - tags: ${{ env.REGISTRY_IMAGE }} - cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }} - cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max + platforms: linux/amd64 + tags: ${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-${{ github.sha }} + push: true + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-buildcache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-buildcache,mode=max + labels: ${{ steps.meta.outputs.labels }} provenance: true sbom: true build-args: | BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') VCS_REF=${{ github.sha }} - outputs: type=image,push-by-digest=true,name-canonical=true,push=true + outputs: type=image,push=true - - name: Export digest - run: | - mkdir -p ${{ runner.temp }}/digests - digest="${{ steps.build.outputs.digest }}" - touch "${{ runner.temp }}/digests/${digest#sha256:}" - - - name: Upload digest - uses: actions/upload-artifact@v4 - with: - name: digests-${{ env.PLATFORM_PAIR }} - path: ${{ runner.temp }}/digests/* - if-no-files-found: error - retention-days: 1 - - merge: + build-arm64: + name: Build ARM64 Image runs-on: ubuntu-latest - needs: - - prepare - - build + env: + DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USERNAME }} steps: - - name: Download digests - uses: actions/download-artifact@v4 + - name: Checkout code + uses: actions/checkout@v4 with: - path: ${{ runner.temp }}/digests - pattern: digests-* - merge-multiple: true + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Clone maim_message + run: git clone https://github.com/MaiM-with-u/maim_message maim_message + + - name: Clone lpmm + run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + buildkitd-flags: --debug - name: Login to Docker Hub uses: docker/login-action@v3 @@ -130,39 +101,69 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - - name: Create manifest list and push - working-directory: ${{ runner.temp }}/digests - run: | - # 确保至少有一个默认标签 - TAGS="-t ${{ env.REGISTRY_IMAGE }}:latest" - - # 如果 meta 输出的标签不为空,则使用它们 - if [ -n "${{ needs.prepare.outputs.tags }}" ]; then - TAGS=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${{ needs.prepare.outputs.tags }}") - fi - - echo "Using tags: ${TAGS}" - docker buildx imagetools create ${TAGS} $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + - name: Build and Push ARM64 Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: linux/arm64 + tags: ${{ secrets.DOCKERHUB_USERNAME }}/maibot:arm64-${{ github.sha }} + push: true + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:arm64-buildcache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:arm64-buildcache,mode=max + labels: ${{ steps.meta.outputs.labels }} + provenance: true + sbom: true + build-args: | + BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') + VCS_REF=${{ github.sha }} + outputs: type=image,push=true - - name: Inspect image + create-manifest: + name: Create Multi-Arch Manifest + runs-on: ubuntu-latest + needs: + - build-amd64 + - build-arm64 + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Create and Push Manifest run: | - # 使用默认标签 - DEFAULT_TAG="${{ env.REGISTRY_IMAGE }}:latest" - - # 尝试从 prepare 输出中获取标签 - if [ -n "${{ needs.prepare.outputs.tags }}" ]; then - TAGS_JSON='${{ needs.prepare.outputs.tags }}' - FIRST_TAG=$(echo $TAGS_JSON | jq -r '.tags[0]') - if [ -n "$FIRST_TAG" ] && [ "$FIRST_TAG" != "null" ]; then - echo "使用从 metadata 获取的标签: $FIRST_TAG" - docker buildx imagetools inspect $FIRST_TAG - exit 0 - fi - fi - - # 如果没有标签或提取失败,使用默认标签 - echo "使用默认标签: $DEFAULT_TAG" - docker buildx imagetools inspect $DEFAULT_TAG \ No newline at end of file + # 为每个标签创建多架构镜像 + for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' '); do + echo "Creating manifest for $tag" + docker buildx imagetools create -t $tag \ + ${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-${{ github.sha }} \ + ${{ secrets.DOCKERHUB_USERNAME }}/maibot:arm64-${{ github.sha }} + done \ No newline at end of file