perf: keep only the image squash when scanning with the squashed scope

- stereoscope builds a squashed tree for every layer, each a full copy of the one below, so memory
  grows with layers x files. The squashed scope only ever reads the top one.
- new `GetSourceConfig.WithImageSquashOnly(bool)` (and `sourceproviders.Config` field) reads images
  with stereoscope's `image.WithImageSquashOnly`, scoped to that one read
- the CLI turns it on when `--scope squashed` (the default)
- an image source read this way returns an error from `FileResolver` for `all-layers` and
  `deep-squashed` instead of panicking on the missing layer squashes

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2026-10-29 12:10:12 -04:00
parent 12f0e2d837
commit b2807f60d2
7 changed files with 108 additions and 3 deletions
@@ -15,6 +15,8 @@ type ProviderConfig struct {
StereoscopeImageProviderConfig stereoscope.ImageProviderConfig
Exclude source.ExcludeConfig
Alias source.Alias
// ImageSquashOnly reads the image keeping only the image squash, see image.WithImageSquashOnly
ImageSquashOnly bool
}
type stereoscopeImageSourceProvider struct {
@@ -29,6 +31,10 @@ func (l stereoscopeImageSourceProvider) Name() string {
}
func (l stereoscopeImageSourceProvider) Provide(ctx context.Context) (source.Source, error) {
if l.cfg.ImageSquashOnly {
// scoped to this read only, the caller's ctx may be shared with reads that need every layer squash
ctx = image.WithImageSquashOnly(ctx)
}
img, err := l.stereoscopeProvider.Provide(ctx)
if err != nil {
return nil, err