mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 22:12:28 +01:00
- 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>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package stereoscopesource
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/anchore/go-collections"
|
|
"github.com/anchore/stereoscope"
|
|
"github.com/anchore/stereoscope/pkg/image"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
const ImageTag = "image"
|
|
|
|
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 {
|
|
stereoscopeProvider image.Provider
|
|
cfg ProviderConfig
|
|
}
|
|
|
|
var _ source.Provider = (*stereoscopeImageSourceProvider)(nil)
|
|
|
|
func (l stereoscopeImageSourceProvider) Name() string {
|
|
return l.stereoscopeProvider.Name()
|
|
}
|
|
|
|
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
|
|
}
|
|
cfg := ImageConfig{
|
|
Reference: l.cfg.StereoscopeImageProviderConfig.UserInput,
|
|
Platform: l.cfg.StereoscopeImageProviderConfig.Platform,
|
|
RegistryOptions: &l.cfg.StereoscopeImageProviderConfig.Registry,
|
|
Exclude: l.cfg.Exclude,
|
|
Alias: l.cfg.Alias,
|
|
}
|
|
return New(img, cfg), nil
|
|
}
|
|
|
|
func Providers(cfg ProviderConfig) []collections.TaggedValue[source.Provider] {
|
|
stereoscopeProviders := collections.TaggedValueSet[source.Provider]{}
|
|
providers := stereoscope.ImageProviders(cfg.StereoscopeImageProviderConfig)
|
|
for _, provider := range providers {
|
|
var sourceProvider source.Provider = stereoscopeImageSourceProvider{
|
|
stereoscopeProvider: provider.Value,
|
|
cfg: cfg,
|
|
}
|
|
stereoscopeProviders = append(stereoscopeProviders,
|
|
collections.NewTaggedValue(sourceProvider, append([]string{provider.Value.Name(), ImageTag}, provider.Tags...)...))
|
|
}
|
|
return stereoscopeProviders
|
|
}
|