Skip to content

Commit 110b0d5

Browse files
committed
runner input
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 861e4cd commit 110b0d5

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

.github/workflows/.test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ jobs:
278278
with:
279279
builder-outputs: ${{ toJSON(needs.build-local-single.outputs) }}
280280

281+
build-set-runner:
282+
uses: ./.github/workflows/build.yml
283+
permissions:
284+
contents: read
285+
packages: write
286+
id-token: write
287+
with:
288+
runner: amd64
289+
output: image
290+
push: false
291+
meta-images: ghcr.io/docker/github-builder-test
292+
meta-tags: |
293+
type=raw,value=build-${{ github.run_id }}
294+
build-file: test/hello.Dockerfile
295+
build-platforms: linux/amd64,linux/arm64
296+
281297
bake-aws-single:
282298
uses: ./.github/workflows/bake.yml
283299
permissions:
@@ -441,3 +457,20 @@ jobs:
441457
- bake-local-single
442458
with:
443459
builder-outputs: ${{ toJSON(needs.bake-local-single.outputs) }}
460+
461+
bake-set-runner:
462+
uses: ./.github/workflows/bake.yml
463+
permissions:
464+
contents: read
465+
packages: write
466+
id-token: write
467+
with:
468+
runner: amd64
469+
context: test
470+
target: hello-cross
471+
output: image
472+
push: false
473+
meta-images: |
474+
public.ecr.aws/q3b5f1u4/test-docker-action
475+
meta-tags: |
476+
type=raw,value=bake-ghbuilder-${{ github.run_id }}

.github/workflows/bake.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: bake
33
on:
44
workflow_call:
55
inputs:
6+
runner:
7+
type: string
8+
description: "Linux machine to run build on. Can be one of auto, amd64, arm64 (defaults to auto which selects best-matching runner based on target platform)"
9+
required: false
10+
default: auto
611
context:
712
type: string
813
description: "Context to build from (defaults to repository root)"
@@ -175,6 +180,7 @@ jobs:
175180
uses: actions/github-script@v8
176181
env:
177182
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
183+
INPUT_RUNNER: ${{ inputs.runner }}
178184
INPUT_CONTEXT: ${{ inputs.context }}
179185
INPUT_TARGET: ${{ inputs.target }}
180186
INPUT_BAKE-ALLOW: ${{ inputs.bake-allow }}
@@ -192,6 +198,7 @@ jobs:
192198
193199
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
194200
201+
const inpRunner = core.getInput('runner');
195202
const inpContext = core.getInput('context');
196203
const inpTarget = core.getInput('target');
197204
const inpBakeAllow = core.getInput('bake-allow');
@@ -200,6 +207,20 @@ jobs:
200207
const inpBakeSbom = core.getInput('bake-sbom');
201208
const inpBakeSet = Util.getInputList('bake-set', {ignoreComma: true, quote: false});
202209
const inpGitHubToken = core.getInput('github-token');
210+
211+
let runner = inpRunner;
212+
switch (inpRunner) {
213+
case 'auto':
214+
break;
215+
case 'amd64':
216+
runner = 'ubuntu-24.04';
217+
break;
218+
case 'arm64':
219+
runner = 'ubuntu-24.04-arm';
220+
break;
221+
default:
222+
throw new Error(`Invalid runner input: ${inpRunner}`);
223+
}
203224
204225
const bakeSource = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}.git#${process.env.GITHUB_REF}:${inpContext}`;
205226
await core.group(`Set bake source`, async () => {
@@ -238,14 +259,14 @@ jobs:
238259
} else if (platforms.length === 0) {
239260
includes.push({
240261
index: 0,
241-
runner: 'ubuntu-24.04'
262+
runner: runner === auto ? 'ubuntu-24.04' : runner
242263
});
243264
} else {
244265
platforms.forEach((platform, index) => {
245266
includes.push({
246267
index: index,
247268
platform: platform,
248-
runner: (!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04' // FIXME: ubuntu-24.04-arm runner not yet available for private repos
269+
runner: runner === auto ? ((!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04') : runner
249270
});
250271
});
251272
}

.github/workflows/build.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: build
33
on:
44
workflow_call:
55
inputs:
6+
runner:
7+
type: string
8+
description: "Linux machine to run build on. Can be one of auto, amd64, arm64 (defaults to auto which selects best-matching runner based on target platform)"
9+
required: false
10+
default: auto
611
context:
712
type: string
813
description: "Context to build from (defaults to repository root)"
@@ -174,6 +179,7 @@ jobs:
174179
uses: actions/github-script@v8
175180
env:
176181
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
182+
INPUT_RUNNER: ${{ inputs.runner }}
177183
INPUT_BUILD-PLATFORMS: ${{ inputs.build-platforms }}
178184
with:
179185
script: |
@@ -182,8 +188,23 @@ jobs:
182188
183189
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
184190
191+
const inpRunner = core.getInput('runner');
185192
const inpBuildPlatforms = Util.getInputList('build-platforms');
186193
194+
let runner = inpRunner;
195+
switch (inpRunner) {
196+
case 'auto':
197+
break;
198+
case 'amd64':
199+
runner = 'ubuntu-24.04';
200+
break;
201+
case 'arm64':
202+
runner = 'ubuntu-24.04-arm';
203+
break;
204+
default:
205+
throw new Error(`Invalid runner input: ${inpRunner}`);
206+
}
207+
187208
const privateRepo = GitHub.context.payload.repository?.private ?? false;
188209
await core.group(`Set includes`, async () => {
189210
let includes = [];
@@ -192,14 +213,14 @@ jobs:
192213
} else if (inpBuildPlatforms.length === 0) {
193214
includes.push({
194215
index: 0,
195-
runner: 'ubuntu-24.04'
216+
runner: runner === auto ? 'ubuntu-24.04' : runner
196217
});
197218
} else {
198219
inpBuildPlatforms.forEach((platform, index) => {
199220
includes.push({
200221
index: index,
201222
platform: platform,
202-
runner: (!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04' // FIXME: ubuntu-24.04-arm runner not yet available for private repos
223+
runner: runner === auto ? ((!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04') : runner
203224
});
204225
});
205226
}

0 commit comments

Comments
 (0)