From a23be18813fea6b3b1a1213ae5d75c2a7ecad41c Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Thu, 27 Jun 2024 05:04:29 +0000 Subject: [PATCH] add --- go.mod | 2 +- go.sum | 4 ++-- pkg/overlay/pack.go | 21 ++++++++++++++------- pkg/stacker/build.go | 2 +- pkg/types/storage.go | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 31a22119..e7c00439 100644 --- a/go.mod +++ b/go.mod @@ -284,6 +284,6 @@ require ( ) replace ( - github.com/opencontainers/umoci => github.com/rchincha/umoci v0.0.0-20240626041051-8a70aa6ab09f + github.com/opencontainers/umoci => github.com/rchincha/umoci v0.0.0-20240626163940-d5817dc92d4c stackerbuild.io/stacker-bom => github.com/project-stacker/stacker-bom v0.0.0-20240509203427-4d685e046780 ) diff --git a/go.sum b/go.sum index ce19ba19..9bf3bf50 100644 --- a/go.sum +++ b/go.sum @@ -816,8 +816,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/rchincha/umoci v0.0.0-20240626041051-8a70aa6ab09f h1:kb6KNqJtAu7bF//luRE42U3ySX79bn0iO+5FVXuEnLo= -github.com/rchincha/umoci v0.0.0-20240626041051-8a70aa6ab09f/go.mod h1:XUXUpCpA/Y8aJWezK1i8o4WDR0Y/vhMcWg+FUNQkKMQ= +github.com/rchincha/umoci v0.0.0-20240626163940-d5817dc92d4c h1:aqbiVMze/TB97xVPAbuu1ryhEK7bKhCU3LAQmT8Pnkw= +github.com/rchincha/umoci v0.0.0-20240626163940-d5817dc92d4c/go.mod h1:XUXUpCpA/Y8aJWezK1i8o4WDR0Y/vhMcWg+FUNQkKMQ= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/pkg/overlay/pack.go b/pkg/overlay/pack.go index 2f32179d..94df76c2 100644 --- a/pkg/overlay/pack.go +++ b/pkg/overlay/pack.go @@ -283,13 +283,13 @@ func (o *overlay) initializeBasesInOutput(name string, layerTypes []types.LayerT return nil } -func (o *overlay) Repack(name string, layerTypes []types.LayerType, sfm types.StackerFiles) error { +func (o *overlay) Repack(name string, layer types.Layer, layerTypes []types.LayerType, sfm types.StackerFiles) error { err := o.initializeBasesInOutput(name, layerTypes, sfm) if err != nil { return err } - return repackOverlay(o.config, name, layerTypes) + return repackOverlay(o.config, name, layer, layerTypes) } // generateBlob generates either a tar blob or a squashfs blob based on layerType @@ -382,7 +382,9 @@ func stripOverlayAttrsUnder(dirPath string) error { }) } -func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mutate.Mutator, name string, layerTypes []types.LayerType) (bool, error) { +func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mutate.Mutator, + name string, layer types.Layer, layerTypes []types.LayerType, +) (bool, error) { dir := path.Join(config.RootFSDir, name, "overlay") ents, err := os.ReadDir(dir) if err != nil { @@ -430,7 +432,12 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu return false, err } - ovl, err := readOverlayMetadata(config.RootFSDir, name) + var ovl overlayMetadata + if layer.From.Type != types.BuiltLayer { + ovl, err = readOverlayMetadata(config.RootFSDir, name) + } else { + ovl, err = readOverlayMetadata(config.RootFSDir, layer.From.Tag) + } if err != nil { return false, err } @@ -557,7 +564,7 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu return true, nil } -func repackOverlay(config types.StackerConfig, name string, layerTypes []types.LayerType) error { +func repackOverlay(config types.StackerConfig, name string, layer types.Layer, layerTypes []types.LayerType) error { oci, err := umoci.OpenLayout(config.OCIDir) if err != nil { return err @@ -612,7 +619,7 @@ func repackOverlay(config types.StackerConfig, name string, layerTypes []types.L // generate blobs for each build layer for _, buildLayer := range ovl.BuiltLayers { - didMutate, err := generateLayer(config, oci, mutators, buildLayer, layerTypes) + didMutate, err := generateLayer(config, oci, mutators, buildLayer, layer, layerTypes) if err != nil { return err } @@ -647,7 +654,7 @@ func repackOverlay(config types.StackerConfig, name string, layerTypes []types.L return err } - didMutate, err := generateLayer(config, oci, mutators, name, layerTypes) + didMutate, err := generateLayer(config, oci, mutators, name, layer, layerTypes) if err != nil { return err } diff --git a/pkg/stacker/build.go b/pkg/stacker/build.go index 8771e75d..d51b8f9f 100644 --- a/pkg/stacker/build.go +++ b/pkg/stacker/build.go @@ -551,7 +551,7 @@ func (b *Builder) build(s types.Storage, file string) error { continue } - err = s.Repack(name, opts.LayerTypes, b.builtStackerfiles) + err = s.Repack(name, l, opts.LayerTypes, b.builtStackerfiles) if err != nil { return err } diff --git a/pkg/types/storage.go b/pkg/types/storage.go index 03487fbf..e19a992d 100644 --- a/pkg/types/storage.go +++ b/pkg/types/storage.go @@ -47,7 +47,7 @@ type Storage interface { Unpack(tag, name string) error // Repack repacks the specified working dir into the specified OCI dir. - Repack(name string, layerTypes []LayerType, sfm StackerFiles) error + Repack(name string, layer Layer, layerTypes []LayerType, sfm StackerFiles) error // GetLXCRootfsConfig returns the string that should be set as // lxc.rootfs.path in the LXC container's config.