Lazily load attestation data in imagetools inspect
#1505
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
⬆️ Follow-up to #1498
This PR improves performance for the standard case of doing a simple
imagetools inspect
command. In v0.10.0 we see a performance regression when inspecting images that have attached attestations using simple format strings like{{ json . }}
. We can resolve this performance issue by lazily loading attestation data, only when requested to by the format template.This is split into two patches:
.SBOM
and.Provenance
attributes into methods instead of properties on the struct. These can be accessed identically to the previous attributes for all valid format inputs (though we get a slightly different error message in some cases, if we attempt to pass arguments to these methods, but these are invalid inputs anyways).Because this data is now loaded lazily, it no longer makes sense to include it in the output of commands such as
{{ json . }}
, so no field forSBOM
orProvenance
is included for those.I think we can cherry-pick this to the v0.10 branch, and release it in v0.10.1? Users who were relying on the SBOM and Provenance data appearing in the output of
{{ json . }}
and similar would be affected, but this is a relatively minor change.Note: we could simplify some of this code with a
Deferred
type in the future, which would encapsulate some of the logic for computing a function and caching the result, however, we'd want to use generics for that, which would require a bump to buildx 1.18 - which we shouldn't do a minor release.