Skip to content

Commit

Permalink
add uncompressed media type
Browse files Browse the repository at this point in the history
Add a new mime type [1] to represent uncompressed DockerV2 layers, and
propagate it to the destination's manifest.

[1] application/vnd.docker.image.rootfs.diff.tar

Fixes: github.com/containers/podman/issues/2013
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Jan 21, 2019
1 parent e42fdf3 commit 51b1a63
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/containers/image/image"
"github.com/containers/image/manifest"
"github.com/containers/image/pkg/blobinfocache"
"github.com/containers/image/pkg/compression"
"github.com/containers/image/signature"
Expand Down Expand Up @@ -813,6 +814,17 @@ func (c *copier) copyBlobFromStream(ctx context.Context, srcStream io.Reader, sr
return types.BlobInfo{}, errors.Wrap(err, "Error writing blob")
}

switch compressionOperation {
case types.Compress:
uploadedInfo.MediaType = manifest.DockerV2Schema2LayerMediaType
case types.Decompress:
uploadedInfo.MediaType = manifest.DockerV2SchemeLayerMediaTypeUncompressed
case types.PreserveOriginal:
// preserve whatever the destination sets by default
default:
panic("unexpected compression operation")
}

// This is fairly horrible: the writer from getOriginalLayerCopyWriter wants to consumer
// all of the input (to compute DiffIDs), even if dest.PutBlob does not need it.
// So, read everything from originalLayerReader, which will cause the rest to be
Expand Down
5 changes: 3 additions & 2 deletions directory/directory_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"

"github.com/containers/image/manifest"
"github.com/containers/image/types"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
Expand Down Expand Up @@ -172,7 +173,7 @@ func (d *dirImageDestination) PutBlob(ctx context.Context, stream io.Reader, inp
return types.BlobInfo{}, err
}
succeeded = true
return types.BlobInfo{Digest: computedDigest, Size: size}, nil
return types.BlobInfo{Digest: computedDigest, Size: size, MediaType: manifest.DockerV2SchemeLayerMediaTypeUncompressed}, nil
}

// TryReusingBlob checks whether the transport already contains, or can efficiently reuse, a blob, and if so, applies it to the current destination
Expand All @@ -194,7 +195,7 @@ func (d *dirImageDestination) TryReusingBlob(ctx context.Context, info types.Blo
if err != nil {
return false, types.BlobInfo{}, err
}
return true, types.BlobInfo{Digest: info.Digest, Size: finfo.Size()}, nil
return true, types.BlobInfo{Digest: info.Digest, Size: finfo.Size(), MediaType: manifest.DockerV2SchemeLayerMediaTypeUncompressed}, nil

}

Expand Down
5 changes: 4 additions & 1 deletion manifest/docker_schema2.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ func (m *Schema2) UpdateLayerInfos(layerInfos []types.BlobInfo) error {
original := m.LayersDescriptors
m.LayersDescriptors = make([]Schema2Descriptor, len(layerInfos))
for i, info := range layerInfos {
m.LayersDescriptors[i].MediaType = original[i].MediaType
m.LayersDescriptors[i].MediaType = info.MediaType
if m.LayersDescriptors[i].MediaType == "" {
m.LayersDescriptors[i].MediaType = original[i].MediaType
}
m.LayersDescriptors[i].Digest = info.Digest
m.LayersDescriptors[i].Size = info.Size
m.LayersDescriptors[i].URLs = info.URLs
Expand Down
2 changes: 2 additions & 0 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
DockerV2Schema2ConfigMediaType = "application/vnd.docker.container.image.v1+json"
// DockerV2Schema2LayerMediaType is the MIME type used for schema 2 layers.
DockerV2Schema2LayerMediaType = "application/vnd.docker.image.rootfs.diff.tar.gzip"
// DockerV2SchemeLayerMediaTypeUncompressed is the mediaType used for layers which are not compressed.
DockerV2SchemeLayerMediaTypeUncompressed = "application/vnd.docker.image.rootfs.diff.tar"
// DockerV2ListMediaType MIME type represents Docker manifest schema 2 list
DockerV2ListMediaType = "application/vnd.docker.distribution.manifest.list.v2+json"
// DockerV2Schema2ForeignLayerMediaType is the MIME type used for schema 2 foreign layers.
Expand Down

0 comments on commit 51b1a63

Please sign in to comment.