|
33 | 33 | permissions: |
34 | 34 | contents: read |
35 | 35 | packages: write |
36 | | - strategy: |
37 | | - matrix: |
38 | | - include: |
39 | | - - platform: linux/amd64 |
40 | | - arch: amd64 |
41 | | - - platform: linux/arm64 |
42 | | - arch: arm64 |
43 | 36 |
|
44 | 37 | steps: |
45 | 38 | - name: 检出代码 |
@@ -73,21 +66,20 @@ jobs: |
73 | 66 | type=raw,value=latest,enable={{is_default_branch}} |
74 | 67 | type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} |
75 | 68 |
|
76 | | - - name: 构建并推送 Docker 镜像 (${{ matrix.arch }}) |
77 | | - if: matrix.arch == 'amd64' || (matrix.arch == 'arm64' && (github.event_name != 'workflow_dispatch' || github.event.inputs.build_arm64 == 'true')) |
| 69 | + - name: 构建并推送多架构 Docker 镜像 |
78 | 70 | uses: docker/build-push-action@v5 |
79 | 71 | with: |
80 | 72 | context: . |
81 | | - file: ${{ matrix.arch == 'arm64' && 'Dockerfile.arm64' || 'Dockerfile' }} |
82 | | - platforms: ${{ matrix.platform }} |
| 73 | + file: Dockerfile |
| 74 | + platforms: linux/amd64${{ (github.event_name != 'workflow_dispatch' || github.event.inputs.build_arm64 == 'true') && ',linux/arm64' || '' }} |
83 | 75 | push: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.push_to_registry == 'true' }} |
84 | 76 | tags: ${{ steps.meta.outputs.tags }} |
85 | 77 | labels: ${{ steps.meta.outputs.labels }} |
86 | | - cache-from: type=gha,scope=${{ matrix.arch }} |
87 | | - cache-to: type=gha,mode=max,scope=${{ matrix.arch }} |
| 78 | + cache-from: type=gha,scope=multi-arch |
| 79 | + cache-to: type=gha,mode=max,scope=multi-arch |
88 | 80 | build-args: | |
89 | | - BUILDPLATFORM=${{ matrix.platform }} |
90 | | - TARGETPLATFORM=${{ matrix.platform }} |
| 81 | + BUILDPLATFORM=linux/amd64 |
| 82 | + TARGETPLATFORM=linux/amd64 |
91 | 83 | outputs: type=registry |
92 | 84 | provenance: false |
93 | 85 | sbom: false |
|
98 | 90 | echo "## 🐳 Docker 镜像构建完成" >> $GITHUB_STEP_SUMMARY |
99 | 91 | echo "" >> $GITHUB_STEP_SUMMARY |
100 | 92 | echo "**触发方式:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY |
101 | | - echo "**构建架构:** ${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY |
| 93 | + echo "**构建架构:** multi-arch (amd64${{ (github.event_name != 'workflow_dispatch' || github.event.inputs.build_arm64 == 'true') && ' + arm64' || '' }})" >> $GITHUB_STEP_SUMMARY |
102 | 94 | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
103 | 95 | echo "**自定义标签:** ${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY |
104 | 96 | echo "**推送到注册表:** ${{ github.event.inputs.push_to_registry }}" >> $GITHUB_STEP_SUMMARY |
|
0 commit comments