Add a --memory flag
CI / build (push) Successful in 10s

This commit is contained in:
2026-08-29 21:12:23 +02:00
parent ec05936d2f
commit 46a86116b0
2 changed files with 20 additions and 12 deletions
+5 -8
View File
@@ -6,7 +6,7 @@ mod registry;
use anyhow::Result; use anyhow::Result;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use crate::image::ImageCmd; use crate::{image::ImageCmd, qemu::RunCmd};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(about = "Build bootable initrd VMs from container images")] #[command(about = "Build bootable initrd VMs from container images")]
@@ -25,11 +25,8 @@ enum Commands {
#[arg(short = 's', long, default_value = "512")] #[arg(short = 's', long, default_value = "512")]
_size: String, _size: String,
}, },
/// Launch the VM via QEMU using registry artifacts /// Launch a previously built VM via QEMU.
Run { Run(RunCmd),
/// Image tag / registry subdir name
name: String,
},
/// List slim images in the registry /// List slim images in the registry
#[command(subcommand)] #[command(subcommand)]
Image(ImageCmd), Image(ImageCmd),
@@ -41,8 +38,8 @@ fn main() -> Result<()> {
Commands::Build { image, _size: _ } => { Commands::Build { image, _size: _ } => {
build::build(&image)?; build::build(&image)?;
} }
Commands::Run { name } => { Commands::Run(cmd) => {
qemu::run(&name)?; qemu::run(cmd)?;
} }
Commands::Image(cmd) => { Commands::Image(cmd) => {
image::run(cmd)?; image::run(cmd)?;
+15 -4
View File
@@ -2,12 +2,23 @@
//! boot (-kernel/-initrd). //! boot (-kernel/-initrd).
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result, bail};
use clap::Args;
use std::process::Command; use std::process::Command;
use crate::registry::registry_dir; use crate::registry::registry_dir;
pub(crate) fn run(name: &str) -> Result<()> { #[derive(Args, Debug)]
let reg_dir = registry_dir(name)?; pub struct RunCmd {
/// Image tag / registry subdir name
name: String,
/// Amount of memory to give the VM, in qemu's format.
#[clap(short, long, default_value = "1024M")]
memory: String,
}
pub(crate) fn run(RunCmd { name, memory }: RunCmd) -> Result<()> {
let reg_dir = registry_dir(&name)?;
let vmlinuz_path = reg_dir.join("vmlinuz"); let vmlinuz_path = reg_dir.join("vmlinuz");
let initrd_path = reg_dir.join("initrd"); let initrd_path = reg_dir.join("initrd");
if !vmlinuz_path.exists() || !initrd_path.exists() { if !vmlinuz_path.exists() || !initrd_path.exists() {
@@ -16,7 +27,7 @@ pub(crate) fn run(name: &str) -> Result<()> {
name name
); );
} }
println!("Booting {} from registry: {}", name, reg_dir.display()); println!("Booting {name} from registry: {}", reg_dir.display());
println!( println!(
" qemu-system-x86_64 -m 256 -nographic -kernel {} -initrd {} -append 'console=ttyS0'", " qemu-system-x86_64 -m 256 -nographic -kernel {} -initrd {} -append 'console=ttyS0'",
vmlinuz_path.display(), vmlinuz_path.display(),
@@ -35,7 +46,7 @@ pub(crate) fn run(name: &str) -> Result<()> {
let mut command = Command::new("qemu-system-x86_64"); let mut command = Command::new("qemu-system-x86_64");
command command
.args(["-m", "1024M"]) .args(["-m", &memory])
.arg("-kernel") .arg("-kernel")
.arg(vmlinuz_path.as_os_str()) .arg(vmlinuz_path.as_os_str())
.arg("-initrd") .arg("-initrd")