mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 08:44:09 +02:00
update bollard
This commit is contained in:
parent
f569ca17e2
commit
df38f16f10
23 changed files with 410 additions and 502 deletions
54
src/image.rs
54
src/image.rs
|
|
@ -1,12 +1,10 @@
|
|||
use bollard::image::CreateImageOptions;
|
||||
use bollard::models::CreateImageInfo;
|
||||
use bollard::query_parameters::CreateImageOptions;
|
||||
use bollard::Docker;
|
||||
use futures_util::StreamExt;
|
||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||
use miette::{IntoDiagnostic, Result, WrapErr};
|
||||
use std::collections::HashMap;
|
||||
use std::io::stdout;
|
||||
use std::io::Write;
|
||||
use termion::cursor;
|
||||
|
||||
pub async fn image_exists(docker: &Docker, image: &str) -> bool {
|
||||
docker.inspect_image(image).await.is_ok()
|
||||
|
|
@ -32,9 +30,9 @@ pub async fn force_pull_image(docker: &Docker, image: &str) -> Result<()> {
|
|||
let mut info_stream = docker.create_image(
|
||||
Some(CreateImageOptions {
|
||||
from_image: if image.contains(':') {
|
||||
image.to_string()
|
||||
Some(image.to_string())
|
||||
} else {
|
||||
format!("{}:latest", image)
|
||||
Some(format!("{}:latest", image))
|
||||
},
|
||||
..Default::default()
|
||||
}),
|
||||
|
|
@ -42,35 +40,33 @@ pub async fn force_pull_image(docker: &Docker, image: &str) -> Result<()> {
|
|||
None,
|
||||
);
|
||||
|
||||
let mut bars: HashMap<String, u16> = HashMap::new();
|
||||
let bar_style = ProgressStyle::with_template(
|
||||
"{spinner:.green} {msg} [{elapsed_precise}] [{bar:.cyan/blue}] {bytes:>12}/{total_bytes}",
|
||||
)
|
||||
.unwrap();
|
||||
let mut bars: HashMap<String, ProgressBar> = HashMap::new();
|
||||
let mp = MultiProgress::new();
|
||||
|
||||
let mut stdout = stdout();
|
||||
while let Some(info) = info_stream.next().await {
|
||||
let info: CreateImageInfo = info
|
||||
.into_diagnostic()
|
||||
.wrap_err_with(|| format!("Error while pulling image {}", image))?;
|
||||
if let (Some(id), Some(status), Some(progress)) = (info.id, info.status, info.progress) {
|
||||
match bars.get(&id) {
|
||||
Some(pos) => {
|
||||
let offset = bars.len() as u16 - pos;
|
||||
write!(
|
||||
stdout,
|
||||
"{}{}{} - {:12} {}{}",
|
||||
cursor::Save,
|
||||
cursor::Up(offset),
|
||||
id,
|
||||
status,
|
||||
progress,
|
||||
cursor::Restore
|
||||
)
|
||||
.into_diagnostic()?;
|
||||
}
|
||||
None => {
|
||||
writeln!(stdout, "{} - {:12} {}", id, status, progress).into_diagnostic()?;
|
||||
bars.insert(id, bars.len() as u16);
|
||||
}
|
||||
if let (Some(id), Some(status), Some(progress)) =
|
||||
(info.id, info.status, info.progress_detail)
|
||||
{
|
||||
let bar = bars.entry(id.clone()).or_insert_with(|| {
|
||||
let bar = ProgressBar::new(progress.total.unwrap_or_default() as u64)
|
||||
.with_style(bar_style.clone())
|
||||
.with_message(format!("{id:20} - {status:10}"));
|
||||
mp.add(bar)
|
||||
});
|
||||
bar.set_message(format!("{id:10} - {status:20}"));
|
||||
if let Some(total) = progress.total {
|
||||
bar.set_length(total as u64);
|
||||
}
|
||||
if let Some(current) = progress.current {
|
||||
bar.set_position(current as u64);
|
||||
}
|
||||
stdout.flush().into_diagnostic()?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue