Skip to content

Commit 7f65c7c

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

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

.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: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ 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
610
context:
711
type: string
812
description: "Context to build from (defaults to repository root)"
@@ -175,6 +179,7 @@ jobs:
175179
uses: actions/github-script@v8
176180
env:
177181
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
182+
INPUT_RUNNER: ${{ inputs.runner }}
178183
INPUT_CONTEXT: ${{ inputs.context }}
179184
INPUT_TARGET: ${{ inputs.target }}
180185
INPUT_BAKE-ALLOW: ${{ inputs.bake-allow }}
@@ -192,6 +197,7 @@ jobs:
192197
193198
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
194199
200+
const inpRunner = core.getInput('runner');
195201
const inpContext = core.getInput('context');
196202
const inpTarget = core.getInput('target');
197203
const inpBakeAllow = core.getInput('bake-allow');
@@ -200,6 +206,20 @@ jobs:
200206
const inpBakeSbom = core.getInput('bake-sbom');
201207
const inpBakeSet = Util.getInputList('bake-set', {ignoreComma: true, quote: false});
202208
const inpGitHubToken = core.getInput('github-token');
209+
210+
let runner = inpRunner;
211+
switch (inpRunner) {
212+
case 'auto':
213+
break;
214+
case 'amd64':
215+
runner = 'ubuntu-24.04';
216+
break;
217+
case 'arm64':
218+
runner = 'ubuntu-24.04-arm';
219+
break;
220+
default:
221+
throw new Error(`Invalid runner input: ${inpRunner}`);
222+
}
203223
204224
const bakeSource = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}.git#${process.env.GITHUB_REF}:${inpContext}`;
205225
await core.group(`Set bake source`, async () => {
@@ -238,14 +258,14 @@ jobs:
238258
} else if (platforms.length === 0) {
239259
includes.push({
240260
index: 0,
241-
runner: 'ubuntu-24.04'
261+
runner: runner === auto ? 'ubuntu-24.04' : runner
242262
});
243263
} else {
244264
platforms.forEach((platform, index) => {
245265
includes.push({
246266
index: index,
247267
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
268+
runner: runner === auto ? ((!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04') : runner
249269
});
250270
});
251271
}

.github/workflows/build.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ 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
610
context:
711
type: string
812
description: "Context to build from (defaults to repository root)"
@@ -174,6 +178,7 @@ jobs:
174178
uses: actions/github-script@v8
175179
env:
176180
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
181+
INPUT_RUNNER: ${{ inputs.runner }}
177182
INPUT_BUILD-PLATFORMS: ${{ inputs.build-platforms }}
178183
with:
179184
script: |
@@ -182,8 +187,23 @@ jobs:
182187
183188
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
184189
190+
const inpRunner = core.getInput('runner');
185191
const inpBuildPlatforms = Util.getInputList('build-platforms');
186192
193+
let runner = inpRunner;
194+
switch (inpRunner) {
195+
case 'auto':
196+
break;
197+
case 'amd64':
198+
runner = 'ubuntu-24.04';
199+
break;
200+
case 'arm64':
201+
runner = 'ubuntu-24.04-arm';
202+
break;
203+
default:
204+
throw new Error(`Invalid runner input: ${inpRunner}`);
205+
}
206+
187207
const privateRepo = GitHub.context.payload.repository?.private ?? false;
188208
await core.group(`Set includes`, async () => {
189209
let includes = [];
@@ -192,14 +212,14 @@ jobs:
192212
} else if (inpBuildPlatforms.length === 0) {
193213
includes.push({
194214
index: 0,
195-
runner: 'ubuntu-24.04'
215+
runner: runner === auto ? 'ubuntu-24.04' : runner
196216
});
197217
} else {
198218
inpBuildPlatforms.forEach((platform, index) => {
199219
includes.push({
200220
index: index,
201221
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
222+
runner: runner === auto ? ((!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04') : runner
203223
});
204224
});
205225
}

0 commit comments

Comments
 (0)