1717 required : true
1818 default : true
1919 type : boolean
20+ build_arm64 :
21+ description : ' 构建 ARM64 架构 (较慢)'
22+ required : true
23+ default : false
24+ type : boolean
2025
2126env :
2227 REGISTRY : ghcr.io
@@ -28,13 +33,24 @@ jobs:
2833 permissions :
2934 contents : read
3035 packages : write
36+ strategy :
37+ matrix :
38+ include :
39+ - platform : linux/amd64
40+ arch : amd64
41+ - platform : linux/arm64
42+ arch : arm64
3143
3244 steps :
3345 - name : 检出代码
3446 uses : actions/checkout@v4
3547
3648 - name : 设置 Docker Buildx
3749 uses : docker/setup-buildx-action@v3
50+ with :
51+ driver-opts : |
52+ image=moby/buildkit:buildx-stable-1
53+ network=host
3854
3955 - name : 登录到 GitHub Container Registry
4056 uses : docker/login-action@v3
@@ -57,26 +73,36 @@ jobs:
5773 type=raw,value=latest,enable={{is_default_branch}}
5874 type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
5975
60- - name : 构建并推送 Docker 镜像
76+ - name : 构建并推送 Docker 镜像 (${{ matrix.arch }})
77+ if : matrix.arch == 'amd64' || (matrix.arch == 'arm64' && (github.event_name != 'workflow_dispatch' || github.event.inputs.build_arm64 == 'true'))
6178 uses : docker/build-push-action@v5
6279 with :
6380 context : .
64- platforms : linux/amd64,linux/arm64
81+ file : ${{ matrix.arch == 'arm64' && 'Dockerfile.arm64' || 'Dockerfile' }}
82+ platforms : ${{ matrix.platform }}
6583 push : ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.push_to_registry == 'true' }}
6684 tags : ${{ steps.meta.outputs.tags }}
6785 labels : ${{ steps.meta.outputs.labels }}
68- cache-from : type=gha
69- cache-to : type=gha,mode=max
86+ cache-from : type=gha,scope=${{ matrix.arch }}
87+ cache-to : type=gha,mode=max,scope=${{ matrix.arch }}
88+ build-args : |
89+ BUILDPLATFORM=${{ matrix.platform }}
90+ TARGETPLATFORM=${{ matrix.platform }}
91+ outputs : type=registry
92+ provenance : false
93+ sbom : false
7094
7195 - name : 生成摘要
7296 if : github.event_name == 'push' || github.event_name == 'workflow_dispatch'
7397 run : |
7498 echo "## 🐳 Docker 镜像构建完成" >> $GITHUB_STEP_SUMMARY
7599 echo "" >> $GITHUB_STEP_SUMMARY
76100 echo "**触发方式:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
101+ echo "**构建架构:** ${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY
77102 if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
78103 echo "**自定义标签:** ${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY
79104 echo "**推送到注册表:** ${{ github.event.inputs.push_to_registry }}" >> $GITHUB_STEP_SUMMARY
105+ echo "**构建 ARM64:** ${{ github.event.inputs.build_arm64 }}" >> $GITHUB_STEP_SUMMARY
80106 fi
81107 echo "" >> $GITHUB_STEP_SUMMARY
82108 echo "**镜像标签:**" >> $GITHUB_STEP_SUMMARY
0 commit comments