Skip to content
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

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Jan 12, 2023

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

@github-actions
Copy link

github-actions bot commented Jan 12, 2023

Benchmark Test Results

Benchmark results from the latest changes vs base branch
latest: Pulling from library/ubuntu
goos: linux
goarch: amd64
pkg: github.com/anchore/stereoscope/pkg/file
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
docker: 
           │ ./.tmp/benchmark-ce31051.txt │
           │            sec/op            │
TarIndex-2                   44.23µ ± ∞ ¹
¹ need >= 6 samples for confidence interval at level 0.95

           │ ./.tmp/benchmark-ce31051.txt │
           │             B/op             │
TarIndex-2                  5.561Ki ± ∞ ¹
¹ need >= 6 samples for confidence interval at level 0.95

           │ ./.tmp/benchmark-ce31051.txt │
           │          allocs/op           │
TarIndex-2                    93.00 ± ∞ ¹
¹ need >= 6 samples for confidence interval at level 0.95

pkg: github.com/anchore/stereoscope/test/integration
                                      │ ./.tmp/benchmark-ce31051.txt │
                                      │            sec/op            │
SimpleImage_GetImage/docker-archive-2                   1.493m ± ∞ ¹
SimpleImage_GetImage/oci-archive-2                      2.229m ± ∞ ¹
SimpleImage_GetImage/oci-dir-2                          780.8µ ± ∞ ¹
geomean                                                 1.375m
¹ need >= 6 samples for confidence interval at level 0.95

                                      │ ./.tmp/benchmark-ce31051.txt │
                                      │             B/op             │
SimpleImage_GetImage/docker-archive-2                  357.8Ki ± ∞ ¹
SimpleImage_GetImage/oci-archive-2                     632.7Ki ± ∞ ¹
SimpleImage_GetImage/oci-dir-2                         399.9Ki ± ∞ ¹
geomean                                                449.0Ki
¹ need >= 6 samples for confidence interval at level 0.95

                                      │ ./.tmp/benchmark-ce31051.txt │
                                      │          allocs/op           │
SimpleImage_GetImage/docker-archive-2                   2.835k ± ∞ ¹
SimpleImage_GetImage/oci-archive-2                      1.549k ± ∞ ¹
SimpleImage_GetImage/oci-dir-2                          1.333k ± ∞ ¹
geomean                                                 1.802k
¹ need >= 6 samples for confidence interval at level 0.95

docker: Error response from daemon: Get "http://localhost/v2/": dial tcp [::1]:80: connect: connection refused.
                                                   │ ./.tmp/benchmark-ce31051.txt │
                                                   │            sec/op            │
SimpleImage_FetchSquashedContents/docker-archive-2                   17.21µ ± ∞ ¹
¹ need >= 6 samples for confidence interval at level 0.95

                                                   │ ./.tmp/benchmark-ce31051.txt │
                                                   │             B/op             │
SimpleImage_FetchSquashedContents/docker-archive-2                  2.648Ki ± ∞ ¹
¹ need >= 6 samples for confidence interval at level 0.95

                                                   │ ./.tmp/benchmark-ce31051.txt │
                                                   │          allocs/op           │
SimpleImage_FetchSquashedContents/docker-archive-2                    21.00 ± ∞ ¹
¹ need >= 6 samples for confidence interval at level 0.95

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
@wagoodman wagoodman force-pushed the loosen-platform-requirements branch from 543bdf2 to bea3bc0 Compare March 23, 2023 14:58
…tform

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
@wagoodman wagoodman marked this pull request as ready for review March 23, 2023 16:08
@wagoodman wagoodman requested a review from a team March 23, 2023 16:08
@wagoodman wagoodman enabled auto-merge (squash) March 23, 2023 16:10
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())
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

@wagoodman wagoodman Mar 23, 2023

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 👍

Copy link
Contributor Author

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.

@wagoodman wagoodman merged commit d7551b7 into main Mar 23, 2023
@wagoodman wagoodman deleted the loosen-platform-requirements branch March 23, 2023 16:15
spiffcs added a commit that referenced this pull request May 5, 2023
willmurphyscode added a commit that referenced this pull request Jun 9, 2023
willmurphyscode added a commit that referenced this pull request Jun 9, 2023
#152)"

This reverts commit d7551b7.

Signed-off-by: Will Murphy <will.murphy@anchore.com>
gnmahanth pushed a commit to deepfence/stereoscope that referenced this pull request Jun 15, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stereoscope pulls different images when using docker: vs registry: from multi-platform images
2 participants