Skip to content

Commit

Permalink
fix: compress overlay_dir import
Browse files Browse the repository at this point in the history
Import overlays currently are generated as tar files and not compressed.
This patch compresses to produce a tar.gz blob

Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Apr 5, 2024
1 parent 6d069c7 commit b887686
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/overlay/overlay-dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/overlay/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -293,15 +293,23 @@ 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
var rootHash string
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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b887686

Please sign in to comment.