Skip to content

Commit 3d686ab

Browse files
authored
Merge pull request bootc-dev#615 from travier/zstd-chunked
Add zstd:chunked support
2 parents e9b16f8 + 651ae79 commit 3d686ab

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version = "1.74.0"
1212
[dependencies]
1313
anyhow = "1.0"
1414
containers-image-proxy = "0.5.5"
15-
async-compression = { version = "0.4", features = ["gzip", "tokio"] }
15+
async-compression = { version = "0.4", features = ["gzip", "tokio", "zstd"] }
1616
camino = "1.0.4"
1717
chrono = "0.4.19"
1818
olpc-cjson = "0.1.1"

lib/src/container/unencapsulate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ fn new_async_decompressor<'a>(
198198
oci_image::MediaType::ImageLayerGzip => Ok(Box::new(tokio::io::BufReader::new(
199199
async_compression::tokio::bufread::GzipDecoder::new(src),
200200
))),
201+
oci_image::MediaType::ImageLayerZstd => Ok(Box::new(tokio::io::BufReader::new(
202+
async_compression::tokio::bufread::ZstdDecoder::new(src),
203+
))),
201204
oci_image::MediaType::ImageLayer => Ok(Box::new(src)),
202205
oci_image::MediaType::Other(t) if t.as_str() == DOCKER_TYPE_LAYER_TAR => Ok(Box::new(src)),
203206
o => Err(anyhow::anyhow!("Unhandled layer type: {}", o)),

lib/tests/it/main.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,47 @@ async fn test_container_write_derive() -> Result<()> {
12611261
Ok(())
12621262
}
12631263

1264+
/// Test for zstd
1265+
/// We need to handle the case of modified hardlinks into /sysroot
1266+
#[tokio::test]
1267+
async fn test_container_zstd() -> Result<()> {
1268+
let fixture = Fixture::new_v1()?;
1269+
let baseimg = &fixture.export_container().await?.0;
1270+
let basepath = &match baseimg.transport {
1271+
Transport::OciDir => fixture.path.join(baseimg.name.as_str()),
1272+
_ => unreachable!(),
1273+
};
1274+
let baseimg_ref = format!("oci:{basepath}");
1275+
let zstd_image_path = &fixture.path.join("zstd.oci");
1276+
let st = tokio::process::Command::new("skopeo")
1277+
.args([
1278+
"copy",
1279+
"--dest-compress-format=zstd",
1280+
baseimg_ref.as_str(),
1281+
&format!("oci:{zstd_image_path}"),
1282+
])
1283+
.status()
1284+
.await?;
1285+
assert!(st.success());
1286+
1287+
let zstdref = &OstreeImageReference {
1288+
sigverify: SignatureSource::ContainerPolicyAllowInsecure,
1289+
imgref: ImageReference {
1290+
transport: Transport::OciDir,
1291+
name: zstd_image_path.to_string(),
1292+
},
1293+
};
1294+
let mut imp =
1295+
store::ImageImporter::new(fixture.destrepo(), zstdref, Default::default()).await?;
1296+
let prep = match imp.prepare().await.context("Init prep derived")? {
1297+
store::PrepareResult::AlreadyPresent(_) => panic!("should not be already imported"),
1298+
store::PrepareResult::Ready(r) => r,
1299+
};
1300+
let _ = imp.import(prep).await.unwrap();
1301+
1302+
Ok(())
1303+
}
1304+
12641305
/// Test for https://github.com/ostreedev/ostree-rs-ext/issues/405
12651306
/// We need to handle the case of modified hardlinks into /sysroot
12661307
#[tokio::test]

0 commit comments

Comments
 (0)