Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions ocipkg/src/distribution/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::distribution::*;
use anyhow::Result;
use crate::{distribution::*, media_types};
use anyhow::{bail, Result};
use oci_spec::{distribution::*, image::*};
use url::Url;

Expand Down Expand Up @@ -106,6 +106,25 @@ impl Client {
MediaType::ImageManifest,
),
))?;

// simple solution to fetch platform manifest from image index
if media_types::is_imageindex(res.content_type()) {
log::debug!("media_type is imageindex type: {}", &res.content_type());
let mi = ImageIndex::from_reader(res.into_reader())?;
let m = mi.manifests().iter().find(|m| {
m.platform().as_ref().map_or(false, |platform| {
Arch::default().eq(platform.architecture())
})
});
if let Some(m) = m {
return self.get_manifest(&Reference::new(m.digest())?);
}
bail!(
"Found ImageIndex but not supported platform: {}",
Arch::default()
);
}

let manifest = ImageManifest::from_reader(res.into_reader())?;
Ok(manifest)
}
Expand Down
13 changes: 13 additions & 0 deletions ocipkg/src/image/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ impl<Base: Image> Artifact<Base> {
files.push(path.to_path_buf());
}
}
media_type if media_type.to_string().ends_with("gzip") => {
let buf = flate2::read::GzDecoder::new(blob.as_slice());
let mut ar = tar::Archive::new(buf);
for entry in ar.entries()? {
let entry = entry?;
let path = entry.path()?;
files.push(path.to_path_buf());
}
}
_ => bail!("Unsupported layer type: {}", desc.media_type()),
}
}
Expand Down Expand Up @@ -231,6 +240,10 @@ impl<Base: Image> Artifact<Base> {
let buf = flate2::read::GzDecoder::new(blob.as_slice());
tar::Archive::new(buf).unpack(&dest)?;
}
(ArtifactVersion::V0, media_type) if media_type.to_string().ends_with("gzip") => {
let buf = flate2::read::GzDecoder::new(blob.as_slice());
tar::Archive::new(buf).unpack(&dest)?;
}
(ArtifactVersion::V1, media_type)
if media_type == &media_types::layer_tar_gzip() =>
{
Expand Down
11 changes: 11 additions & 0 deletions ocipkg/src/media_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ pub fn config_json() -> MediaType {
pub fn layer_tar_gzip() -> MediaType {
MediaType::Other("application/vnd.ocipkg.v1.layer.tar+gzip".to_string())
}

/// Test media_type is imageindex
///
/// DockerV2S2 can't directly match by MediaType
pub fn is_imageindex(media_type: &str) -> bool {
matches!(
media_type,
"application/vnd.docker.distribution.manifest.list.v2+json"
| "application/vnd.oci.image.index.v1+json"
)
}