8000 Replace Vagrant with Cloud-Init and QEMU for VM image builds by ralphlange · Pull Request #97 · epics-training/training-vm · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/Containerfile.debian

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/Containerfile.fedora

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/Containerfile.rocky

This file was deleted.

17 changes: 0 additions & 17 de 10BC8 letions .github/workflows/Containerfile.ubuntu

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/_arch_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: "Resolve Architecture Matrix"

# Turns a requested architecture list into the `arch` matrix dimension used by
# the QEMU-based build/test workflows, so the arch -> runner/package mapping
# lives in exactly one place.
#
# x86_64 is the default because it is the only architecture GitHub-hosted
# runners can do here: the QEMU jobs need /dev/kvm, and GitHub's arm64 hosted
# runners provide no nested virtualization. Without KVM, QEMU falls back to TCG
# emulation, which is far too slow for these jobs (hours, past GitHub's 6 h job
# cap). aarch64 is therefore opt-in via workflow_dispatch, ready for a
# KVM-capable (self-hosted or larger) arm64 runner.

on:
workflow_call:
inputs:
architectures:
description: "Comma-separated architectures (x86_64, aarch64). Empty means x86_64 only."
required: false
type: string
default: ""
outputs:
matrix:
description: "JSON array of {name, runner, qemu} objects for the arch matrix dimension"
value: ${{ jobs.resolve.outputs.matrix }}

permissions: {}

jobs:
resolve:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
matrix: ${{ steps.set.outputs.matrix }}
steps:
- name: Build arch matrix
id: set
# Passed via env (not interpolated into the script) because this is a
# workflow_dispatch input, i.e. user-controlled. Values are matched
# against a fixed whitelist below.
env:
REQUESTED: ${{ inputs.architectures }}
run: |
set -euo pipefail

requested="${REQUESTED:-}"
if [ -z "$requested" ]; then
requested="x86_64"
fi

entries=""
for arch in $(echo "$requested" | tr ',' ' '); do
case "$arch" in
x86_64|amd64)
entry='{"name":"x86_64","runner":"ubuntu-latest","qemu":"qemu-system-x86"}'
;;
aarch64|arm64)
# qemu-system-arm provides qemu-system-aarch64; aarch64 guests
# are UEFI-only, hence the firmware package
entry='{"name":"aarch64","runner":"ubuntu-24.04-arm","qemu":"qemu-system-arm qemu-efi-aarch64"}'
;;
*)
echo "::error ::Unknown architecture '$arch' (supported: x86_64, aarch64)"
exit 1
;;
esac
entries="${entries:+$entries,}$entry"
done

echo "matrix=[$entries]" >> "$GITHUB_OUTPUT"
echo "Architecture matrix: [$entries]"
128 changes: 128 additions & 0 deletions .github/workflows/_resolve_build_run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: "Resolve Stage-1 Build Run"

on:
workflow_call:
inputs:
workflow_file:
required: true
type: string
sha:
required: true
type: string
branch:
description: "Branch to check for a same-branch fallback build (e.g. the branch/PR under test)"
required: true
type: string
outputs:
run_id:
description: "Run ID of the stage-1 build whose qcow2 artifacts should be used"
value: ${{ jobs.resolve.outputs.run_id }}
source:
description: "same-commit | same-branch | main-fallback"
value: ${{ jobs.resolve.outputs.source }}

permissions: {}

jobs:
resolve:
runs-on: ubuntu-latest
timeout-minutes: 90
permissions:
actions: read
outputs:
run_id: ${{ steps.resolve.outputs.run_id }}
source: ${{ steps.resolve.outputs.source }}
steps:
- name: Resolve build run
id: resolve
env:
WORKFLOW_FILE: ${{ inputs.workflow_file }}
TARGET_SHA: ${{ inputs.sha }}
TARGET_BRANCH: ${{ inputs.branch }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const workflow_file = process.env.WORKFLOW_FILE;
const sha = process.env.TARGET_SHA;
const branch = process.env.TARGET_BRANCH;
const max_retries = 6;
const retry_delay_ms = 30000;

let retry_count = 0;
while (true) {
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflow_file,
head_sha: sha,
});
const run = runs.workflow_runs.find(r => r.head_sha === sha);

if (!run) {
if (retry_count < max_retries) {
console.log(`No run of ${workflow_file} found for ${sha} yet. Retry ${retry_count + 1}/${max_retries}...`);
retry_count++;
await new Promise(r => setTimeout(r, retry_delay_ms));
continue;
}
console.log(`No run of ${workflow_file} found for ${sha} after ${max_retries} retries. Falling back to branch history.`);
break;
}

if (run.status !== "completed") {
console.log(`Run ${run.id} is still ${run.status}. Waiting...`);
await new Promise(r => setTimeout(r, retry_delay_ms));
continue;
}

console.log(`Found run ${run.id} for ${sha}, conclusion=${run.conclusion}`);
if (run.conclusion === "success") {
core.setOutput("run_id", run.id.toString());
core.setOutput("source", "same-commit");
return;
}
console.log(`Stage-1 build (${workflow_file}) for commit ${sha} concluded with '${run.conclusion}', not 'success'. Falling back to branch history instead of failing outright.`);
break;
}

// Tier 2: latest successful run on the same branch as the commit under test.
const { data: branchRuns } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflow_file,
branch: branch,
status: "success",
per_page: 1,
});

if (branchRuns.workflow_runs.length > 0) {
const fallback = branchRuns.workflow_runs[0];
console.log(`Using same-branch (${branch}) fallback run ${fallback.id} (created ${fallback.created_at}).`);
core.setOutput("run_id", fallback.id.toString());
core.setOutput("source", "same-branch");
return;
}

console.log(`No successful run of ${workflow_file} on branch ${branch}. Falling back to main.`);

// Tier 3: latest successful run on main (skip if branch under test already is main).
if (branch !== "main") {
const { data: mainRuns } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflow_file,
branch: "main",
status: "success",
per_page: 1,
});

if (mainRuns.workflow_runs.length > 0) {
const fallback = mainRuns.workflow_runs[0];
console.log(`Using main-branch fallback run ${fallback.id} (created ${fallback.created_at}).`);
core.setOutput("run_id", fallback.id.toString());
core.setOutput("source", "main-fallback");
return;
}
}

core.setFailed(`No successful run of ${workflow_file} found for commit ${sha}, on branch ${branch}, or on main. There is no qcow2 image available to test against.`);
83 changes: 0 additions & 83 deletions .github/workflows/_wait_for_workflow.yml

This file was deleted.

Loading
0