use monocore::{
oci::distribution::{DockerRegistry, OciRegistryPull},
utils::{OCI_LAYER_SUBDIR, OCI_REPO_SUBDIR},
};
use std::path::PathBuf;
use tempfile::tempdir;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
let temp_dir = tempdir()?;
println!("\nUsing temporary directory: {}", temp_dir.path().display());
let registry = DockerRegistry::with_oci_dir(temp_dir.path().to_path_buf());
println!("\nPulling Alpine Linux image...");
registry
.pull_image("library/alpine", Some("latest"))
.await?;
print_oci_files(temp_dir.path().to_path_buf())?;
Ok(())
}
fn print_oci_files(oci_dir: PathBuf) -> anyhow::Result<()> {
println!("\nOCI Directory Structure:");
println!("------------------------");
let repo_dir = oci_dir.join(OCI_REPO_SUBDIR).join("library_alpine__latest");
println!("\nRepository files at {}:", repo_dir.display());
for entry in std::fs::read_dir(&repo_dir)? {
let entry = entry?;
println!("- {}", entry.file_name().to_string_lossy());
}
let layers_dir = oci_dir.join(OCI_LAYER_SUBDIR);
println!("\nLayers at {}:", layers_dir.display());
for entry in std::fs::read_dir(layers_dir)? {
let entry = entry?;
println!("- {}", entry.file_name().to_string_lossy());
}
println!("\nNote: These files are in a temporary directory and will be deleted when the program exits.");
println!(
" For persistent storage, use DockerRegistry::new() which stores files in ~/.monocore"
);
Ok(())
}