Skip to content

Commit 7e81f9c

Browse files
ericcurtincgwalters
authored andcommitted
Move docker .tar.gz handling to unencapsulate.rs
To handle this is a different location Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 086fa3b commit 7e81f9c

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

crates/ostree-ext/src/container/unencapsulate.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub(crate) async fn fetch_layer<'a>(
203203
tracing::debug!("fetching {}", layer.digest());
204204
let layer_index = manifest.layers().iter().position(|x| x == layer).unwrap();
205205
let (blob, driver, size);
206-
let media_type: oci_image::MediaType;
206+
let mut media_type: oci_image::MediaType;
207207
match transport_src {
208208
// Both containers-storage and docker-daemon store layers uncompressed in their
209209
// local storage, even though the manifest may indicate they are compressed.
@@ -218,6 +218,19 @@ pub(crate) async fn fetch_layer<'a>(
218218
})?;
219219
size = layer_blob.size;
220220
media_type = layer_blob.media_type.clone();
221+
222+
// docker-daemon stores layers uncompressed even when the media type
223+
// indicates gzip compression. Translate to the uncompressed variant.
224+
if transport_src == Transport::DockerDaemon {
225+
if let oci_image::MediaType::Other(t) = &media_type {
226+
if t.as_str() == "application/vnd.docker.image.rootfs.diff.tar.gzip" {
227+
media_type = oci_image::MediaType::Other(
228+
"application/vnd.docker.image.rootfs.diff.tar".to_string(),
229+
);
230+
}
231+
}
232+
}
233+
221234
(blob, driver) = proxy.get_blob(img, &layer_blob.digest, size).await?;
222235
}
223236
_ => {

crates/ostree-ext/src/generic_decompress.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ use crate::oci_spec::image as oci_image;
2222
/// TODO: change the skopeo code to shield us from this correctly
2323
const DOCKER_TYPE_LAYER_TAR: &str = "application/vnd.docker.image.rootfs.diff.tar";
2424

25-
/// The Docker MIME type for gzipped layers when stored in docker-daemon.
26-
/// Even though this indicates gzip compression, docker-daemon actually stores
27-
/// the layers uncompressed, so we need to treat this as uncompressed.
28-
const DOCKER_TYPE_LAYER_TAR_GZIP: &str = "application/vnd.docker.image.rootfs.diff.tar.gzip";
29-
3025
/// Extends the `Read` trait with another method to get mutable access to the inner reader
3126
trait ReadWithGetInnerMut: Read + Send + 'static {
3227
fn get_inner_mut(&mut self) -> &mut dyn Read;
@@ -130,9 +125,6 @@ impl Decompressor {
130125
oci_image::MediaType::Other(t) if t.as_str() == DOCKER_TYPE_LAYER_TAR => {
131126
Box::new(TransparentDecompressor(src))
132127
}
133-
oci_image::MediaType::Other(t) if t.as_str() == DOCKER_TYPE_LAYER_TAR_GZIP => {
134-
Box::new(TransparentDecompressor(src))
135-
}
136128
o => anyhow::bail!("Unhandled layer type: {}", o),
137129
};
138130
Ok(Self {
@@ -236,17 +228,4 @@ mod tests {
236228
assert_eq!(e.to_string(), "Unknown frame descriptor".to_string());
237229
drop(d)
238230
}
239-
240-
#[test]
241-
fn test_docker_tar_gzip_media_type_uses_transparent_decompressor() {
242-
// Test that the docker-daemon gzip media type is treated as uncompressed
243-
let data = b"test data";
244-
let media_type = oci_image::MediaType::Other(DOCKER_TYPE_LAYER_TAR_GZIP.to_string());
245-
let mut d = Decompressor::new(&media_type, &data[..]).unwrap();
246-
let mut buf = [0u8; 32];
247-
let n = d.read(&mut buf).unwrap();
248-
assert_eq!(n, data.len());
249-
assert_eq!(&buf[..n], data);
250-
drop(d)
251-
}
252231
}

0 commit comments

Comments
 (0)