Skip to content

Commit 82f8284

Browse files
committed
libvirt-run: Add --update-from-host
This streamlines the UX of upgrading from a local build; it's part of the idea of #86 but this is a lot smaller than that. Signed-off-by: Colin Walters <[email protected]>
1 parent 84b02c2 commit 82f8284

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

crates/kit/src/cache_metadata.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ struct CacheInputs {
3434
/// This is crucial because it determines the upgrade source for the installed system
3535
source_imgref: String,
3636

37+
/// Target transport
38+
#[serde(skip_serializing_if = "Option::is_none")]
39+
target_transport: Option<String>,
40+
3741
/// Filesystem type used for installation (e.g., "ext4", "xfs", "btrfs")
42+
#[serde(skip_serializing_if = "Option::is_none")]
3843
filesystem: Option<String>,
3944

4045
/// Root filesystem size if specified
46+
#[serde(skip_serializing_if = "Option::is_none")]
4147
root_size: Option<String>,
4248

4349
/// Whether to use composefs-native storage
@@ -60,6 +66,9 @@ pub struct DiskImageMetadata {
6066
/// This is crucial because it determines the upgrade source for the installed system
6167
pub source_imgref: String,
6268

69+
/// Target transport
70+
pub target_transport: Option<String>,
71+
6372
/// Filesystem type used for installation (e.g., "ext4", "xfs", "btrfs")
6473
pub filesystem: Option<String>,
6574

@@ -82,6 +91,7 @@ impl DiskImageMetadata {
8291
let inputs = CacheInputs {
8392
image_digest: self.digest.clone(),
8493
source_imgref: self.source_imgref.clone(),
94+
target_transport: self.target_transport.clone(),
8595
filesystem: self.filesystem.clone(),
8696
root_size: self.root_size.clone(),
8797
composefs_backend: self.composefs_backend,
@@ -169,6 +179,7 @@ impl DiskImageMetadata {
169179
version: 1,
170180
digest: image_digest.to_owned(),
171181
source_imgref: source_imgref.to_owned(),
182+
target_transport: options.target_transport.clone(),
172183
filesystem: options.filesystem.clone(),
173184
root_size: options.root_size.clone(),
174185
kernel_args: options.karg.clone(),
@@ -326,6 +337,7 @@ mod tests {
326337
let inputs = CacheInputs {
327338
image_digest: "sha256:abc123".to_string(),
328339
source_imgref: "quay.io/test/image:v1".to_string(),
340+
target_transport: None,
329341
filesystem: Some("ext4".to_string()),
330342
root_size: Some("20G".to_string()),
331343
kernel_args: vec!["console=ttyS0".to_string()],

crates/kit/src/install_options.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub struct InstallOptions {
2929
)]
3030
pub storage_path: Option<Utf8PathBuf>,
3131

32+
/// The transport; e.g. oci, oci-archive, containers-storage. Defaults to `registry`
33+
#[clap(long)]
34+
pub target_transport: Option<String>,
35+
3236
#[clap(long)]
3337
/// Set a kernel argument
3438
pub karg: Vec<String>,
@@ -57,6 +61,11 @@ impl InstallOptions {
5761
args.push(format!("--karg={k}"));
5862
}
5963

64+
if let Some(ref t) = self.target_transport {
65+
args.push("--target-transport".to_string());
66+
args.push(t.clone());
67+
}
68+
6069
if self.composefs_backend {
6170
args.push("--composefs-backend".to_owned());
6271
}

crates/kit/src/libvirt/run.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use crate::xml_utils;
2222
/// SSH wait timeout in seconds
2323
const SSH_WAIT_TIMEOUT_SECONDS: u64 = 180;
2424

25+
/// Transport type for updating from host container storage
26+
const UPDATE_FROM_HOST_TRANSPORT: &str = "containers-storage";
27+
2528
/// Create a virsh command with optional connection URI
2629
pub(super) fn virsh_command(connect_uri: Option<&str>) -> Result<std::process::Command> {
2730
let mut cmd = std::process::Command::new("virsh");
@@ -264,6 +267,11 @@ pub struct LibvirtRunOpts {
264267
#[clap(long = "bind-storage-ro")]
265268
pub bind_storage_ro: bool,
266269

270+
/// Implies --bind-storage-ro, but also configure to update from the host
271+
/// container storage by default.
272+
#[clap(long, conflicts_with = "target_transport")]
273+
pub update_from_host: bool,
274+
267275
/// Firmware type for the VM (defaults to uefi-secure)
268276
#[clap(long, default_value = "uefi-secure")]
269277
pub firmware: FirmwareType,
@@ -381,7 +389,7 @@ fn wait_for_ssh_ready(
381389
}
382390

383391
/// Execute the libvirt run command
384-
pub fn run(global_opts: &crate::libvirt::LibvirtOptions, opts: LibvirtRunOpts) -> Result<()> {
392+
pub fn run(global_opts: &crate::libvirt::LibvirtOptions, mut opts: LibvirtRunOpts) -> Result<()> {
385393
use crate::images;
386394

387395
// Validate labels don't contain commas
@@ -417,6 +425,11 @@ pub fn run(global_opts: &crate::libvirt::LibvirtOptions, opts: LibvirtRunOpts) -
417425
let image_digest = inspect.digest.to_string();
418426
debug!("Image digest: {}", image_digest);
419427

428+
if opts.update_from_host {
429+
opts.bind_storage_ro = true;
430+
opts.install.target_transport = Some(UPDATE_FROM_HOST_TRANSPORT.to_owned());
431+
}
432+
420433
// Phase 1: Find or create a base disk image
421434
let base_disk_path = crate::libvirt::base_disks::find_or_create_base_disk(
422435
&opts.image,

docs/src/man/bcvk-libvirt-run.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Run a bootable container as a persistent VM
5757

5858
Path to host container storage (auto-detected if not specified)
5959

60+
**--target-transport**=*TARGET_TRANSPORT*
61+
62+
The transport; e.g. oci, oci-archive, containers-storage. Defaults to `registry`
63+
6064
**--karg**=*KARG*
6165

6266
Set a kernel argument
@@ -103,6 +107,10 @@ Run a bootable container as a persistent VM
103107

104108
Mount host container storage (RO) at /run/host-container-storage
105109

110+
**--update-from-host**
111+
112+
Implies --bind-storage-ro, but also configure to update from the host container storage by default
113+
106114
**--firmware**=*FIRMWARE*
107115

108116
Firmware type for the VM (defaults to uefi-secure)

docs/src/man/bcvk-libvirt-upload.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Upload bootc disk images to libvirt with metadata annotations
4545

4646
Path to host container storage (auto-detected if not specified)
4747

48+
**--target-transport**=*TARGET_TRANSPORT*
49+
50+
The transport; e.g. oci, oci-archive, containers-storage. Defaults to `registry`
51+
4852
**--karg**=*KARG*
4953

5054
Set a kernel argument

docs/src/man/bcvk-to-disk.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ The installation process:
4747

4848
Path to host container storage (auto-detected if not specified)
4949

50+
**--target-transport**=*TARGET_TRANSPORT*
51+
52+
The transport; e.g. oci, oci-archive, containers-storage. Defaults to `registry`
53+
5054
**--karg**=*KARG*
5155

5256
Set a kernel argument

0 commit comments

Comments
 (0)