Skip to content

Commit

Permalink
Merge pull request #368 from hermit-os/github-runner
Browse files Browse the repository at this point in the history
ci: run KVM tests on GitHub runners
  • Loading branch information
mkroening authored Dec 10, 2024
2 parents abb2975 + f92182c commit b61ec53
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
88 changes: 33 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
matrix:
target: [x86_64, aarch64, riscv64]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- target: x86_64
os: ubuntu-latest
flags: --accel --sudo
runs-on: ${{ matrix.os }}
steps:
- name: Install QEMU (ubuntu)
Expand All @@ -61,6 +65,21 @@ jobs:
run: |
choco install qemu
echo "C:\Program Files\qemu" >> $GITHUB_PATH
- name: Install firecracker
run: |
# https://github.com/firecracker-microvm/firecracker/blob/v1.5.1/docs/getting-started.md#getting-a-firecracker-binary
ARCH="$(uname -m)"
release_url="https://github.com/firecracker-microvm/firecracker/releases"
latest=$(basename $(curl -fsSLI -o /dev/null -w %{url_effective} ${release_url}/latest))
curl -L ${release_url}/download/${latest}/firecracker-${latest}-${ARCH}.tgz \
| tar -xz
mkdir -p $HOME/.local/bin
mv release-${latest}-$(uname -m)/firecracker-${latest}-${ARCH} $HOME/.local/bin/firecracker
echo $HOME/.local/bin >> $GITHUB_PATH
$HOME/.local/bin/firecracker --version
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64'
- uses: actions/checkout@v4
with:
lfs: true
Expand All @@ -85,71 +104,30 @@ jobs:
cp /usr/share/OVMF/OVMF_VARS.fd edk2-stable202408-r1-bin/x64/vars.fd
if: matrix.os == 'ubuntu-latest'
- name: Run VM (hello_world, dev)
run: cargo xtask ci qemu --target ${{ matrix.target }}
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }}
- name: Run VM (hello_world, release)
run: cargo xtask ci qemu --target ${{ matrix.target }} --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --release
- name: Run VM (hello_world, uefi, dev)
run: cargo xtask ci qemu --target ${{ matrix.target }}-uefi
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }}-uefi
if: matrix.target == 'x86_64'
- name: Run VM (hello_world, uefi, release)
run: cargo xtask ci qemu --target ${{ matrix.target }}-uefi --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }}-uefi --release
if: matrix.target == 'x86_64'
- name: Run VM (hello_world-microvm, dev)
if: matrix.target == 'x86_64' && matrix.os == 'ubuntu-latest'
run: cargo xtask ci qemu --target ${{ matrix.target }} --microvm
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --microvm
- name: Run VM (hello_world-microvm, release)
if: matrix.target == 'x86_64' && matrix.os == 'ubuntu-latest'
run: cargo xtask ci qemu --target ${{ matrix.target }} --microvm --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --microvm --release
- name: Run VM (hello_c, dev)
if: matrix.target == 'x86_64'
run: cargo xtask ci qemu --target ${{ matrix.target }} --image hello_c
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --image hello_c
- name: Run VM (hello_c, release)
if: matrix.target == 'x86_64'
run: cargo xtask ci qemu --target ${{ matrix.target }} --image hello_c --release

run-kvm:
name: Run (KVM)
runs-on: [self-hosted]
steps:
- name: Install QEMU
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends qemu-system-x86
- uses: actions/checkout@v4
with:
lfs: true
- name: Install firecracker
run: |
# https://github.com/firecracker-microvm/firecracker/blob/v1.5.1/docs/getting-started.md#getting-a-firecracker-binary
ARCH="$(uname -m)"
release_url="https://github.com/firecracker-microvm/firecracker/releases"
latest=$(basename $(curl -fsSLI -o /dev/null -w %{url_effective} ${release_url}/latest))
curl -L ${release_url}/download/${latest}/firecracker-${latest}-${ARCH}.tgz \
| tar -xz
# Rename the binary to "firecracker"
mv release-${latest}-$(uname -m)/firecracker-${latest}-${ARCH} firecracker
echo "$PWD" >> $GITHUB_PATH
./firecracker --version
- name: Download OVMF
run: |
gh release download edk2-stable202408-r1 --repo rust-osdev/ovmf-prebuilt --pattern 'edk2-stable*-bin.tar.xz'
tar -xvf edk2-stable*-bin.tar.xz edk2-stable202408-r1-bin/x64
- uses: dtolnay/rust-toolchain@stable
- name: Run QEMU (hello_world, dev)
run: cargo xtask ci qemu --target x86_64 --accel
- name: Run QEMU (hello_world, release)
run: cargo xtask ci qemu --target x86_64 --accel --release
- name: Run QEMU (hello_world-microvm, dev)
run: cargo xtask ci qemu --target x86_64 --accel --microvm
- name: Run QEMU (hello_world-microvm, release)
run: cargo xtask ci qemu --target x86_64 --accel --microvm --release
- name: Run UEFI (dev)
run: cargo xtask ci qemu --target x86_64-uefi --accel
- name: Run UEFI (release)
run: cargo xtask ci qemu --target x86_64-uefi --accel --release
- name: Run Firecracker (hello_world, dev)
run: cargo xtask ci firecracker --target x86_64-fc
- name: Run Firecracker (hello_world, release)
run: cargo xtask ci firecracker --target x86_64-fc --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --image hello_c --release
- name: Run VM (hello_world-microvm, fc, release)
run: FIRECRACKER=$HOME/.local/bin/firecracker cargo xtask ci firecracker --target ${{ matrix.target }}-fc --sudo
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64'
- name: Run VM (hello_world-microvm, fc, release)
run: FIRECRACKER=$HOME/.local/bin/firecracker cargo xtask ci firecracker --target ${{ matrix.target }}-fc --sudo --release
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64'
16 changes: 15 additions & 1 deletion xtask/src/ci/firecracker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::path::Path;

use anyhow::Result;
Expand All @@ -9,6 +10,10 @@ use crate::build::Build;
/// Run hermit-rs images on Firecracker.
#[derive(Args)]
pub struct Firecracker {
/// Run Firecracker using `sudo`.
#[arg(long)]
sudo: bool,

#[command(flatten)]
build: Build,

Expand All @@ -34,13 +39,22 @@ impl Firecracker {
let config_path = Path::new("firecracker_vm_config.json");
sh.write_file(config_path, config)?;

let firecracker = env::var("FIRECRACKER").unwrap_or_else(|_| "firecracker".to_string());
let program = if self.sudo {
"sudo"
} else {
firecracker.as_str()
};
let arg = self.sudo.then_some(firecracker.as_str());

let log_path = Path::new("firecracker.log");
sh.write_file(log_path, "")?;
cmd!(sh, "firecracker --no-api --config-file {config_path} --log-path {log_path} --level Info --show-level --show-log-origin").run()?;
let res = cmd!(sh, "{program} {arg...} --no-api --config-file {config_path} --log-path {log_path} --level Info --show-level --show-log-origin").run();
let log = sh.read_file(log_path)?;

eprintln!("firecracker log");
eprintln!("{log}");
res?;

Ok(())
}
Expand Down
10 changes: 8 additions & 2 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct Qemu {
#[arg(long)]
accel: bool,

/// Run QEMU using `sudo`.
#[arg(long)]
sudo: bool,

/// Enable the `microvm` machine type.
#[arg(long)]
microvm: bool,
Expand Down Expand Up @@ -60,9 +64,11 @@ impl Qemu {

let target = self.build.target();
let arch = target.arch();
let qemu = env::var_os("QEMU").unwrap_or_else(|| format!("qemu-system-{arch}").into());
let qemu = env::var("QEMU").unwrap_or_else(|_| format!("qemu-system-{arch}"));
let program = if self.sudo { "sudo" } else { qemu.as_str() };
let arg = self.sudo.then_some(qemu.as_str());

let qemu = cmd!(sh, "{qemu}")
let qemu = cmd!(sh, "{program} {arg...}")
.args(&["-display", "none"])
.args(&["-serial", "stdio"])
.args(self.machine_args())
Expand Down

0 comments on commit b61ec53

Please sign in to comment.