Skip to content

Commit

Permalink
Add imagedestination.impl.Properties.DesiredLayerCompression
Browse files Browse the repository at this point in the history
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Jul 1, 2022
1 parent 7238caf commit 9a2d2f5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 41 deletions.
11 changes: 3 additions & 8 deletions directory/directory_dest.go
Expand Up @@ -31,8 +31,7 @@ type dirImageDestination struct {
stubs.NoPutBlobPartialInitialize
stubs.AlwaysSupportsSignatures

ref dirReference
desiredLayerCompression types.LayerCompression
ref dirReference
}

// newImageDestination returns an ImageDestination for writing to a directory.
Expand Down Expand Up @@ -102,14 +101,14 @@ func newImageDestination(sys *types.SystemContext, ref dirReference) (types.Imag
d := &dirImageDestination{
PropertyMethodsInitialize: impl.PropertyMethods(impl.Properties{
SupportedManifestMIMETypes: nil,
DesiredLayerCompression: desiredLayerCompression,
MustMatchRuntimeOS: false,
IgnoresEmbeddedDockerReference: false, // N/A, DockerReference() returns nil.
HasThreadSafePutBlob: false,
}),
NoPutBlobPartialInitialize: stubs.NoPutBlobPartial(ref),

ref: ref,
desiredLayerCompression: desiredLayerCompression,
ref: ref,
}
d.Compat = impl.AddCompat(d)
return d, nil
Expand All @@ -126,10 +125,6 @@ func (d *dirImageDestination) Close() error {
return nil
}

func (d *dirImageDestination) DesiredLayerCompression() types.LayerCompression {
return d.desiredLayerCompression
}

// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
// uploaded to the image destination, true otherwise.
func (d *dirImageDestination) AcceptsForeignLayerURLs() bool {
Expand Down
5 changes: 0 additions & 5 deletions docker/archive/dest.go
Expand Up @@ -47,11 +47,6 @@ func newImageDestination(sys *types.SystemContext, ref archiveReference) (types.
}, nil
}

// DesiredLayerCompression indicates if layers must be compressed, decompressed or preserved
func (d *archiveImageDestination) DesiredLayerCompression() types.LayerCompression {
return types.Decompress
}

// Reference returns the reference used to set up this destination. Note that this should directly correspond to user's intent,
// e.g. it should use the public hostname instead of the result of resolving CNAMEs or following redirects.
func (d *archiveImageDestination) Reference() types.ImageReference {
Expand Down
5 changes: 1 addition & 4 deletions docker/docker_image_dest.go
Expand Up @@ -62,6 +62,7 @@ func newImageDestination(sys *types.SystemContext, ref dockerReference) (types.I
dest := &dockerImageDestination{
PropertyMethodsInitialize: impl.PropertyMethods(impl.Properties{
SupportedManifestMIMETypes: mimeTypes,
DesiredLayerCompression: types.Compress,
MustMatchRuntimeOS: false,
IgnoresEmbeddedDockerReference: false, // We do want the manifest updated; older registry versions refuse manifests if the embedded reference does not match.
HasThreadSafePutBlob: true,
Expand Down Expand Up @@ -102,10 +103,6 @@ func (d *dockerImageDestination) SupportsSignatures(ctx context.Context) error {
}
}

func (d *dockerImageDestination) DesiredLayerCompression() types.LayerCompression {
return types.Compress
}

// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
// uploaded to the image destination, true otherwise.
func (d *dockerImageDestination) AcceptsForeignLayerURLs() bool {
Expand Down
1 change: 1 addition & 0 deletions docker/internal/tarfile/dest.go
Expand Up @@ -45,6 +45,7 @@ func NewDestination(sys *types.SystemContext, archive *Writer, transportName str
SupportedManifestMIMETypes: []string{
manifest.DockerV2Schema2MediaType, // We rely on the types.Image.UpdatedImage schema conversion capabilities.
},
DesiredLayerCompression: types.Decompress,
MustMatchRuntimeOS: false,
IgnoresEmbeddedDockerReference: false, // N/A, we only accept schema2 images where EmbeddedDockerReferenceConflicts() is always false.
// The code _is_ actually thread-safe, but apart from computing sizes/digests of layers where
Expand Down
9 changes: 9 additions & 0 deletions internal/imagedestination/impl/properties.go
@@ -1,11 +1,15 @@
package impl

import "github.com/containers/image/v5/types"

// Properties collects properties of an ImageDestination that are constant throughout its lifetime
// (but might differ across instances).
type Properties struct {
// SupportedManifestMIMETypes tells which manifest MIME types the destination supports.
// A empty slice or nil means any MIME type can be tried to upload.
SupportedManifestMIMETypes []string
// DesiredLayerCompression indicates the kind of compression to apply on layers
DesiredLayerCompression types.LayerCompression
// MustMatchRuntimeOS is set to true if the destination can store only images targeted for the current runtime architecture and OS.
MustMatchRuntimeOS bool
// IgnoresEmbeddedDockerReference is set to true if the destination does not care about Image.EmbeddedDockerReferenceConflicts(),
Expand Down Expand Up @@ -36,6 +40,11 @@ func (o PropertyMethodsInitialize) SupportedManifestMIMETypes() []string {
return o.vals.SupportedManifestMIMETypes
}

// DesiredLayerCompression indicates the kind of compression to apply on layers
func (o PropertyMethodsInitialize) DesiredLayerCompression() types.LayerCompression {
return o.vals.DesiredLayerCompression
}

// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime architecture and OS. False otherwise.
func (o PropertyMethodsInitialize) MustMatchRuntimeOS() bool {
return o.vals.MustMatchRuntimeOS
Expand Down
21 changes: 9 additions & 12 deletions oci/layout/oci_dest.go
Expand Up @@ -27,10 +27,9 @@ type ociImageDestination struct {
stubs.NoPutBlobPartialInitialize
stubs.NoSignaturesInitialize

ref ociReference
index imgspecv1.Index
sharedBlobDir string
acceptUncompressedLayers bool
ref ociReference
index imgspecv1.Index
sharedBlobDir string
}

// newImageDestination returns an ImageDestination for writing to an existing directory.
Expand All @@ -51,12 +50,18 @@ func newImageDestination(sys *types.SystemContext, ref ociReference) (types.Imag
}
}

desiredLayerCompression := types.Compress
if sys != nil && sys.OCIAcceptUncompressedLayers {
desiredLayerCompression = types.PreserveOriginal
}

d := &ociImageDestination{
PropertyMethodsInitialize: impl.PropertyMethods(impl.Properties{
SupportedManifestMIMETypes: []string{
imgspecv1.MediaTypeImageManifest,
imgspecv1.MediaTypeImageIndex,
},
DesiredLayerCompression: desiredLayerCompression,
MustMatchRuntimeOS: false,
IgnoresEmbeddedDockerReference: false, // N/A, DockerReference() returns nil.
HasThreadSafePutBlob: true,
Expand All @@ -70,7 +75,6 @@ func newImageDestination(sys *types.SystemContext, ref ociReference) (types.Imag
d.Compat = impl.AddCompat(d)
if sys != nil {
d.sharedBlobDir = sys.OCISharedBlobDirPath
d.acceptUncompressedLayers = sys.OCIAcceptUncompressedLayers
}

if err := ensureDirectoryExists(d.ref.dir); err != nil {
Expand All @@ -96,13 +100,6 @@ func (d *ociImageDestination) Close() error {
return nil
}

func (d *ociImageDestination) DesiredLayerCompression() types.LayerCompression {
if d.acceptUncompressedLayers {
return types.PreserveOriginal
}
return types.Compress
}

// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
// uploaded to the image destination, true otherwise.
func (d *ociImageDestination) AcceptsForeignLayerURLs() bool {
Expand Down
6 changes: 1 addition & 5 deletions ostree/ostree_dest.go
Expand Up @@ -93,6 +93,7 @@ func newImageDestination(ref ostreeReference, tmpDirPath string) (types.ImageDes
d := &ostreeImageDestination{
PropertyMethodsInitialize: impl.PropertyMethods(impl.Properties{
SupportedManifestMIMETypes: []string{manifest.DockerV2Schema2MediaType},
DesiredLayerCompression: types.PreserveOriginal,
MustMatchRuntimeOS: true,
IgnoresEmbeddedDockerReference: false, // N/A, DockerReference() returns nil.
HasThreadSafePutBlob: false,
Expand Down Expand Up @@ -126,11 +127,6 @@ func (d *ostreeImageDestination) Close() error {
return os.RemoveAll(d.tmpDirPath)
}

// ShouldCompressLayers returns true iff it is desirable to compress layer blobs written to this destination.
func (d *ostreeImageDestination) DesiredLayerCompression() types.LayerCompression {
return types.PreserveOriginal
}

// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
// uploaded to the image destination, true otherwise.
func (d *ostreeImageDestination) AcceptsForeignLayerURLs() bool {
Expand Down
11 changes: 4 additions & 7 deletions storage/storage_image.go
Expand Up @@ -414,6 +414,10 @@ func newImageDestination(sys *types.SystemContext, imageRef storageReference) (*
manifest.DockerV2Schema1SignedMediaType,
manifest.DockerV2Schema1MediaType,
},
// We ultimately have to decompress layers to populate trees on disk
// and need to explicitly ask for it here, so that the layers' MIME
// types can be set accordingly.
DesiredLayerCompression: types.PreserveOriginal,
MustMatchRuntimeOS: true,
IgnoresEmbeddedDockerReference: true, // Yes, we want the unmodified manifest
HasThreadSafePutBlob: true,
Expand Down Expand Up @@ -455,13 +459,6 @@ func (s *storageImageDestination) Close() error {
return os.RemoveAll(s.directory)
}

func (s *storageImageDestination) DesiredLayerCompression() types.LayerCompression {
// We ultimately have to decompress layers to populate trees on disk
// and need to explicitly ask for it here, so that the layers' MIME
// types can be set accordingly.
return types.PreserveOriginal
}

func (s *storageImageDestination) computeNextBlobCacheFile() string {
return filepath.Join(s.directory, fmt.Sprintf("%d", atomic.AddInt32(&s.nextTempFileID, 1)))
}
Expand Down

0 comments on commit 9a2d2f5

Please sign in to comment.