Skip to content

Commit 6b59374

Browse files
feat(docker-build-push-multiarch): allow github hosted runner usage (#1456)
* update .github/workflows/docker-build-push-multiarch.yml to allow for more dynamic runner type selection, and add sane defaults for both self-hosted and github runners * change runner_arches output to runner-arches to match other inputs/outputs * run prettier
1 parent cbb5c3f commit 6b59374

File tree

2 files changed

+75
-13
lines changed

2 files changed

+75
-13
lines changed

.github/workflows/docker-build-push-multiarch.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ jobs:
7474
| `platforms` | string | List of platforms to build the image for. Passed to `docker/build-push-action`. |
7575
| `push` | string | Whether to push the image to the configured registries. Passed to `docker/build-push-action`. |
7676
| `registries` | string | CSV list of registries to build images for. Accepted registries are "gar" and "dockerhub". |
77+
| `runner-type` | string | Setting this flag will dictate the default instance types to use. If runner-type-x64, runner-type-arm64, and runner-type-manifest are all set then this value is superseded because no defaults will be used. |
78+
| `runner-type-arm64` | string | The instance type to use for arm64 builds. |
79+
| `runner-type-manifest` | string | The instance type to use when building and pushing the manifest. |
80+
| `runner-type-x64` | string | The instance type to use for x64 builds. |
7781
| `secrets` | string | Secrets to expose to the build. Only needed when authenticating to private repositories outside the repository in which the image is being built. Passed to `docker/build-push-action`. |
78-
| `server-size` | string | Size of the Grafana self-hosted runner |
7982
| `ssh` | string | List of SSH agent socket or keys to expose to the build Passed to `docker/build-push-action`. |
8083
| `tags` | string | List of Docker tags to be pushed. Passed to `docker/build-push-action`. |
8184
| `target` | string | Sets the target stage to build. Passed to `docker/build-push-action`. |

.github/workflows/docker-build-push-multiarch.yml

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,27 @@ on:
55
inputs:
66
# THE FOLLOWING INPUTS ARE UNIQUE TO THIS WORKFLOW
77
# MULTIARCH CONFIGS
8-
server-size:
9-
description: "Size of the Grafana self-hosted runner"
8+
runner-type:
9+
description: |
10+
Setting this flag will dictate the default instance types to use.
11+
Allowed values are 'self-hosted' or 'github'.
12+
required: false
13+
default: "self-hosted"
14+
type: string
15+
runner-type-arm64:
16+
description: |
17+
The instance type to use for arm64 builds.
18+
required: false
19+
type: string
20+
runner-type-manifest:
21+
description: |
22+
The instance type to use when building and pushing the manifest.
23+
required: false
24+
type: string
25+
runner-type-x64:
26+
description: |
27+
The instance type to use for x64 builds.
1028
required: false
11-
default: "small"
1229
type: string
1330

1431
# The following inputs are identical to the inputs
@@ -190,18 +207,21 @@ on:
190207
version:
191208
description: "Generated Docker image version (from docker/metadata-action)"
192209
value: ${{ jobs.build-and-push.outputs.version }}
193-
runner_arches:
210+
runner-arches:
194211
description: "The list of OS used to build images (for mapping to self hosted runners)"
195-
value: ${{ jobs.prepare-matrix.outputs.runner_arches }}
212+
value: ${{ jobs.prepare-matrix.outputs.runner-arches }}
196213

197214
env:
198215
ARCH_TO_PLATFORM_MAP: '{"arm64": "linux/arm64", "x64": "linux/amd64"}'
199216

200217
jobs:
201218
prepare-matrix:
202-
runs-on: ubuntu-arm64-small
219+
runs-on: ${{ inputs.runner-type == 'self-hosted' && 'ubuntu-x64-small' || 'ubuntu-latest' }}
203220
outputs:
204-
runner_arches: ${{ steps.matrix.outputs.runner_arches }}
221+
runner-arches: ${{ steps.matrix.outputs.runner-arches }}
222+
runner-type-x64: ${{ steps.runners.outputs.runner-type-x64 }}
223+
runner-type-arm64: ${{ steps.runners.outputs.runner-type-arm64 }}
224+
runner-type-manifest: ${{ steps.runners.outputs.runner-type-manifest }}
205225
steps:
206226
- id: matrix
207227
shell: bash
@@ -232,15 +252,54 @@ jobs:
232252
MATRIX=$(echo "$PS" | jq -R -c 'split(",")')
233253
234254
# Export as GitHub Action output
235-
echo "runner_arches=$MATRIX" | tee -a "${GITHUB_OUTPUT}"
255+
echo "runner-arches=$MATRIX" | tee -a "${GITHUB_OUTPUT}"
256+
- id: runners
257+
shell: bash
258+
env:
259+
RUNNER_TYPE: ${{ inputs.runner-type }}
260+
X64_TYPE: ${{ inputs.runner-type-x64 }}
261+
ARM64_TYPE: ${{ inputs.runner-type-arm64 }}
262+
MANIFEST_TYPE: ${{ inputs.runner-type-manifest }}
263+
run: |
264+
#############################################################
265+
# This step sets up the runner types for the remaining jobs
266+
#############################################################
267+
268+
# Set default runner types based on RUNNER_TYPE
269+
case "$RUNNER_TYPE" in
270+
self-hosted)
271+
DEFAULT_X64="ubuntu-x64-small"
272+
DEFAULT_ARM64="ubuntu-arm64-small"
273+
DEFAULT_MANIFEST="ubuntu-arm64-small"
274+
;;
275+
github)
276+
DEFAULT_X64="ubuntu-24.04"
277+
DEFAULT_ARM64="ubuntu-24.04-arm"
278+
DEFAULT_MANIFEST="ubuntu-24.04-arm"
279+
;;
280+
*)
281+
echo "Unknown RUNNER_TYPE: $RUNNER_TYPE" >&2
282+
exit 1
283+
;;
284+
esac
285+
286+
# Use user-provided overrides if they exist, otherwise use defaults
287+
X64_OUT="${X64_TYPE:-$DEFAULT_X64}"
288+
ARM64_OUT="${ARM64_TYPE:-$DEFAULT_ARM64}"
289+
MANIFEST_OUT="${MANIFEST_TYPE:-$DEFAULT_MANIFEST}"
290+
291+
# Export to GitHub Actions outputs
292+
echo "runner-type-x64=$X64_OUT" | tee -a "${GITHUB_OUTPUT}"
293+
echo "runner-type-arm64=$ARM64_OUT" | tee -a "${GITHUB_OUTPUT}"
294+
echo "runner-type-manifest=$MANIFEST_OUT" | tee -a "${GITHUB_OUTPUT}"
236295
237296
build-and-push:
238297
needs: prepare-matrix
239298
strategy:
240299
fail-fast: false
241300
matrix:
242-
arch: ${{ fromJson(needs.prepare-matrix.outputs.runner_arches) }}
243-
runs-on: ubuntu-${{ matrix.arch }}-${{ inputs.server-size }}
301+
arch: ${{ fromJson(needs.prepare-matrix.outputs.runner-arches) }}
302+
runs-on: ${{ matrix.arch == 'x64' && needs.prepare-matrix.outputs.runner-type-x64 || needs.prepare-matrix.outputs.runner-type-arm64 }}
244303
outputs:
245304
annotations: ${{ steps.build.outputs.annotations }}
246305
digest: ${{ steps.build.outputs.digest }}
@@ -312,8 +371,8 @@ jobs:
312371
platform: ${{ env.PLATFORM }}
313372

314373
merge-digest:
315-
runs-on: ubuntu-arm64-small
316-
needs: build-and-push
374+
runs-on: ${{ needs.prepare-matrix.outputs.runner-type-manifest }}
375+
needs: [prepare-matrix, build-and-push]
317376
permissions:
318377
contents: read
319378
id-token: write

0 commit comments

Comments
 (0)