-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the default platform for select sources based on host arch #152
Conversation
Benchmark Test ResultsBenchmark results from the latest changes vs base branch
|
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
543bdf2
to
bea3bc0
Compare
…tform Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
switch source { | ||
case image.DockerTarballSource, image.OciDirectorySource, image.OciTarballSource, image.SingularitySource: | ||
if cfg.Platform != nil { | ||
return fmt.Errorf("specified platform=%q however image source=%q does not support selecting platform", cfg.Platform.String(), source.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be an error? could it just safely be ignored here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that the user explicitly asked for an image with the given platform, we don't want to analyze a different image than what was intended. Logging an error would allow for the analysis to continue, and say in syft an SBOM to be produced, but the SBOM config would show a platform that differs than that of what was really analyzed (which seems wrong)
provider = sif.NewProviderFromPath(imgStr, tempDirGenerator) | ||
default: | ||
return nil, fmt.Errorf("unable to determine image source") | ||
} | ||
return provider, nil | ||
} | ||
|
||
func setPlatform(source image.Source, cfg *config, defaultArch string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: setDefaultPlatform
or similar, since it does nothing if platform is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's probably the right name 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, on second thought, this is also verifying that a non-default, non-nil platform is allowed to be set by the user... which goes beyond setting the default. There is probably a better name for this but setPlatform and setDefaultPlatform both don't quite fit the bill... but setPlatform is slightly less incorrect, so I'll leave it for now.
…re#152) * set the default platform for select sources based on host arch Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * decompose into smaller function and add tests for setting default platform Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This PR sets a default platform to image providers that support platform options only if there is no overriding platform specified by the caller.
This should help alleviate the problems described in anchore/syft#1391 .
Fixes #149