Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Add zstd support #615

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
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
Loading