Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: Add spinner/progress for layer fetches #4962

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions rust/src/sysroot_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::cxxrsutil::*;
use crate::ffi::ExportedManifestDiff;
use crate::ffi::{output_message, ContainerImageState};
use crate::ffi::{progress_begin_task, ExportedManifestDiff};
use anyhow::{Context, Result};
use ostree::glib;
use ostree_container::store::{
Expand Down Expand Up @@ -56,10 +56,32 @@ fn layer_counts<'a>(layers: impl Iterator<Item = &'a ManifestLayerState>) -> (u3
)
}

// Output when we begin/end fetching a layer. Ideally, we'd handle
// byte-level progress here too, but that requires some more sophisticated
// binding with the rpmostree-output.h via cxx.rs.
async fn layer_progress_print(mut r: Receiver<ImportProgress>) {
// This is just used to hold a reference to the task.
#[allow(unused_variables, unused_assignments)]
let mut task = None;
while let Some(v) = r.recv().await {
let msg = ostree_ext::cli::layer_progress_format(&v);
output_message(&msg);
tracing::debug!("layer progress: {msg}");
match v {
ImportProgress::OstreeChunkStarted(_) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other tech debt here is that this would all blow up if we started fetching layers concurrently. Ultimately we're going to switch to using podman via containers/bootc#215 so we can ignore this.

assert!(task.is_none());
task = Some(progress_begin_task(&msg));
}
ImportProgress::OstreeChunkCompleted(_) => {
assert!(task.take().is_some());
}
ImportProgress::DerivedLayerStarted(_) => {
assert!(task.is_none());
task = Some(progress_begin_task(&msg));
}
ImportProgress::DerivedLayerCompleted(_) => {
assert!(task.take().is_some());
}
}
}
}

Expand Down Expand Up @@ -99,8 +121,6 @@ async fn pull_container_async(
PrepareResult::AlreadyPresent(r) => return Ok(r.into()),
PrepareResult::Ready(r) => r,
};
let progress_printer =
tokio::task::spawn(async move { layer_progress_print(layer_progress).await });
let digest = prep.manifest_digest.clone();
output_message(&format!("Importing: {} (digest: {})", &imgref, &digest));
let ostree_layers = prep
Expand All @@ -125,8 +145,14 @@ async fn pull_container_async(
let size = glib::format_size(size_to_fetch);
output_message(&format!("custom layers needed: {n_to_fetch} ({size})"));
}
let import = imp.import(prep).await;
let _ = progress_printer.await;
let local = tokio::task::LocalSet::new();
let import = local
.run_until(async move {
let _progress_printer =
tokio::task::spawn_local(async move { layer_progress_print(layer_progress).await });
imp.import(prep).await
})
.await;
// TODO log the discarded bits from import
Ok(import?.into())
}
Expand Down
Loading