Skip to content

Commit

Permalink
Improve outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ianoc committed Jun 2, 2022
1 parent 04c2760 commit 1f9432a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
27 changes: 20 additions & 7 deletions app/pusher_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,24 @@ async fn main() -> Result<(), anyhow::Error> {
actions_taken.merge(&join_result.await??);
}


println!("\n\nAll referred to layers have been ensured present, actions taken:\n{}\nManifest uploads commencing", actions_taken);

let mut tokio_data = Vec::default();


// First lets upload the manifest keyed by the digest.
let manifest = Arc::new(manifest);
for destination_registry in destination_registries.iter() {
for t in tags.iter() {

let message_style = ProgressStyle::with_template("{msg}").unwrap();
let message_pb = ProgressBar::new(1);
message_pb.set_style(message_style.clone());
let pb = mp.add(message_pb);

pb.set_message(format!("Uploading tag {} to {}", t, destination_registry.registry_name()));

pb.set_message(format!(
"Uploading tag {} to {}",
t,
destination_registry.registry_name()
));

let t = t.clone();
let destination_registry = destination_registry.clone();
Expand All @@ -283,17 +283,30 @@ async fn main() -> Result<(), anyhow::Error> {
} else {
pb.set_message(format!("{}", console::style("x").red()));
}
r
r.map(|s| (s, t))
}));
}
}

let mut uploaded_locations = Vec::default();
for join_result in tokio_data {
join_result.await??;
let uploaded_location = join_result.await??;
uploaded_locations.push(uploaded_location);
}

mp.clear()?;
mp.set_draw_target(ProgressDrawTarget::hidden());
drop(mp);

for (uploaded_location, tag) in uploaded_locations {
if let Some(loc) = uploaded_location {
eprintln!("Uploaded {} to: {}", tag, loc);
} else {
eprintln!(
"Skipped an upload, manifest already present for tag {}",
tag
);
}
}
Ok(())
}
10 changes: 3 additions & 7 deletions src/registry/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl super::RegistryCore for HttpRegistry {
container_name: &str,
manifest: &Manifest,
tag: &str,
) -> Result<(), Error> {
) -> Result<Option<String>, Error> {
let manifest: Manifest = {
let mut manifest = manifest.clone();
manifest.tag = Some(tag.to_string());
Expand All @@ -55,7 +55,7 @@ impl super::RegistryCore for HttpRegistry {

if let Ok(content_and_type) = self.fetch_manifest_as_string(tag).await {
if manifest_bytes == content_and_type.content.as_bytes() {
return Ok(());
return Ok(None);
}
}

Expand All @@ -74,14 +74,10 @@ impl super::RegistryCore for HttpRegistry {

if let Some(location_header) = r.headers().get(http::header::LOCATION) {
let location_str = location_header.to_str()?;
eprintln!(
"Uploaded manifest to repository {} @ {:#?}, for tag: {} @ {}",
self.name, post_target_uri, tag, location_str
);
Ok(Some(location_str.to_string()))
} else {
bail!("We got a positive response code: {:#?}, however we are missing the location header as is required in the spec", r.status())
}
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait RegistryCore {
container_name: &str,
manifest: &crate::container_specs::manifest::Manifest,
tag: &str,
) -> Result<(), Error>;
) -> Result<Option<String>, Error>;
}

#[derive(Debug)]
Expand Down

0 comments on commit 1f9432a

Please sign in to comment.