feat: implement oci image progress (#64)

* feat: oci progress events

* feat: oci progress bars on launch
This commit is contained in:
Alex Zenla
2024-04-12 11:09:26 -07:00
committed by GitHub
parent 6cef03bffa
commit 6d07112e3d
26 changed files with 630 additions and 159 deletions

42
crates/daemon/src/oci.rs Normal file
View File

@ -0,0 +1,42 @@
use krata::v1::control::{
OciProgressEvent, OciProgressEventLayer, OciProgressEventLayerPhase, OciProgressEventPhase,
};
use krataoci::progress::{OciProgress, OciProgressLayer, OciProgressLayerPhase, OciProgressPhase};
fn convert_oci_layer_progress(layer: OciProgressLayer) -> OciProgressEventLayer {
OciProgressEventLayer {
id: layer.id,
phase: match layer.phase {
OciProgressLayerPhase::Waiting => OciProgressEventLayerPhase::Waiting,
OciProgressLayerPhase::Downloading => OciProgressEventLayerPhase::Downloading,
OciProgressLayerPhase::Downloaded => OciProgressEventLayerPhase::Downloaded,
OciProgressLayerPhase::Extracting => OciProgressEventLayerPhase::Extracting,
OciProgressLayerPhase::Extracted => OciProgressEventLayerPhase::Extracted,
}
.into(),
value: layer.value,
total: layer.total,
}
}
pub fn convert_oci_progress(oci: OciProgress) -> OciProgressEvent {
OciProgressEvent {
guest_id: oci.id,
phase: match oci.phase {
OciProgressPhase::Resolving => OciProgressEventPhase::Resolving,
OciProgressPhase::Resolved => OciProgressEventPhase::Resolved,
OciProgressPhase::ConfigAcquire => OciProgressEventPhase::ConfigAcquire,
OciProgressPhase::LayerAcquire => OciProgressEventPhase::LayerAcquire,
OciProgressPhase::Packing => OciProgressEventPhase::Packing,
OciProgressPhase::Complete => OciProgressEventPhase::Complete,
}
.into(),
layers: oci
.layers
.into_values()
.map(convert_oci_layer_progress)
.collect::<Vec<_>>(),
value: oci.value,
total: oci.total,
}
}