Skip to content

Commit

Permalink
Work around docker v25 tarballs (#1872)
Browse files Browse the repository at this point in the history
Previously, we'd only seen compressed layers have LayerSources. As of
v25, docker puts all layers in here, uncompressed, which exposed a bug
in how Descriptor interacts with partial's uncompressed layer handling.

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr authored Jan 29, 2024
1 parent a0658aa commit 8dadbe7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
33 changes: 22 additions & 11 deletions pkg/v1/tarball/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,29 @@ func (i *uncompressedImage) LayerByDiffID(h v1.Hash) (partial.UncompressedLayer,
// v1.Layer doesn't force consumers to care about whether the layer is compressed
// we should be fine returning the DockerLayer media type
mt := types.DockerLayer
if bd, ok := i.imgDescriptor.LayerSources[h]; ok {
// Overwrite the mediaType for foreign layers.
return &foreignUncompressedLayer{
uncompressedLayerFromTarball: uncompressedLayerFromTarball{
diffID: diffID,
mediaType: bd.MediaType,
opener: i.opener,
filePath: i.imgDescriptor.Layers[idx],
},
desc: bd,
}, nil
bd, ok := i.imgDescriptor.LayerSources[h]
if ok {
// This is janky, but we don't want to implement Descriptor for
// uncompressed layers because it breaks a bunch of assumptions in partial.
// See https://github.com/google/go-containerregistry/issues/1870
docker25workaround := bd.MediaType == types.DockerUncompressedLayer || bd.MediaType == types.OCIUncompressedLayer

if !docker25workaround {
// Overwrite the mediaType for foreign layers.
return &foreignUncompressedLayer{
uncompressedLayerFromTarball: uncompressedLayerFromTarball{
diffID: diffID,
mediaType: bd.MediaType,
opener: i.opener,
filePath: i.imgDescriptor.Layers[idx],
},
desc: bd,
}, nil
}

// Intentional fall through.
}

return &uncompressedLayerFromTarball{
diffID: diffID,
mediaType: mt,
Expand Down
10 changes: 10 additions & 0 deletions pkg/v1/tarball/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ func TestBundleSingle(t *testing.T) {
}
}

func TestDocker25(t *testing.T) {
img, err := ImageFromPath("testdata/hello-world-v25.tar", nil)
if err != nil {
t.Fatal(err)
}
if err := validate.Image(img); err != nil {
t.Fatal(err)
}
}

func TestBundleMultiple(t *testing.T) {
for _, imgName := range []string{
"test_image_1",
Expand Down
Binary file added pkg/v1/tarball/testdata/hello-world-v25.tar
Binary file not shown.

0 comments on commit 8dadbe7

Please sign in to comment.