Skip to content

Commit 813ea76

Browse files
authored
Merge pull request #46 from crazy-max/runner-input
runner input
2 parents 861e4cd + 80f7203 commit 813ea76

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-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: 18 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,15 @@ 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+
if (inpRunner === 'amd64') {
213+
runner = 'ubuntu-24.04';
214+
} else if (inpRunner === 'arm64') {
215+
runner = 'ubuntu-24.04-arm';
216+
} else if (inpRunner !== 'auto') {
217+
throw new Error(`Invalid runner input: ${inpRunner}`);
218+
}
203219
204220
const bakeSource = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}.git#${process.env.GITHUB_REF}:${inpContext}`;
205221
await core.group(`Set bake source`, async () => {
@@ -238,14 +254,14 @@ jobs:
238254
} else if (platforms.length === 0) {
239255
includes.push({
240256
index: 0,
241-
runner: 'ubuntu-24.04'
257+
runner: runner === 'auto' ? 'ubuntu-24.04' : runner
242258
});
243259
} else {
244260
platforms.forEach((platform, index) => {
245261
includes.push({
246262
index: index,
247263
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
264+
runner: runner === 'auto' ? ((!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04') : runner
249265
});
250266
});
251267
}

.github/workflows/build.yml

Lines changed: 18 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,18 @@ 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+
if (inpRunner === 'amd64') {
196+
runner = 'ubuntu-24.04';
197+
} else if (inpRunner === 'arm64') {
198+
runner = 'ubuntu-24.04-arm';
199+
} else if (inpRunner !== 'auto') {
200+
throw new Error(`Invalid runner input: ${inpRunner}`);
201+
}
202+
187203
const privateRepo = GitHub.context.payload.repository?.private ?? false;
188204
await core.group(`Set includes`, async () => {
189205
let includes = [];
@@ -192,14 +208,14 @@ jobs:
192208
} else if (inpBuildPlatforms.length === 0) {
193209
includes.push({
194210
index: 0,
195-
runner: 'ubuntu-24.04'
211+
runner: runner === 'auto' ? 'ubuntu-24.04' : runner
196212
});
197213
} else {
198214
inpBuildPlatforms.forEach((platform, index) => {
199215
includes.push({
200216
index: index,
201217
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
218+
runner: runner === 'auto' ? ((!privateRepo && platform.startsWith('linux/arm')) ? 'ubuntu-24.04-arm' : 'ubuntu-24.04') : runner
203219
});
204220
});
205221
}

0 commit comments

Comments
 (0)