chore: rework oci crate to be more composable

This commit is contained in:
Alex Zenla
2024-04-15 05:06:02 +00:00
parent 24c71e9725
commit 5511fb2fa1
14 changed files with 564 additions and 492 deletions

View File

@ -3,11 +3,10 @@ use std::{env::args, path::PathBuf};
use anyhow::Result;
use env_logger::Env;
use krataoci::{
cache::ImageCache,
compiler::OciImageCompiler,
name::ImageName,
packer::OciPackerFormat,
packer::{service::OciPackerService, OciPackedFormat},
progress::{OciProgress, OciProgressContext},
registry::OciPlatform,
};
use tokio::{fs, sync::broadcast};
@ -23,8 +22,6 @@ async fn main() -> Result<()> {
fs::create_dir(&cache_dir).await?;
}
let cache = ImageCache::new(&cache_dir)?;
let (sender, mut receiver) = broadcast::channel::<OciProgress>(1000);
tokio::task::spawn(async move {
loop {
@ -41,14 +38,14 @@ async fn main() -> Result<()> {
}
});
let context = OciProgressContext::new(sender);
let compiler = OciImageCompiler::new(&cache, seed, context)?;
let info = compiler
.compile(&image.to_string(), &image, OciPackerFormat::Squashfs)
let service = OciPackerService::new(seed, &cache_dir, OciPlatform::current(), context)?;
let packed = service
.pack("cli", image.clone(), OciPackedFormat::Squashfs)
.await?;
println!(
"generated squashfs of {} to {}",
image,
info.image.to_string_lossy()
packed.path.to_string_lossy()
);
Ok(())
}