Skip to content

Commit e331633

Browse files
committed
Add dynamic CPU allocation for Docker builds in multiarch workflow
1 parent 3f5fc19 commit e331633

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

.github/workflows/multiarch.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ jobs:
8989
username: ${{ secrets.DOCKERHUB_LOGIN }}
9090
password: ${{ secrets.DOCKERHUB_TOKEN }}
9191

92+
- name: Set build parameters
93+
id: build-params
94+
run: |
95+
# Get available CPUs, use 75% for build, minimum 2
96+
AVAILABLE_CPUS=$(nproc)
97+
OPTIMAL_NPROC=$(( AVAILABLE_CPUS * 3 / 4 ))
98+
OPTIMAL_NPROC=$(( OPTIMAL_NPROC > 1 ? OPTIMAL_NPROC : 2 ))
99+
100+
# ARM architectures might need special handling
101+
if [[ "${{ matrix.arch }}" == *"arm"* ]]; then
102+
# For ARM, be more conservative with resources
103+
OPTIMAL_NPROC=$(( OPTIMAL_NPROC > 2 ? 2 : OPTIMAL_NPROC ))
104+
fi
105+
106+
echo "nproc=${OPTIMAL_NPROC}" >> $GITHUB_OUTPUT
107+
92108
- name: Build image
93109
uses: docker/build-push-action@v6
94110
env:
@@ -102,6 +118,7 @@ jobs:
102118
platforms: ${{ matrix.arch }}
103119
build-args: |
104120
ALPINE_VERSION=${{ env.ALPINE_VERSION }}
121+
nproc=${{ steps.build-params.outputs.nproc }}
105122
push: false
106123
load: true
107124
tags: |

0 commit comments

Comments
 (0)