mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-02 21:00:55 +00:00
feat: implement oci image progress (#64)
* feat: oci progress events * feat: oci progress bars on launch
This commit is contained in:
parent
6cef03bffa
commit
6d07112e3d
55
Cargo.lock
generated
55
Cargo.lock
generated
@ -421,6 +421,19 @@ dependencies = [
|
|||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console"
|
||||||
|
version = "0.15.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb"
|
||||||
|
dependencies = [
|
||||||
|
"encode_unicode",
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
"unicode-width",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
version = "0.8.6"
|
version = "0.8.6"
|
||||||
@ -693,6 +706,12 @@ version = "0.7.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b"
|
checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "encode_unicode"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_filter"
|
name = "env_filter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -1223,6 +1242,28 @@ dependencies = [
|
|||||||
"hashbrown 0.14.3",
|
"hashbrown 0.14.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indicatif"
|
||||||
|
version = "0.17.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3"
|
||||||
|
dependencies = [
|
||||||
|
"console",
|
||||||
|
"instant",
|
||||||
|
"number_prefix",
|
||||||
|
"portable-atomic",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.9.0"
|
version = "2.9.0"
|
||||||
@ -1321,6 +1362,7 @@ dependencies = [
|
|||||||
"env_logger",
|
"env_logger",
|
||||||
"fancy-duration",
|
"fancy-duration",
|
||||||
"human_bytes",
|
"human_bytes",
|
||||||
|
"indicatif",
|
||||||
"krata",
|
"krata",
|
||||||
"log",
|
"log",
|
||||||
"prost-reflect",
|
"prost-reflect",
|
||||||
@ -1347,6 +1389,7 @@ dependencies = [
|
|||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"krata",
|
"krata",
|
||||||
|
"krata-oci",
|
||||||
"krata-runtime",
|
"krata-runtime",
|
||||||
"log",
|
"log",
|
||||||
"prost",
|
"prost",
|
||||||
@ -1801,6 +1844,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_prefix"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.32.2"
|
version = "0.32.2"
|
||||||
@ -1945,6 +1994,12 @@ version = "0.3.30"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
|
@ -42,6 +42,7 @@ fancy-duration = "0.9.2"
|
|||||||
flate2 = "1.0"
|
flate2 = "1.0"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
human_bytes = "0.4"
|
human_bytes = "0.4"
|
||||||
|
indicatif = "0.17.8"
|
||||||
ipnetwork = "0.20.0"
|
ipnetwork = "0.20.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
|
@ -18,6 +18,7 @@ ctrlc = { workspace = true, features = ["termination"] }
|
|||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
fancy-duration = { workspace = true }
|
fancy-duration = { workspace = true }
|
||||||
human_bytes = { workspace = true }
|
human_bytes = { workspace = true }
|
||||||
|
indicatif = { workspace = true }
|
||||||
krata = { path = "../krata", version = "^0.0.8" }
|
krata = { path = "../krata", version = "^0.0.8" }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
prost-reflect = { workspace = true, features = ["serde"] }
|
prost-reflect = { workspace = true, features = ["serde"] }
|
||||||
|
@ -52,8 +52,7 @@ impl DestroyCommand {
|
|||||||
async fn wait_guest_destroyed(id: &str, events: EventStream) -> Result<()> {
|
async fn wait_guest_destroyed(id: &str, events: EventStream) -> Result<()> {
|
||||||
let mut stream = events.subscribe();
|
let mut stream = events.subscribe();
|
||||||
while let Ok(event) = stream.recv().await {
|
while let Ok(event) = stream.recv().await {
|
||||||
match event {
|
if let Event::GuestChanged(changed) = event {
|
||||||
Event::GuestChanged(changed) => {
|
|
||||||
let Some(guest) = changed.guest else {
|
let Some(guest) = changed.guest else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@ -80,6 +79,5 @@ async fn wait_guest_destroyed(id: &str, events: EventStream) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||||
use krata::{
|
use krata::{
|
||||||
events::EventStream,
|
events::EventStream,
|
||||||
v1::{
|
v1::{
|
||||||
@ -11,7 +12,7 @@ use krata::{
|
|||||||
},
|
},
|
||||||
control::{
|
control::{
|
||||||
control_service_client::ControlServiceClient, watch_events_reply::Event,
|
control_service_client::ControlServiceClient, watch_events_reply::Event,
|
||||||
CreateGuestRequest,
|
CreateGuestRequest, OciProgressEventLayerPhase, OciProgressEventPhase,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -125,9 +126,14 @@ impl LauchCommand {
|
|||||||
|
|
||||||
async fn wait_guest_started(id: &str, events: EventStream) -> Result<()> {
|
async fn wait_guest_started(id: &str, events: EventStream) -> Result<()> {
|
||||||
let mut stream = events.subscribe();
|
let mut stream = events.subscribe();
|
||||||
|
let mut multi_progress: Option<(MultiProgress, HashMap<String, ProgressBar>)> = None;
|
||||||
while let Ok(event) = stream.recv().await {
|
while let Ok(event) = stream.recv().await {
|
||||||
match event {
|
match event {
|
||||||
Event::GuestChanged(changed) => {
|
Event::GuestChanged(changed) => {
|
||||||
|
if let Some((multi_progress, _)) = multi_progress.as_mut() {
|
||||||
|
let _ = multi_progress.clear();
|
||||||
|
}
|
||||||
|
|
||||||
let Some(guest) = changed.guest else {
|
let Some(guest) = changed.guest else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@ -158,6 +164,84 @@ async fn wait_guest_started(id: &str, events: EventStream) -> Result<()> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event::OciProgress(oci) => {
|
||||||
|
if multi_progress.is_none() {
|
||||||
|
multi_progress = Some((MultiProgress::new(), HashMap::new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some((multi_progress, progresses)) = multi_progress.as_mut() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
match oci.phase() {
|
||||||
|
OciProgressEventPhase::Resolved
|
||||||
|
| OciProgressEventPhase::ConfigAcquire
|
||||||
|
| OciProgressEventPhase::LayerAcquire => {
|
||||||
|
if progresses.is_empty() && !oci.layers.is_empty() {
|
||||||
|
for layer in &oci.layers {
|
||||||
|
let bar = ProgressBar::new(layer.total);
|
||||||
|
bar.set_style(
|
||||||
|
ProgressStyle::with_template("{msg} {wide_bar} {pos}/{len}")
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
progresses.insert(layer.id.clone(), bar.clone());
|
||||||
|
multi_progress.add(bar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for layer in oci.layers {
|
||||||
|
let Some(progress) = progresses.get_mut(&layer.id) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let phase = match layer.phase() {
|
||||||
|
OciProgressEventLayerPhase::Waiting => "waiting",
|
||||||
|
OciProgressEventLayerPhase::Downloading => "downloading",
|
||||||
|
OciProgressEventLayerPhase::Downloaded => "downloaded",
|
||||||
|
OciProgressEventLayerPhase::Extracting => "extracting",
|
||||||
|
OciProgressEventLayerPhase::Extracted => "extracted",
|
||||||
|
_ => "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
progress.set_message(format!("{} {}", layer.id, phase));
|
||||||
|
progress.set_length(layer.total);
|
||||||
|
progress.set_position(layer.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OciProgressEventPhase::Packing => {
|
||||||
|
for (key, progress) in &mut *progresses {
|
||||||
|
if key == "packing" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
progress.finish_and_clear();
|
||||||
|
multi_progress.remove(progress);
|
||||||
|
}
|
||||||
|
progresses.retain(|k, _| k == "packing");
|
||||||
|
if progresses.is_empty() {
|
||||||
|
let progress = ProgressBar::new(100);
|
||||||
|
progress.set_style(
|
||||||
|
ProgressStyle::with_template("{msg} {wide_bar} {pos}/{len}")
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
progresses.insert("packing".to_string(), progress);
|
||||||
|
}
|
||||||
|
let Some(progress) = progresses.get("packing") else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
progress.set_message("packing image");
|
||||||
|
progress.set_length(oci.total);
|
||||||
|
progress.set_position(oci.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
for progress in progresses {
|
||||||
|
progress.1.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -28,14 +28,13 @@ impl WatchCommand {
|
|||||||
let mut stream = events.subscribe();
|
let mut stream = events.subscribe();
|
||||||
loop {
|
loop {
|
||||||
let event = stream.recv().await?;
|
let event = stream.recv().await?;
|
||||||
match event {
|
|
||||||
Event::GuestChanged(changed) => {
|
if let Event::GuestChanged(changed) = event {
|
||||||
let guest = changed.guest.clone();
|
let guest = changed.guest.clone();
|
||||||
self.print_event("guest.changed", changed, guest)?;
|
self.print_event("guest.changed", changed, guest)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn print_event(
|
fn print_event(
|
||||||
&self,
|
&self,
|
||||||
|
@ -69,8 +69,7 @@ impl StdioConsoleStream {
|
|||||||
Ok(tokio::task::spawn(async move {
|
Ok(tokio::task::spawn(async move {
|
||||||
let mut stream = events.subscribe();
|
let mut stream = events.subscribe();
|
||||||
while let Ok(event) = stream.recv().await {
|
while let Ok(event) = stream.recv().await {
|
||||||
match event {
|
if let Event::GuestChanged(changed) = event {
|
||||||
Event::GuestChanged(changed) => {
|
|
||||||
let Some(guest) = changed.guest else {
|
let Some(guest) = changed.guest else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@ -93,7 +92,6 @@ impl StdioConsoleStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ clap = { workspace = true }
|
|||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
futures = { workspace = true }
|
futures = { workspace = true }
|
||||||
krata = { path = "../krata", version = "^0.0.8" }
|
krata = { path = "../krata", version = "^0.0.8" }
|
||||||
|
krata-oci = { path = "../oci", version = "^0.0.8" }
|
||||||
krata-runtime = { path = "../runtime", version = "^0.0.8" }
|
krata-runtime = { path = "../runtime", version = "^0.0.8" }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
prost = { workspace = true }
|
prost = { workspace = true }
|
||||||
|
@ -3,7 +3,6 @@ use clap::Parser;
|
|||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use krata::dial::ControlDialAddress;
|
use krata::dial::ControlDialAddress;
|
||||||
use kratad::Daemon;
|
use kratad::Daemon;
|
||||||
use kratart::Runtime;
|
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use std::{
|
use std::{
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
@ -27,8 +26,8 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
let args = DaemonCommand::parse();
|
let args = DaemonCommand::parse();
|
||||||
let addr = ControlDialAddress::from_str(&args.listen)?;
|
let addr = ControlDialAddress::from_str(&args.listen)?;
|
||||||
let runtime = Runtime::new(args.store.clone()).await?;
|
|
||||||
let mut daemon = Daemon::new(args.store.clone(), runtime).await?;
|
let mut daemon = Daemon::new(args.store.clone()).await?;
|
||||||
daemon.listen(addr).await?;
|
daemon.listen(addr).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ use krata::{
|
|||||||
idm::protocol::{idm_event::Event, IdmEvent},
|
idm::protocol::{idm_event::Event, IdmEvent},
|
||||||
v1::common::{GuestExitInfo, GuestState, GuestStatus},
|
v1::common::{GuestExitInfo, GuestState, GuestStatus},
|
||||||
};
|
};
|
||||||
|
use krataoci::progress::OciProgress;
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
select,
|
select,
|
||||||
@ -21,7 +22,7 @@ use tokio::{
|
|||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{db::GuestStore, idm::DaemonIdmHandle};
|
use crate::{db::GuestStore, idm::DaemonIdmHandle, oci::convert_oci_progress};
|
||||||
|
|
||||||
pub type DaemonEvent = krata::v1::control::watch_events_reply::Event;
|
pub type DaemonEvent = krata::v1::control::watch_events_reply::Event;
|
||||||
|
|
||||||
@ -52,7 +53,8 @@ pub struct DaemonEventGenerator {
|
|||||||
idms: HashMap<u32, (Uuid, JoinHandle<()>)>,
|
idms: HashMap<u32, (Uuid, JoinHandle<()>)>,
|
||||||
idm_sender: Sender<(u32, IdmEvent)>,
|
idm_sender: Sender<(u32, IdmEvent)>,
|
||||||
idm_receiver: Receiver<(u32, IdmEvent)>,
|
idm_receiver: Receiver<(u32, IdmEvent)>,
|
||||||
_event_sender: broadcast::Sender<DaemonEvent>,
|
oci_progress_receiver: broadcast::Receiver<OciProgress>,
|
||||||
|
event_sender: broadcast::Sender<DaemonEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DaemonEventGenerator {
|
impl DaemonEventGenerator {
|
||||||
@ -60,6 +62,7 @@ impl DaemonEventGenerator {
|
|||||||
guests: GuestStore,
|
guests: GuestStore,
|
||||||
guest_reconciler_notify: Sender<Uuid>,
|
guest_reconciler_notify: Sender<Uuid>,
|
||||||
idm: DaemonIdmHandle,
|
idm: DaemonIdmHandle,
|
||||||
|
oci_progress_receiver: broadcast::Receiver<OciProgress>,
|
||||||
) -> Result<(DaemonEventContext, DaemonEventGenerator)> {
|
) -> Result<(DaemonEventContext, DaemonEventGenerator)> {
|
||||||
let (sender, _) = broadcast::channel(EVENT_CHANNEL_QUEUE_LEN);
|
let (sender, _) = broadcast::channel(EVENT_CHANNEL_QUEUE_LEN);
|
||||||
let (idm_sender, idm_receiver) = channel(IDM_EVENT_CHANNEL_QUEUE_LEN);
|
let (idm_sender, idm_receiver) = channel(IDM_EVENT_CHANNEL_QUEUE_LEN);
|
||||||
@ -71,15 +74,15 @@ impl DaemonEventGenerator {
|
|||||||
idms: HashMap::new(),
|
idms: HashMap::new(),
|
||||||
idm_sender,
|
idm_sender,
|
||||||
idm_receiver,
|
idm_receiver,
|
||||||
_event_sender: sender.clone(),
|
oci_progress_receiver,
|
||||||
|
event_sender: sender.clone(),
|
||||||
};
|
};
|
||||||
let context = DaemonEventContext { sender };
|
let context = DaemonEventContext { sender };
|
||||||
Ok((context, generator))
|
Ok((context, generator))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_feed_event(&mut self, event: &DaemonEvent) -> Result<()> {
|
async fn handle_feed_event(&mut self, event: &DaemonEvent) -> Result<()> {
|
||||||
match event {
|
if let DaemonEvent::GuestChanged(changed) = event {
|
||||||
DaemonEvent::GuestChanged(changed) => {
|
|
||||||
let Some(ref guest) = changed.guest else {
|
let Some(ref guest) = changed.guest else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
@ -121,7 +124,6 @@ impl DaemonEventGenerator {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,6 +150,17 @@ impl DaemonEventGenerator {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_oci_progress_event(&mut self, progress: OciProgress) -> Result<()> {
|
||||||
|
let Some(_) = Uuid::from_str(&progress.id).ok() else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
let event = convert_oci_progress(progress);
|
||||||
|
self.event_sender.send(DaemonEvent::OciProgress(event))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn evaluate(&mut self) -> Result<()> {
|
async fn evaluate(&mut self) -> Result<()> {
|
||||||
select! {
|
select! {
|
||||||
x = self.idm_receiver.recv() => match x {
|
x = self.idm_receiver.recv() => match x {
|
||||||
@ -168,6 +181,14 @@ impl DaemonEventGenerator {
|
|||||||
Err(error) => {
|
Err(error) => {
|
||||||
Err(error.into())
|
Err(error.into())
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
x = self.oci_progress_receiver.recv() => match x {
|
||||||
|
Ok(event) => {
|
||||||
|
self.handle_oci_progress_event(event).await
|
||||||
|
},
|
||||||
|
Err(error) => {
|
||||||
|
Err(error.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,16 @@ use db::GuestStore;
|
|||||||
use event::{DaemonEventContext, DaemonEventGenerator};
|
use event::{DaemonEventContext, DaemonEventGenerator};
|
||||||
use idm::{DaemonIdm, DaemonIdmHandle};
|
use idm::{DaemonIdm, DaemonIdmHandle};
|
||||||
use krata::{dial::ControlDialAddress, v1::control::control_service_server::ControlServiceServer};
|
use krata::{dial::ControlDialAddress, v1::control::control_service_server::ControlServiceServer};
|
||||||
|
use krataoci::progress::OciProgressContext;
|
||||||
use kratart::Runtime;
|
use kratart::Runtime;
|
||||||
use log::info;
|
use log::info;
|
||||||
use reconcile::guest::GuestReconciler;
|
use reconcile::guest::GuestReconciler;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
net::UnixListener,
|
net::UnixListener,
|
||||||
sync::mpsc::{channel, Sender},
|
sync::{
|
||||||
|
broadcast,
|
||||||
|
mpsc::{channel, Sender},
|
||||||
|
},
|
||||||
task::JoinHandle,
|
task::JoinHandle,
|
||||||
};
|
};
|
||||||
use tokio_stream::wrappers::UnixListenerStream;
|
use tokio_stream::wrappers::UnixListenerStream;
|
||||||
@ -25,6 +29,7 @@ pub mod db;
|
|||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod idm;
|
pub mod idm;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
|
pub mod oci;
|
||||||
pub mod reconcile;
|
pub mod reconcile;
|
||||||
|
|
||||||
pub struct Daemon {
|
pub struct Daemon {
|
||||||
@ -39,9 +44,14 @@ pub struct Daemon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const GUEST_RECONCILER_QUEUE_LEN: usize = 1000;
|
const GUEST_RECONCILER_QUEUE_LEN: usize = 1000;
|
||||||
|
const OCI_PROGRESS_QUEUE_LEN: usize = 1000;
|
||||||
|
|
||||||
impl Daemon {
|
impl Daemon {
|
||||||
pub async fn new(store: String, runtime: Runtime) -> Result<Self> {
|
pub async fn new(store: String) -> Result<Self> {
|
||||||
|
let (oci_progress_sender, oci_progress_receiver) =
|
||||||
|
broadcast::channel(OCI_PROGRESS_QUEUE_LEN);
|
||||||
|
let runtime =
|
||||||
|
Runtime::new(OciProgressContext::new(oci_progress_sender), store.clone()).await?;
|
||||||
let guests_db_path = format!("{}/guests.db", store);
|
let guests_db_path = format!("{}/guests.db", store);
|
||||||
let guests = GuestStore::open(&PathBuf::from(guests_db_path))?;
|
let guests = GuestStore::open(&PathBuf::from(guests_db_path))?;
|
||||||
let (guest_reconciler_notify, guest_reconciler_receiver) =
|
let (guest_reconciler_notify, guest_reconciler_receiver) =
|
||||||
@ -50,8 +60,12 @@ impl Daemon {
|
|||||||
let idm = idm.launch().await?;
|
let idm = idm.launch().await?;
|
||||||
let console = DaemonConsole::new().await?;
|
let console = DaemonConsole::new().await?;
|
||||||
let console = console.launch().await?;
|
let console = console.launch().await?;
|
||||||
let (events, generator) =
|
let (events, generator) = DaemonEventGenerator::new(
|
||||||
DaemonEventGenerator::new(guests.clone(), guest_reconciler_notify.clone(), idm.clone())
|
guests.clone(),
|
||||||
|
guest_reconciler_notify.clone(),
|
||||||
|
idm.clone(),
|
||||||
|
oci_progress_receiver,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let runtime_for_reconciler = runtime.dupe().await?;
|
let runtime_for_reconciler = runtime.dupe().await?;
|
||||||
let guest_reconciler = GuestReconciler::new(
|
let guest_reconciler = GuestReconciler::new(
|
||||||
|
42
crates/daemon/src/oci.rs
Normal file
42
crates/daemon/src/oci.rs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
@ -61,6 +61,7 @@ message WatchEventsRequest {}
|
|||||||
message WatchEventsReply {
|
message WatchEventsReply {
|
||||||
oneof event {
|
oneof event {
|
||||||
GuestChangedEvent guest_changed = 1;
|
GuestChangedEvent guest_changed = 1;
|
||||||
|
OciProgressEvent oci_progress = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +69,40 @@ message GuestChangedEvent {
|
|||||||
krata.v1.common.Guest guest = 1;
|
krata.v1.common.Guest guest = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OciProgressEventLayerPhase {
|
||||||
|
OCI_PROGRESS_EVENT_LAYER_PHASE_UNKNOWN = 0;
|
||||||
|
OCI_PROGRESS_EVENT_LAYER_PHASE_WAITING = 1;
|
||||||
|
OCI_PROGRESS_EVENT_LAYER_PHASE_DOWNLOADING = 2;
|
||||||
|
OCI_PROGRESS_EVENT_LAYER_PHASE_DOWNLOADED = 3;
|
||||||
|
OCI_PROGRESS_EVENT_LAYER_PHASE_EXTRACTING = 4;
|
||||||
|
OCI_PROGRESS_EVENT_LAYER_PHASE_EXTRACTED = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message OciProgressEventLayer {
|
||||||
|
string id = 1;
|
||||||
|
OciProgressEventLayerPhase phase = 2;
|
||||||
|
uint64 value = 3;
|
||||||
|
uint64 total = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum OciProgressEventPhase {
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_UNKNOWN = 0;
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_RESOLVING = 1;
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_RESOLVED = 2;
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_CONFIG_ACQUIRE = 3;
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_LAYER_ACQUIRE = 4;
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_PACKING = 5;
|
||||||
|
OCI_PROGRESS_EVENT_PHASE_COMPLETE = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message OciProgressEvent {
|
||||||
|
string guest_id = 1;
|
||||||
|
OciProgressEventPhase phase = 2;
|
||||||
|
repeated OciProgressEventLayer layers = 3;
|
||||||
|
uint64 value = 4;
|
||||||
|
uint64 total = 5;
|
||||||
|
}
|
||||||
|
|
||||||
message ReadGuestMetricsRequest {
|
message ReadGuestMetricsRequest {
|
||||||
string guest_id = 1;
|
string guest_id = 1;
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
#![allow(clippy::all)]
|
||||||
tonic::include_proto!("krata.v1.common");
|
tonic::include_proto!("krata.v1.common");
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
#![allow(clippy::all)]
|
||||||
tonic::include_proto!("krata.v1.control");
|
tonic::include_proto!("krata.v1.control");
|
||||||
|
@ -179,6 +179,8 @@ impl AutoNetworkWatcher {
|
|||||||
break;
|
break;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Ok(_) => {},
|
||||||
|
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
warn!("failed to receive event: {}", error);
|
warn!("failed to receive event: {}", error);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ use std::{env::args, path::PathBuf};
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use krataoci::{cache::ImageCache, compiler::ImageCompiler, name::ImageName};
|
use krataoci::{
|
||||||
use tokio::fs;
|
cache::ImageCache, compiler::ImageCompiler, name::ImageName, progress::OciProgressContext,
|
||||||
|
};
|
||||||
|
use tokio::{fs, sync::broadcast};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@ -18,8 +20,18 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cache = ImageCache::new(&cache_dir)?;
|
let cache = ImageCache::new(&cache_dir)?;
|
||||||
let compiler = ImageCompiler::new(&cache, seed)?;
|
|
||||||
let info = compiler.compile(&image).await?;
|
let (sender, mut receiver) = broadcast::channel(1000);
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
loop {
|
||||||
|
let Some(_) = receiver.recv().await.ok() else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let context = OciProgressContext::new(sender);
|
||||||
|
let compiler = ImageCompiler::new(&cache, seed, context)?;
|
||||||
|
let info = compiler.compile(&image.to_string(), &image).await?;
|
||||||
println!(
|
println!(
|
||||||
"generated squashfs of {} to {}",
|
"generated squashfs of {} to {}",
|
||||||
image,
|
image,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::cache::ImageCache;
|
use crate::cache::ImageCache;
|
||||||
use crate::fetch::{OciImageDownloader, OciImageLayer};
|
use crate::fetch::{OciImageDownloader, OciImageLayer};
|
||||||
use crate::name::ImageName;
|
use crate::name::ImageName;
|
||||||
|
use crate::progress::{OciProgress, OciProgressContext, OciProgressPhase};
|
||||||
use crate::registry::OciRegistryPlatform;
|
use crate::registry::OciRegistryPlatform;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use backhand::compression::Compressor;
|
use backhand::compression::Compressor;
|
||||||
@ -8,6 +9,7 @@ use backhand::{FilesystemCompressor, FilesystemWriter, NodeHeader};
|
|||||||
use log::{debug, trace, warn};
|
use log::{debug, trace, warn};
|
||||||
use oci_spec::image::{ImageConfiguration, ImageManifest};
|
use oci_spec::image::{ImageConfiguration, ImageManifest};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufWriter, ErrorKind, Read};
|
use std::io::{BufWriter, ErrorKind, Read};
|
||||||
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
||||||
@ -45,14 +47,23 @@ impl ImageInfo {
|
|||||||
pub struct ImageCompiler<'a> {
|
pub struct ImageCompiler<'a> {
|
||||||
cache: &'a ImageCache,
|
cache: &'a ImageCache,
|
||||||
seed: Option<PathBuf>,
|
seed: Option<PathBuf>,
|
||||||
|
progress: OciProgressContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageCompiler<'_> {
|
impl ImageCompiler<'_> {
|
||||||
pub fn new(cache: &ImageCache, seed: Option<PathBuf>) -> Result<ImageCompiler> {
|
pub fn new(
|
||||||
Ok(ImageCompiler { cache, seed })
|
cache: &ImageCache,
|
||||||
|
seed: Option<PathBuf>,
|
||||||
|
progress: OciProgressContext,
|
||||||
|
) -> Result<ImageCompiler> {
|
||||||
|
Ok(ImageCompiler {
|
||||||
|
cache,
|
||||||
|
seed,
|
||||||
|
progress,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn compile(&self, image: &ImageName) -> Result<ImageInfo> {
|
pub async fn compile(&self, id: &str, image: &ImageName) -> Result<ImageInfo> {
|
||||||
debug!("compile image={image}");
|
debug!("compile image={image}");
|
||||||
let mut tmp_dir = std::env::temp_dir().clone();
|
let mut tmp_dir = std::env::temp_dir().clone();
|
||||||
tmp_dir.push(format!("krata-compile-{}", Uuid::new_v4()));
|
tmp_dir.push(format!("krata-compile-{}", Uuid::new_v4()));
|
||||||
@ -68,7 +79,7 @@ impl ImageCompiler<'_> {
|
|||||||
let mut squash_file = tmp_dir.clone();
|
let mut squash_file = tmp_dir.clone();
|
||||||
squash_file.push("image.squashfs");
|
squash_file.push("image.squashfs");
|
||||||
let info = self
|
let info = self
|
||||||
.download_and_compile(image, &layer_dir, &image_dir, &squash_file)
|
.download_and_compile(id, image, &layer_dir, &image_dir, &squash_file)
|
||||||
.await?;
|
.await?;
|
||||||
fs::remove_dir_all(&tmp_dir).await?;
|
fs::remove_dir_all(&tmp_dir).await?;
|
||||||
Ok(info)
|
Ok(info)
|
||||||
@ -76,15 +87,25 @@ impl ImageCompiler<'_> {
|
|||||||
|
|
||||||
async fn download_and_compile(
|
async fn download_and_compile(
|
||||||
&self,
|
&self,
|
||||||
|
id: &str,
|
||||||
image: &ImageName,
|
image: &ImageName,
|
||||||
layer_dir: &Path,
|
layer_dir: &Path,
|
||||||
image_dir: &Path,
|
image_dir: &Path,
|
||||||
squash_file: &Path,
|
squash_file: &Path,
|
||||||
) -> Result<ImageInfo> {
|
) -> Result<ImageInfo> {
|
||||||
|
let mut progress = OciProgress {
|
||||||
|
id: id.to_string(),
|
||||||
|
phase: OciProgressPhase::Resolving,
|
||||||
|
layers: BTreeMap::new(),
|
||||||
|
value: 0,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
self.progress.update(&progress);
|
||||||
let downloader = OciImageDownloader::new(
|
let downloader = OciImageDownloader::new(
|
||||||
self.seed.clone(),
|
self.seed.clone(),
|
||||||
layer_dir.to_path_buf(),
|
layer_dir.to_path_buf(),
|
||||||
OciRegistryPlatform::current(),
|
OciRegistryPlatform::current(),
|
||||||
|
self.progress.clone(),
|
||||||
);
|
);
|
||||||
let resolved = downloader.resolve(image.clone()).await?;
|
let resolved = downloader.resolve(image.clone()).await?;
|
||||||
let cache_key = format!(
|
let cache_key = format!(
|
||||||
@ -93,28 +114,44 @@ impl ImageCompiler<'_> {
|
|||||||
);
|
);
|
||||||
let cache_digest = sha256::digest(cache_key);
|
let cache_digest = sha256::digest(cache_key);
|
||||||
|
|
||||||
|
progress.phase = OciProgressPhase::Complete;
|
||||||
|
self.progress.update(&progress);
|
||||||
if let Some(cached) = self.cache.recall(&cache_digest).await? {
|
if let Some(cached) = self.cache.recall(&cache_digest).await? {
|
||||||
return Ok(cached);
|
return Ok(cached);
|
||||||
}
|
}
|
||||||
|
|
||||||
let local = downloader.download(resolved).await?;
|
progress.phase = OciProgressPhase::Resolved;
|
||||||
|
for layer in resolved.manifest.layers() {
|
||||||
|
progress.add_layer(layer.digest());
|
||||||
|
}
|
||||||
|
self.progress.update(&progress);
|
||||||
|
|
||||||
|
let local = downloader.download(resolved, &mut progress).await?;
|
||||||
for layer in &local.layers {
|
for layer in &local.layers {
|
||||||
debug!(
|
debug!(
|
||||||
"process layer digest={} compression={:?}",
|
"process layer digest={} compression={:?}",
|
||||||
&layer.digest, layer.compression,
|
&layer.digest, layer.compression,
|
||||||
);
|
);
|
||||||
let whiteouts = self.process_layer_whiteout(layer, image_dir).await?;
|
progress.extracting_layer(&layer.digest, 0, 0);
|
||||||
|
self.progress.update(&progress);
|
||||||
|
let (whiteouts, count) = self.process_layer_whiteout(layer, image_dir).await?;
|
||||||
|
progress.extracting_layer(&layer.digest, 0, count);
|
||||||
|
self.progress.update(&progress);
|
||||||
debug!(
|
debug!(
|
||||||
"process layer digest={} whiteouts={:?}",
|
"process layer digest={} whiteouts={:?}",
|
||||||
&layer.digest, whiteouts
|
&layer.digest, whiteouts
|
||||||
);
|
);
|
||||||
let mut archive = layer.archive().await?;
|
let mut archive = layer.archive().await?;
|
||||||
let mut entries = archive.entries()?;
|
let mut entries = archive.entries()?;
|
||||||
|
let mut completed = 0;
|
||||||
while let Some(entry) = entries.next().await {
|
while let Some(entry) = entries.next().await {
|
||||||
let mut entry = entry?;
|
let mut entry = entry?;
|
||||||
let path = entry.path()?;
|
let path = entry.path()?;
|
||||||
let mut maybe_whiteout_path_str =
|
let mut maybe_whiteout_path_str =
|
||||||
path.to_str().map(|x| x.to_string()).unwrap_or_default();
|
path.to_str().map(|x| x.to_string()).unwrap_or_default();
|
||||||
|
progress.extracting_layer(&layer.digest, completed, count);
|
||||||
|
completed += 1;
|
||||||
|
self.progress.update(&progress);
|
||||||
if whiteouts.contains(&maybe_whiteout_path_str) {
|
if whiteouts.contains(&maybe_whiteout_path_str) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -123,10 +160,10 @@ impl ImageCompiler<'_> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let Some(name) = path.file_name() else {
|
let Some(name) = path.file_name() else {
|
||||||
return Err(anyhow!("unable to get file name"));
|
continue;
|
||||||
};
|
};
|
||||||
let Some(name) = name.to_str() else {
|
let Some(name) = name.to_str() else {
|
||||||
return Err(anyhow!("unable to get file name as string"));
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if name.starts_with(".wh.") {
|
if name.starts_with(".wh.") {
|
||||||
@ -136,6 +173,8 @@ impl ImageCompiler<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
progress.extracted_layer(&layer.digest);
|
||||||
|
self.progress.update(&progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
for layer in &local.layers {
|
for layer in &local.layers {
|
||||||
@ -144,31 +183,51 @@ impl ImageCompiler<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.squash(image_dir, squash_file)?;
|
let image_dir_squash = image_dir.to_path_buf();
|
||||||
|
let squash_file_squash = squash_file.to_path_buf();
|
||||||
|
let progress_squash = progress.clone();
|
||||||
|
let progress_context = self.progress.clone();
|
||||||
|
progress = tokio::task::spawn_blocking(move || {
|
||||||
|
ImageCompiler::squash(
|
||||||
|
&image_dir_squash,
|
||||||
|
&squash_file_squash,
|
||||||
|
progress_squash,
|
||||||
|
progress_context,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
let info = ImageInfo::new(
|
let info = ImageInfo::new(
|
||||||
squash_file.to_path_buf(),
|
squash_file.to_path_buf(),
|
||||||
local.image.manifest,
|
local.image.manifest,
|
||||||
local.config,
|
local.config,
|
||||||
)?;
|
)?;
|
||||||
self.cache.store(&cache_digest, &info).await
|
let info = self.cache.store(&cache_digest, &info).await?;
|
||||||
|
progress.phase = OciProgressPhase::Complete;
|
||||||
|
progress.value = 0;
|
||||||
|
progress.total = 0;
|
||||||
|
self.progress.update(&progress);
|
||||||
|
Ok(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_layer_whiteout(
|
async fn process_layer_whiteout(
|
||||||
&self,
|
&self,
|
||||||
layer: &OciImageLayer,
|
layer: &OciImageLayer,
|
||||||
image_dir: &Path,
|
image_dir: &Path,
|
||||||
) -> Result<Vec<String>> {
|
) -> Result<(Vec<String>, usize)> {
|
||||||
let mut whiteouts = Vec::new();
|
let mut whiteouts = Vec::new();
|
||||||
let mut archive = layer.archive().await?;
|
let mut archive = layer.archive().await?;
|
||||||
let mut entries = archive.entries()?;
|
let mut entries = archive.entries()?;
|
||||||
|
let mut count = 0usize;
|
||||||
while let Some(entry) = entries.next().await {
|
while let Some(entry) = entries.next().await {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
|
count += 1;
|
||||||
let path = entry.path()?;
|
let path = entry.path()?;
|
||||||
let Some(name) = path.file_name() else {
|
let Some(name) = path.file_name() else {
|
||||||
return Err(anyhow!("unable to get file name"));
|
continue;
|
||||||
};
|
};
|
||||||
let Some(name) = name.to_str() else {
|
let Some(name) = name.to_str() else {
|
||||||
return Err(anyhow!("unable to get file name as string"));
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if name.starts_with(".wh.") {
|
if name.starts_with(".wh.") {
|
||||||
@ -180,7 +239,7 @@ impl ImageCompiler<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(whiteouts)
|
Ok((whiteouts, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_whiteout_entry(
|
async fn process_whiteout_entry(
|
||||||
@ -300,7 +359,16 @@ impl ImageCompiler<'_> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn squash(&self, image_dir: &Path, squash_file: &Path) -> Result<()> {
|
fn squash(
|
||||||
|
image_dir: &Path,
|
||||||
|
squash_file: &Path,
|
||||||
|
mut progress: OciProgress,
|
||||||
|
progress_context: OciProgressContext,
|
||||||
|
) -> Result<OciProgress> {
|
||||||
|
progress.phase = OciProgressPhase::Packing;
|
||||||
|
progress.total = 2;
|
||||||
|
progress.value = 0;
|
||||||
|
progress_context.update(&progress);
|
||||||
let mut writer = FilesystemWriter::default();
|
let mut writer = FilesystemWriter::default();
|
||||||
writer.set_compressor(FilesystemCompressor::new(Compressor::Gzip, None)?);
|
writer.set_compressor(FilesystemCompressor::new(Compressor::Gzip, None)?);
|
||||||
let walk = WalkDir::new(image_dir).follow_links(false);
|
let walk = WalkDir::new(image_dir).follow_links(false);
|
||||||
@ -358,6 +426,10 @@ impl ImageCompiler<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress.phase = OciProgressPhase::Packing;
|
||||||
|
progress.value = 1;
|
||||||
|
progress_context.update(&progress);
|
||||||
|
|
||||||
let squash_file_path = squash_file
|
let squash_file_path = squash_file
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or_else(|| anyhow!("failed to convert squashfs string"))?;
|
.ok_or_else(|| anyhow!("failed to convert squashfs string"))?;
|
||||||
@ -367,7 +439,10 @@ impl ImageCompiler<'_> {
|
|||||||
trace!("squash generate: {}", squash_file_path);
|
trace!("squash generate: {}", squash_file_path);
|
||||||
writer.write(&mut bufwrite)?;
|
writer.write(&mut bufwrite)?;
|
||||||
std::fs::remove_dir_all(image_dir)?;
|
std::fs::remove_dir_all(image_dir)?;
|
||||||
Ok(())
|
progress.phase = OciProgressPhase::Packing;
|
||||||
|
progress.value = 2;
|
||||||
|
progress_context.update(&progress);
|
||||||
|
Ok(progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::progress::{OciProgress, OciProgressContext, OciProgressPhase};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
name::ImageName,
|
name::ImageName,
|
||||||
registry::{OciRegistryClient, OciRegistryPlatform},
|
registry::{OciRegistryClient, OciRegistryPlatform},
|
||||||
@ -26,6 +28,7 @@ pub struct OciImageDownloader {
|
|||||||
seed: Option<PathBuf>,
|
seed: Option<PathBuf>,
|
||||||
storage: PathBuf,
|
storage: PathBuf,
|
||||||
platform: OciRegistryPlatform,
|
platform: OciRegistryPlatform,
|
||||||
|
progress: OciProgressContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
@ -79,11 +82,13 @@ impl OciImageDownloader {
|
|||||||
seed: Option<PathBuf>,
|
seed: Option<PathBuf>,
|
||||||
storage: PathBuf,
|
storage: PathBuf,
|
||||||
platform: OciRegistryPlatform,
|
platform: OciRegistryPlatform,
|
||||||
|
progress: OciProgressContext,
|
||||||
) -> OciImageDownloader {
|
) -> OciImageDownloader {
|
||||||
OciImageDownloader {
|
OciImageDownloader {
|
||||||
seed,
|
seed,
|
||||||
storage,
|
storage,
|
||||||
platform,
|
platform,
|
||||||
|
progress,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +213,15 @@ impl OciImageDownloader {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn download(&self, image: OciResolvedImage) -> Result<OciLocalImage> {
|
pub async fn download(
|
||||||
|
&self,
|
||||||
|
image: OciResolvedImage,
|
||||||
|
progress: &mut OciProgress,
|
||||||
|
) -> Result<OciLocalImage> {
|
||||||
let config: ImageConfiguration;
|
let config: ImageConfiguration;
|
||||||
|
|
||||||
|
progress.phase = OciProgressPhase::ConfigAcquire;
|
||||||
|
self.progress.update(progress);
|
||||||
let mut client = OciRegistryClient::new(image.name.registry_url()?, self.platform.clone())?;
|
let mut client = OciRegistryClient::new(image.name.registry_url()?, self.platform.clone())?;
|
||||||
if let Some(seeded) = self
|
if let Some(seeded) = self
|
||||||
.load_seed_json_blob::<ImageConfiguration>(image.manifest.config())
|
.load_seed_json_blob::<ImageConfiguration>(image.manifest.config())
|
||||||
@ -223,9 +234,18 @@ impl OciImageDownloader {
|
|||||||
.await?;
|
.await?;
|
||||||
config = serde_json::from_slice(&config_bytes)?;
|
config = serde_json::from_slice(&config_bytes)?;
|
||||||
}
|
}
|
||||||
|
progress.phase = OciProgressPhase::LayerAcquire;
|
||||||
|
self.progress.update(progress);
|
||||||
let mut layers = Vec::new();
|
let mut layers = Vec::new();
|
||||||
for layer in image.manifest.layers() {
|
for layer in image.manifest.layers() {
|
||||||
layers.push(self.acquire_layer(&image.name, layer, &mut client).await?);
|
progress.downloading_layer(layer.digest(), 0, layer.size() as usize);
|
||||||
|
self.progress.update(progress);
|
||||||
|
layers.push(
|
||||||
|
self.acquire_layer(&image.name, layer, &mut client, progress)
|
||||||
|
.await?,
|
||||||
|
);
|
||||||
|
progress.downloaded_layer(layer.digest());
|
||||||
|
self.progress.update(progress);
|
||||||
}
|
}
|
||||||
Ok(OciLocalImage {
|
Ok(OciLocalImage {
|
||||||
image,
|
image,
|
||||||
@ -239,6 +259,7 @@ impl OciImageDownloader {
|
|||||||
image: &ImageName,
|
image: &ImageName,
|
||||||
layer: &Descriptor,
|
layer: &Descriptor,
|
||||||
client: &mut OciRegistryClient,
|
client: &mut OciRegistryClient,
|
||||||
|
progress: &mut OciProgress,
|
||||||
) -> Result<OciImageLayer> {
|
) -> Result<OciImageLayer> {
|
||||||
debug!(
|
debug!(
|
||||||
"acquire layer digest={} size={}",
|
"acquire layer digest={} size={}",
|
||||||
@ -251,7 +272,15 @@ impl OciImageDownloader {
|
|||||||
let seeded = self.extract_seed_blob(layer, &layer_path).await?;
|
let seeded = self.extract_seed_blob(layer, &layer_path).await?;
|
||||||
if !seeded {
|
if !seeded {
|
||||||
let file = File::create(&layer_path).await?;
|
let file = File::create(&layer_path).await?;
|
||||||
let size = client.write_blob_to_file(&image.name, layer, file).await?;
|
let size = client
|
||||||
|
.write_blob_to_file(
|
||||||
|
&image.name,
|
||||||
|
layer,
|
||||||
|
file,
|
||||||
|
Some(progress),
|
||||||
|
Some(&self.progress),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
if layer.size() as u64 != size {
|
if layer.size() as u64 != size {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"downloaded layer size differs from size in manifest",
|
"downloaded layer size differs from size in manifest",
|
||||||
|
@ -2,4 +2,5 @@ pub mod cache;
|
|||||||
pub mod compiler;
|
pub mod compiler;
|
||||||
pub mod fetch;
|
pub mod fetch;
|
||||||
pub mod name;
|
pub mod name;
|
||||||
|
pub mod progress;
|
||||||
pub mod registry;
|
pub mod registry;
|
||||||
|
98
crates/oci/src/progress.rs
Normal file
98
crates/oci/src/progress.rs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use tokio::sync::broadcast::Sender;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct OciProgress {
|
||||||
|
pub id: String,
|
||||||
|
pub phase: OciProgressPhase,
|
||||||
|
pub layers: BTreeMap<String, OciProgressLayer>,
|
||||||
|
pub value: u64,
|
||||||
|
pub total: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OciProgress {
|
||||||
|
pub fn add_layer(&mut self, id: &str) {
|
||||||
|
self.layers.insert(
|
||||||
|
id.to_string(),
|
||||||
|
OciProgressLayer {
|
||||||
|
id: id.to_string(),
|
||||||
|
phase: OciProgressLayerPhase::Waiting,
|
||||||
|
value: 0,
|
||||||
|
total: 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn downloading_layer(&mut self, id: &str, downloaded: usize, total: usize) {
|
||||||
|
if let Some(entry) = self.layers.get_mut(id) {
|
||||||
|
entry.phase = OciProgressLayerPhase::Downloading;
|
||||||
|
entry.value = downloaded as u64;
|
||||||
|
entry.total = total as u64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn downloaded_layer(&mut self, id: &str) {
|
||||||
|
if let Some(entry) = self.layers.get_mut(id) {
|
||||||
|
entry.phase = OciProgressLayerPhase::Downloaded;
|
||||||
|
entry.value = entry.total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extracting_layer(&mut self, id: &str, extracted: usize, total: usize) {
|
||||||
|
if let Some(entry) = self.layers.get_mut(id) {
|
||||||
|
entry.phase = OciProgressLayerPhase::Extracting;
|
||||||
|
entry.value = extracted as u64;
|
||||||
|
entry.total = total as u64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extracted_layer(&mut self, id: &str) {
|
||||||
|
if let Some(entry) = self.layers.get_mut(id) {
|
||||||
|
entry.phase = OciProgressLayerPhase::Extracted;
|
||||||
|
entry.value = entry.total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum OciProgressPhase {
|
||||||
|
Resolving,
|
||||||
|
Resolved,
|
||||||
|
ConfigAcquire,
|
||||||
|
LayerAcquire,
|
||||||
|
Packing,
|
||||||
|
Complete,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct OciProgressLayer {
|
||||||
|
pub id: String,
|
||||||
|
pub phase: OciProgressLayerPhase,
|
||||||
|
pub value: u64,
|
||||||
|
pub total: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum OciProgressLayerPhase {
|
||||||
|
Waiting,
|
||||||
|
Downloading,
|
||||||
|
Downloaded,
|
||||||
|
Extracting,
|
||||||
|
Extracted,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct OciProgressContext {
|
||||||
|
sender: Sender<OciProgress>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OciProgressContext {
|
||||||
|
pub fn new(sender: Sender<OciProgress>) -> OciProgressContext {
|
||||||
|
OciProgressContext { sender }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(&self, progress: &OciProgress) {
|
||||||
|
let _ = self.sender.send(progress.clone());
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,8 @@ use reqwest::{Client, RequestBuilder, Response, StatusCode};
|
|||||||
use tokio::{fs::File, io::AsyncWriteExt};
|
use tokio::{fs::File, io::AsyncWriteExt};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use crate::progress::{OciProgress, OciProgressContext};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct OciRegistryPlatform {
|
pub struct OciRegistryPlatform {
|
||||||
pub os: Os,
|
pub os: Os,
|
||||||
@ -138,6 +140,8 @@ impl OciRegistryClient {
|
|||||||
name: N,
|
name: N,
|
||||||
descriptor: &Descriptor,
|
descriptor: &Descriptor,
|
||||||
mut dest: File,
|
mut dest: File,
|
||||||
|
mut progress_handle: Option<&mut OciProgress>,
|
||||||
|
progress_context: Option<&OciProgressContext>,
|
||||||
) -> Result<u64> {
|
) -> Result<u64> {
|
||||||
let url = self.url.join(&format!(
|
let url = self.url.join(&format!(
|
||||||
"/v2/{}/blobs/{}",
|
"/v2/{}/blobs/{}",
|
||||||
@ -146,9 +150,24 @@ impl OciRegistryClient {
|
|||||||
))?;
|
))?;
|
||||||
let mut response = self.call(self.agent.get(url.as_str())).await?;
|
let mut response = self.call(self.agent.get(url.as_str())).await?;
|
||||||
let mut size: u64 = 0;
|
let mut size: u64 = 0;
|
||||||
|
let mut last_progress_size: u64 = 0;
|
||||||
while let Some(chunk) = response.chunk().await? {
|
while let Some(chunk) = response.chunk().await? {
|
||||||
dest.write_all(&chunk).await?;
|
dest.write_all(&chunk).await?;
|
||||||
size += chunk.len() as u64;
|
size += chunk.len() as u64;
|
||||||
|
|
||||||
|
if (size - last_progress_size) > (5 * 1024 * 1024) {
|
||||||
|
last_progress_size = size;
|
||||||
|
if let Some(progress_handle) = progress_handle.as_mut() {
|
||||||
|
progress_handle.downloading_layer(
|
||||||
|
descriptor.digest(),
|
||||||
|
size as usize,
|
||||||
|
descriptor.size() as usize,
|
||||||
|
);
|
||||||
|
if let Some(progress_context) = progress_context.as_ref() {
|
||||||
|
progress_context.update(progress_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(size)
|
Ok(size)
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,6 @@ name = "kratart"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
|
|
||||||
[[example]]
|
|
||||||
name = "kratart-squashify"
|
|
||||||
path = "examples/squashify.rs"
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "kratart-channel"
|
name = "kratart-channel"
|
||||||
path = "examples/channel.rs"
|
path = "examples/channel.rs"
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
use std::{env::args, path::PathBuf};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use env_logger::Env;
|
|
||||||
use krataoci::{cache::ImageCache, compiler::ImageCompiler, name::ImageName};
|
|
||||||
use tokio::fs;
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<()> {
|
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
|
||||||
|
|
||||||
let image = ImageName::parse(&args().nth(1).unwrap())?;
|
|
||||||
let seed = args().nth(2).map(PathBuf::from);
|
|
||||||
|
|
||||||
let cache_dir = PathBuf::from("krata-cache");
|
|
||||||
if !cache_dir.exists() {
|
|
||||||
fs::create_dir(&cache_dir).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cache = ImageCache::new(&cache_dir)?;
|
|
||||||
let compiler = ImageCompiler::new(&cache, seed)?;
|
|
||||||
let info = compiler.compile(&image).await?;
|
|
||||||
println!(
|
|
||||||
"generated squashfs of {} to {}",
|
|
||||||
image,
|
|
||||||
info.image_squashfs.to_string_lossy()
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
@ -9,6 +9,7 @@ use ipnetwork::{IpNetwork, Ipv4Network};
|
|||||||
use krata::launchcfg::{
|
use krata::launchcfg::{
|
||||||
LaunchInfo, LaunchNetwork, LaunchNetworkIpv4, LaunchNetworkIpv6, LaunchNetworkResolver,
|
LaunchInfo, LaunchNetwork, LaunchNetworkIpv4, LaunchNetworkIpv6, LaunchNetworkResolver,
|
||||||
};
|
};
|
||||||
|
use krataoci::progress::OciProgressContext;
|
||||||
use tokio::sync::Semaphore;
|
use tokio::sync::Semaphore;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use xenclient::{DomainChannel, DomainConfig, DomainDisk, DomainNetworkInterface};
|
use xenclient::{DomainChannel, DomainConfig, DomainDisk, DomainNetworkInterface};
|
||||||
@ -51,7 +52,14 @@ impl GuestLauncher {
|
|||||||
) -> Result<GuestInfo> {
|
) -> Result<GuestInfo> {
|
||||||
let uuid = request.uuid.unwrap_or_else(Uuid::new_v4);
|
let uuid = request.uuid.unwrap_or_else(Uuid::new_v4);
|
||||||
let xen_name = format!("krata-{uuid}");
|
let xen_name = format!("krata-{uuid}");
|
||||||
let image_info = self.compile(request.image, &context.image_cache).await?;
|
let image_info = self
|
||||||
|
.compile(
|
||||||
|
&uuid.to_string(),
|
||||||
|
request.image,
|
||||||
|
&context.image_cache,
|
||||||
|
&context.oci_progress_context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let mut gateway_mac = MacAddr6::random();
|
let mut gateway_mac = MacAddr6::random();
|
||||||
gateway_mac.set_local(true);
|
gateway_mac.set_local(true);
|
||||||
@ -243,10 +251,16 @@ impl GuestLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn compile(&self, image: &str, image_cache: &ImageCache) -> Result<ImageInfo> {
|
async fn compile(
|
||||||
|
&self,
|
||||||
|
id: &str,
|
||||||
|
image: &str,
|
||||||
|
image_cache: &ImageCache,
|
||||||
|
progress: &OciProgressContext,
|
||||||
|
) -> Result<ImageInfo> {
|
||||||
let image = ImageName::parse(image)?;
|
let image = ImageName::parse(image)?;
|
||||||
let compiler = ImageCompiler::new(image_cache, None)?;
|
let compiler = ImageCompiler::new(image_cache, None, progress.clone())?;
|
||||||
compiler.compile(&image).await
|
compiler.compile(id, &image).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn allocate_ipv4(&self, context: &RuntimeContext) -> Result<Ipv4Addr> {
|
async fn allocate_ipv4(&self, context: &RuntimeContext) -> Result<Ipv4Addr> {
|
||||||
|
@ -17,7 +17,7 @@ use self::{
|
|||||||
autoloop::AutoLoop,
|
autoloop::AutoLoop,
|
||||||
launch::{GuestLaunchRequest, GuestLauncher},
|
launch::{GuestLaunchRequest, GuestLauncher},
|
||||||
};
|
};
|
||||||
use krataoci::cache::ImageCache;
|
use krataoci::{cache::ImageCache, progress::OciProgressContext};
|
||||||
|
|
||||||
pub mod autoloop;
|
pub mod autoloop;
|
||||||
pub mod cfgblk;
|
pub mod cfgblk;
|
||||||
@ -51,6 +51,7 @@ pub struct GuestInfo {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RuntimeContext {
|
pub struct RuntimeContext {
|
||||||
|
pub oci_progress_context: OciProgressContext,
|
||||||
pub image_cache: ImageCache,
|
pub image_cache: ImageCache,
|
||||||
pub autoloop: AutoLoop,
|
pub autoloop: AutoLoop,
|
||||||
pub xen: XenClient,
|
pub xen: XenClient,
|
||||||
@ -59,7 +60,7 @@ pub struct RuntimeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RuntimeContext {
|
impl RuntimeContext {
|
||||||
pub async fn new(store: String) -> Result<Self> {
|
pub async fn new(oci_progress_context: OciProgressContext, store: String) -> Result<Self> {
|
||||||
let mut image_cache_path = PathBuf::from(&store);
|
let mut image_cache_path = PathBuf::from(&store);
|
||||||
image_cache_path.push("cache");
|
image_cache_path.push("cache");
|
||||||
fs::create_dir_all(&image_cache_path)?;
|
fs::create_dir_all(&image_cache_path)?;
|
||||||
@ -72,6 +73,7 @@ impl RuntimeContext {
|
|||||||
let initrd = RuntimeContext::detect_guest_file(&store, "initrd")?;
|
let initrd = RuntimeContext::detect_guest_file(&store, "initrd")?;
|
||||||
|
|
||||||
Ok(RuntimeContext {
|
Ok(RuntimeContext {
|
||||||
|
oci_progress_context,
|
||||||
image_cache,
|
image_cache,
|
||||||
autoloop: AutoLoop::new(LoopControl::open()?),
|
autoloop: AutoLoop::new(LoopControl::open()?),
|
||||||
xen,
|
xen,
|
||||||
@ -252,15 +254,17 @@ impl RuntimeContext {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Runtime {
|
pub struct Runtime {
|
||||||
|
oci_progress_context: OciProgressContext,
|
||||||
store: Arc<String>,
|
store: Arc<String>,
|
||||||
context: RuntimeContext,
|
context: RuntimeContext,
|
||||||
launch_semaphore: Arc<Semaphore>,
|
launch_semaphore: Arc<Semaphore>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Runtime {
|
impl Runtime {
|
||||||
pub async fn new(store: String) -> Result<Self> {
|
pub async fn new(oci_progress_context: OciProgressContext, store: String) -> Result<Self> {
|
||||||
let context = RuntimeContext::new(store.clone()).await?;
|
let context = RuntimeContext::new(oci_progress_context.clone(), store.clone()).await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
oci_progress_context,
|
||||||
store: Arc::new(store),
|
store: Arc::new(store),
|
||||||
context,
|
context,
|
||||||
launch_semaphore: Arc::new(Semaphore::new(1)),
|
launch_semaphore: Arc::new(Semaphore::new(1)),
|
||||||
@ -324,7 +328,7 @@ impl Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn dupe(&self) -> Result<Runtime> {
|
pub async fn dupe(&self) -> Result<Runtime> {
|
||||||
Runtime::new((*self.store).clone()).await
|
Runtime::new(self.oci_progress_context.clone(), (*self.store).clone()).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user