mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 08:44:09 +02:00
db and image pull
This commit is contained in:
parent
2ca635603b
commit
2a4a2b9d17
9 changed files with 180 additions and 38 deletions
55
src/image.rs
Normal file
55
src/image.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use bollard::image::CreateImageOptions;
|
||||
use bollard::models::CreateImageInfo;
|
||||
use bollard::Docker;
|
||||
use color_eyre::Result;
|
||||
use futures_util::StreamExt;
|
||||
use std::collections::HashMap;
|
||||
use std::io::stdout;
|
||||
use std::io::Write;
|
||||
use termion::cursor;
|
||||
|
||||
pub async fn pull_image(docker: &mut Docker, image: &str) -> Result<()> {
|
||||
if let Err(_) = docker.inspect_image(image).await {
|
||||
let mut info_stream = docker.create_image(
|
||||
Some(CreateImageOptions {
|
||||
from_image: image,
|
||||
..Default::default()
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
let mut bars: HashMap<String, u16> = HashMap::new();
|
||||
|
||||
let stdout = stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
while let Some(info) = info_stream.next().await {
|
||||
let info: CreateImageInfo = info?;
|
||||
// dbg!(&info);
|
||||
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
|
||||
)?;
|
||||
}
|
||||
None => {
|
||||
writeln!(stdout, "{} - {:12} {}", id, status, progress)?;
|
||||
bars.insert(id, bars.len() as u16);
|
||||
}
|
||||
}
|
||||
stdout.flush()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue