Skip to content

Commit

Permalink
Merge pull request #1101 from balena-io-library/kyle/self-hosted
Browse files Browse the repository at this point in the history
Bake on self-hosted runners with full concurrency
  • Loading branch information
flowzone-app[bot] authored Aug 26, 2024
2 parents 06038fc + c50c4c0 commit 8890bd7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 33 deletions.
19 changes: 10 additions & 9 deletions scripts/blueprints/workflows/os-arch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output:
type: boolean
default: false
concurrency:
group: bake
group: ${{ github.workflow }}
cancel-in-progress: ${{ inputs.cancel-in-progress == true }}
jobs:
prepare:
Expand Down Expand Up @@ -71,19 +71,20 @@ output:
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
fetch-depth: 1
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v6.2.0
# https://github.com/docker/setup-buildx-action
- name: Setup buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
id: setup-buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
with:
driver-opts: network=host
install: true
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v8.0.4-33
# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
Expand Down
17 changes: 9 additions & 8 deletions scripts/blueprints/workflows/os-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output:
type: boolean
default: false
concurrency:
group: bake
group: ${{ github.workflow }}
cancel-in-progress: ${{ inputs.cancel-in-progress == true }}
jobs:
prepare:
Expand Down Expand Up @@ -71,19 +71,20 @@ output:
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
fetch-depth: 1
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v6.2.0
# https://github.com/docker/setup-buildx-action
- name: Setup buildx
id: setup-buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
with:
driver-opts: network=host
install: true
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v8.0.4-33
# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
Expand Down
17 changes: 9 additions & 8 deletions scripts/blueprints/workflows/stack-arch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ output:
type: boolean
default: false
concurrency:
group: bake
group: ${{ github.workflow }}
cancel-in-progress: ${{ inputs.cancel-in-progress == true }}
jobs:
prepare:
Expand Down Expand Up @@ -72,19 +72,20 @@ output:
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
fetch-depth: 1
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v6.2.0
# https://github.com/docker/setup-buildx-action
- name: Setup buildx
id: setup-buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
with:
driver-opts: network=host
install: true
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v8.0.4-33
# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
Expand Down
17 changes: 9 additions & 8 deletions scripts/blueprints/workflows/stack-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ output:
type: boolean
default: false
concurrency:
group: bake
group: ${{ github.workflow }}
cancel-in-progress: ${{ inputs.cancel-in-progress == true }}
jobs:
prepare:
Expand Down Expand Up @@ -72,19 +72,20 @@ output:
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
fetch-depth: 1
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v6.2.0
# https://github.com/docker/setup-buildx-action
- name: Setup buildx
id: setup-buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
with:
driver-opts: network=host
install: true
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v8.0.4-33
# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
Expand Down
46 changes: 46 additions & 0 deletions scripts/generate-workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,58 @@ const balena = getSdk({
dataDirectory: false,
});

function getRunnerLabels(arch) {
switch (arch) {
case 'aarch64':
return ['self-hosted', 'base-images', 'ARM64'];
case 'amd64':
return ['self-hosted', 'base-images', 'X64'];
case 'armv7hf':
return ['self-hosted', 'base-images', 'ARM64'];
case 'i386':
return ['self-hosted', 'base-images', 'X64'];
case 'rpi':
return ['self-hosted', 'base-images', 'ARM64'];
default:
console.error(`Unsupported arch: ${arch}`);
process.exit(1);
}
}

function getPlatform(arch) {
switch (arch) {
case 'aarch64':
return 'linux/arm64';
case 'amd64':
return 'linux/amd64';
case 'armv7hf':
return 'linux/arm/v7';
case 'i386':
return 'linux/386';
case 'rpi':
return 'linux/arm/v5';
default:
console.error(`Unsupported arch: ${arch}`);
process.exit(1);
}
}

const workflows = {};
function addToWorkflow(dest, context) {
const workflow = context.template;

workflow.jobs.bake.strategy.matrix.target = `\${{ fromJSON(needs.prepare-${context.imageName}.outputs.bake-targets) }}`;

// Use self-hosted runners with pre-defined labels
workflow.jobs.bake['runs-on'] = getRunnerLabels(
context.children.arch.sw.slug,
);

// Update the QEMU condition to check if emulation is needed
workflow.jobs.bake.steps[2].if = `contains(steps.setup-buildx.outputs.platforms, '${getPlatform(
context.children.arch.sw.slug,
)}') == false`;

workflow.jobs[`prepare-${context.imageName}`] = workflow.jobs.prepare;
workflow.jobs[`bake-${context.imageName}`] = workflow.jobs.bake;

Expand Down

0 comments on commit 8890bd7

Please sign in to comment.