Closed CodeMan99 closed 5 months ago
So what I am looking for is something akin to this.
use std::fs::File;
use std::io::Write;
use std::path::Path;
use oci_spec::image::MediaType;
use ocipkg::{Digest, ImageName, distribution};
/// Pull OCI Artifact "ghcr.io/devcontainers/index:latest" and download the JSON layer to the given filename.
pub fn pull_devcontainer_index<P: AsRef<Path>>(filename: P) -> Result<(), Box<dyn std::error::Error>> {
let image_name = ImageName::parse("ghcr.io/devcontainers/index:latest")?;
let mut client = distribution::Client::try_from(&image_name)?;
let layer = distribution::get_image_layer(&mut client, &image_name, |media_type| {
match media_type {
MediaType::Other(other_type) => other_type == "application/vnd.devcontainers.index.layer.v1+json",
_ => false,
}
})?;
let digest = Digest::new(layer.digest())?;
let blob = client.get_blob(&digest)?;
let mut file = File::create(filename)?;
file.write_all(&blob[..])?;
Ok(())
}
Note that Client::try_from
& get_image_layer
exist in my fork of this project. I am willing to submit a PR after #93 is merged.
I've closed #93 in favor of #94. Seems like a less opinionated approach to me.
Will close this as soon as the next release (to crates.io) occurs!
Release v0.2.9 includes the contributed work.
Thank you!
:wave: hello! Cool project.
I am trying to write a CLI frontend for containers.dev. Mostly for fun and learning of Rust patterns. Also, because the existing cli is pretty hard to use in some cases.
Anyway, the index is what I'm trying download and parse. Using oras cli works fine:
This project seems to not like that?
Or am I mis-using the tool somehow?