Skip to content

Commit

Permalink
Merge pull request #615 from travier/zstd-chunked
Browse files Browse the repository at this point in the history
Add zstd:chunked support
  • Loading branch information
cgwalters committed Mar 27, 2024
2 parents e9b16f8 + 651ae79 commit 3d686ab
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rust-version = "1.74.0"
[dependencies]
anyhow = "1.0"
containers-image-proxy = "0.5.5"
async-compression = { version = "0.4", features = ["gzip", "tokio"] }
async-compression = { version = "0.4", features = ["gzip", "tokio", "zstd"] }
camino = "1.0.4"
chrono = "0.4.19"
olpc-cjson = "0.1.1"
Expand Down
3 changes: 3 additions & 0 deletions lib/src/container/unencapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ fn new_async_decompressor<'a>(
oci_image::MediaType::ImageLayerGzip => Ok(Box::new(tokio::io::BufReader::new(
async_compression::tokio::bufread::GzipDecoder::new(src),
))),
oci_image::MediaType::ImageLayerZstd => Ok(Box::new(tokio::io::BufReader::new(
async_compression::tokio::bufread::ZstdDecoder::new(src),
))),
oci_image::MediaType::ImageLayer => Ok(Box::new(src)),
oci_image::MediaType::Other(t) if t.as_str() == DOCKER_TYPE_LAYER_TAR => Ok(Box::new(src)),
o => Err(anyhow::anyhow!("Unhandled layer type: {}", o)),
Expand Down
41 changes: 41 additions & 0 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,47 @@ async fn test_container_write_derive() -> Result<()> {
Ok(())
}

/// Test for zstd
/// We need to handle the case of modified hardlinks into /sysroot
#[tokio::test]
async fn test_container_zstd() -> Result<()> {
let fixture = Fixture::new_v1()?;
let baseimg = &fixture.export_container().await?.0;
let basepath = &match baseimg.transport {
Transport::OciDir => fixture.path.join(baseimg.name.as_str()),
_ => unreachable!(),
};
let baseimg_ref = format!("oci:{basepath}");
let zstd_image_path = &fixture.path.join("zstd.oci");
let st = tokio::process::Command::new("skopeo")
.args([
"copy",
"--dest-compress-format=zstd",
baseimg_ref.as_str(),
&format!("oci:{zstd_image_path}"),
])
.status()
.await?;
assert!(st.success());

let zstdref = &OstreeImageReference {
sigverify: SignatureSource::ContainerPolicyAllowInsecure,
imgref: ImageReference {
transport: Transport::OciDir,
name: zstd_image_path.to_string(),
},
};
let mut imp =
store::ImageImporter::new(fixture.destrepo(), zstdref, Default::default()).await?;
let prep = match imp.prepare().await.context("Init prep derived")? {
store::PrepareResult::AlreadyPresent(_) => panic!("should not be already imported"),
store::PrepareResult::Ready(r) => r,
};
let _ = imp.import(prep).await.unwrap();

Ok(())
}

/// Test for https://github.com/ostreedev/ostree-rs-ext/issues/405
/// We need to handle the case of modified hardlinks into /sysroot
#[tokio::test]
Expand Down

0 comments on commit 3d686ab

Please sign in to comment.