Add session callback before export completion #4139
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.
This allows for more neatly adding client-side logic that allows affecting the status of the export.
For example, in buildx for the
docker
driver, we have logic for taking the resultingtype=image
export and pushing it to a registry: https://github.com/docker/buildx/blob/master/build/build.go#L1149. Additionally, we have follow-ups for multi-node manifest list merging https://github.com/docker/buildx/blob/master/build/build.go#L1035.Eventually, we'll also want something similar in relation to moby/moby#44369, where we'll want the client to stream content from the BuildKit image exporter's containerd store into the client's containerd store directly.
These kind of client-side exporter follow-ups are reasonably common, but currently, because the result of the build export is only available after a call to Solve, then we can't:
unpack
, the results will be cleaned up by GC at some point after Solve.To resolve this, we can add a new session API - this new API will be called immediately after the exporter runs and we know whether it succeeded or failed, but before the underlying resources are cleaned up, and before
Solve
succeeds. This allows us to affect the final error message and exporter response from Solve, as well as guarantee access to any image layers/etc before they are cleaned up.A few considered alternatives:
custom
exporter that simply calls the client-side callback, without propagating it through each exporter. The issue is that we'd still need to duplicate much of theimage
exporter to ensure that the layers we'd want to pull are present. This is also much less flexible, and can't be used everywhere.Note: this should work with #2760, so we'd likely want to modify this to include an exporter ID if we take this approach.
Naming is hard,
export
is definitely the wrong name for this new session API, but struggling to come up with anything different 😢