diff --git a/pkg/overlay/overlay-dirs.go b/pkg/overlay/overlay-dirs.go index 249642f5..711d55d7 100644 --- a/pkg/overlay/overlay-dirs.go +++ b/pkg/overlay/overlay-dirs.go @@ -48,7 +48,7 @@ func generateOverlayDirLayer(name string, layerType types.LayerType, overlayDir defer oci.Close() contents := path.Join(config.RootFSDir, name, "overlay_dirs", path.Base(overlayDir.Source)) - blob, mediaType, rootHash, err := generateBlob(layerType, contents, config.OCIDir) + blob, mediaType, rootHash, err := generateBlob(layerType, contents, config.OCIDir, true) if err != nil { return ispec.Descriptor{}, err } diff --git a/pkg/overlay/pack.go b/pkg/overlay/pack.go index 3a6cc7d7..96cc4b92 100644 --- a/pkg/overlay/pack.go +++ b/pkg/overlay/pack.go @@ -135,7 +135,7 @@ func ConvertAndOutput(config types.StackerConfig, tag, name string, layerType ty bundlePath := overlayPath(config.RootFSDir, theLayer.Digest) overlayDir := path.Join(bundlePath, "overlay") // generate blob - blob, mediaType, rootHash, err := generateBlob(layerType, overlayDir, config.OCIDir) + blob, mediaType, rootHash, err := generateBlob(layerType, overlayDir, config.OCIDir, false) if err != nil { return err } @@ -293,7 +293,7 @@ func (o *overlay) Repack(name string, layerTypes []types.LayerType, sfm types.St } // generateBlob generates either a tar blob or a squashfs blob based on layerType -func generateBlob(layerType types.LayerType, contents string, ociDir string) (io.ReadCloser, string, string, error) { +func generateBlob(layerType types.LayerType, contents string, ociDir string, compress bool) (io.ReadCloser, string, string, error) { var blob io.ReadCloser var err error var mediaType string @@ -301,7 +301,15 @@ func generateBlob(layerType types.LayerType, contents string, ociDir string) (io if layerType.Type == "tar" { packOptions := layer.RepackOptions{TranslateOverlayWhiteouts: true} blob = layer.GenerateInsertLayer(contents, "/", false, &packOptions) - mediaType = ispec.MediaTypeImageLayer + if !compress { + mediaType = ispec.MediaTypeImageLayer + } else { + blob, err = mutate.GzipCompressor.WithOpt(gzipBlockSize).Compress(blob) + if err != nil { + return nil, "", "", err + } + mediaType = ispec.MediaTypeImageLayerGzip + } } else { blob, mediaType, rootHash, err = squashfs.MakeSquashfs(ociDir, contents, nil, layerType.Verity) if err != nil { @@ -435,7 +443,7 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu mutator := mutators[i] var desc ispec.Descriptor - blob, mediaType, rootHash, err := generateBlob(layerType, dir, config.OCIDir) + blob, mediaType, rootHash, err := generateBlob(layerType, dir, config.OCIDir, false) if err != nil { return false, err }