Skip to content

Conversation

@a-palchikov
Copy link
Contributor

This is an attempt to fix #5556 by implementing support for separate exporter responses.

While working on this, I realized that I don't quite understand the preinitialized sessions and how custom-initialized sessions play with the exporter configuration:

buildkit/client/solve.go

Lines 49 to 50 in 7d7a919

SharedSession *session.Session // TODO: refactor to better session syncing
SessionPreInitialized bool // TODO: refactor to better session syncing

I've moved some code that sets up exporter configuration in the session to a public API but this is definitely something I'd like more feedback and context on. Basically, I was thinking along the lines of allowing users setting up sessions on their own to reuse some work that buildkit does internally.

Otherwise, on to the actual issue: I'm trying to re-introduce explicit exporter IDs as I believe it's hard to avoid this at this point. And unless there's going to be major architectural changes around exports soon, I think this should lay some ground for further improvements with the cache exports.
By re-introducing IDs, I also removed them from actual exporter implementations as I think they carry little weight there and were introducing a point of inconsistency with the assumption that they are indices in some array. Instead - these are completely under control of the client for now.

I'm still working on tests.

Let me know if this is the direction to go or there are other options to explore.

@tonistiigi @jedevc @crazy-max @LaurentGoderre

client/graph.go Outdated
Comment on lines 59 to 60
ExporterResponse map[string]string
ExporterResponse map[string]string
ExporterResponses []ExporterResponse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, I think I suggested this before in #4134 (comment) (but never got around to it 😢)

While we're here though, we should also split out the CacheExporterResponses as well, since those currently suffer from exactly the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll focus on the image exporters for now with the tests. Will see if supporting cache responses is something that can be included or done separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, atm, all the exporters and cache export results are merged into this one ExporterResponse map.

If all the exporters are made their own item in a list, then the caches should be split out too. We definitely shouldn't try and merge all the cache exporters into all the ExporterResponses (that's possibly the most confusing behavior).

@jedevc
Copy link
Member

jedevc commented Dec 11, 2024

Not 100% convinced on re-introducing exporter IDs - that said, no objection, I think I liked them removed because it felt simpler, so if it feels necessary to add them back, I don't think it's too much of an issue.

Bringing them back might actually be as simple as reverting and fixing the rebase issues in 1c1777b? Although we still need the backwards-compat with old clients / servers.

@tonistiigi
Copy link
Member

@crazy-max How will this affect --metadata-file in buildx?

@crazy-max
Copy link
Member

crazy-max commented Dec 12, 2024

@crazy-max How will this affect --metadata-file in buildx?

We would need to handle new list of resp.ExporterResponses instead of single map resp.ExporterResponse: https://github.com/docker/buildx/blob/3e3242cfdda23ab9077dde54479a74d26fcc2242/commands/build.go#L368-L400

Main case is to get the image id from it and from what I see we would need to pick the right one (docker exporter) for --iidfile flag. I recall we wanted to deprecate iidfile at some point, maybe it's time now 😅

The other case is in our GHA where we use the metadata to set imageid and digest: https://github.com/docker/build-push-action/?tab=readme-ov-file#outputs, see https://github.com/docker/build-push-action/blob/11be14d908760a0756f045980728ec5fb7880f74/src/main.ts#L120

Would need some changes in our toolkit to check if multiple exporter responses are available: https://github.com/docker/actions-toolkit/blob/ba72b5ac36b2cacdd458ba242d8ec94f5de373bf/src/buildx/build.ts#L113-L124 but not sure what "digest" would be the right one. Maybe the very first one for backward compat and we could have a new digests input that would be a map but then we would need some kind of ID if user wants to pick a specific one.

@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from 07fafeb to 1799133 Compare December 15, 2024 23:49
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from 9264400 to 3e59e14 Compare December 23, 2024 12:23
@a-palchikov
Copy link
Contributor Author

@jedevc @tonistiigi @crazy-max Updated to keep cache export responses separate as well.

@a-palchikov a-palchikov marked this pull request as ready for review December 23, 2024 17:14
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 3 times, most recently from f88a9e1 to 3dda6be Compare January 10, 2025 12:53
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 3 times, most recently from 10e1b40 to 7db8d3f Compare January 20, 2025 09:49
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from 89259b4 to 18788b5 Compare January 24, 2025 20:00
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 3 times, most recently from 7bdc5cc to 1721c8c Compare February 7, 2025 23:49
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from 438cc71 to cbafd8c Compare February 11, 2025 12:24
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from 0614490 to 12efd01 Compare July 11, 2025 23:35
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from 12efd01 to 42c1f44 Compare July 21, 2025 11:32
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from 42c1f44 to b253b0d Compare August 5, 2025 15:47
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from b253b0d to fa9d3e5 Compare August 19, 2025 17:17
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from 50f9487 to 9533fc4 Compare September 8, 2025 16:51
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from 2f0d5bd to 040d974 Compare September 30, 2025 17:27
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 3 times, most recently from 967d80c to 76e70cf Compare October 10, 2025 11:17
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from ae783fe to e496f9b Compare October 18, 2025 21:23
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 3 times, most recently from 167026e to c55dc31 Compare October 28, 2025 12:40
@jedevc
Copy link
Member

jedevc commented Oct 28, 2025

@a-palchikov thanks for keeping this rebased for so long (sorry, I've been a bit inactive here).

I'd really like to move this forward, currently this information gets completely lost, so if we can get the API to serve it that's perfect. I don't know if your intention is to get this merged, or whether you're just treating as a place to keep a fork up-to-date.

I started reviewing, I have a couple things:

  • Some of the refactoring are a bit far reaching, e.g. I'm not sure the refactoring in solve.go is all necessary in this change. Not to say we shouldn't work to tidy up that logic, but, it feels orthoganal to getting the API in the right shape.

  • I still don't feel convinced on the exporter IDs. I know it's a while back, but using the array indices seems fine to me (also avoids us needing to update clients to create and send those).

    If we do add IDs here though, we should probably do the same for the cache exporters?

    Don't really know, (tbf, don't really care, but switching seems like more work in updating clients, even if it's less work in updating the engine). Happy to defer to @tonistiigi on this point.

I'm happy to post a longer review, or to just hack on this myself, I feel like it's been left hanging for ages (again, sorry, I dropped the ball here).

@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from f7312cd to 47c5a84 Compare November 7, 2025 17:19
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 2 times, most recently from 7c2c504 to d82efe5 Compare November 17, 2025 11:39
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch 3 times, most recently from 8d98df9 to eaef139 Compare November 27, 2025 14:08
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from eaef139 to f060d21 Compare December 2, 2025 17:12
unfinished in the sense that exporter responses (which are abstracted as
a map of key/value pairs) are combined into a single map at the end of
the export: https://github.com/moby/buildkit/blob/55a7483b0564a7ad5b2ce5e62512789dce327bca/solver/llbsolver/solver.go#L808-L809

In order to provide the correct exporter response, each response
(currently at least each container image exporter) needs to be dedicated
to the exporter instance.

To achieve this, assign and propagate exporter IDs from the client and
have corresponding exporters annotate their responses with the
respective ID so the client can order outputs per exporter instance.

Fixes moby#5556.

Output descriptors in container image exporters with backwards-compatible fallbacks. Move the exporter set up to a public helper API so that users that custom-initialize the session can benefit from being able to configure exporters correctly.
Remove ids from the exporter implementation further shifting the burden of managing exporter identities to the control/client so it can be unified and kept an implementation detail as much as possible. Implement support for multiple exporter responses in APIs.

Signed-off-by: a-palchikov <[email protected]>
image formats generated different metadata.

Signed-off-by: a-palchikov <[email protected]>
by adding IDs similar to output exporters.

Signed-off-by: a-palchikov <[email protected]>
@a-palchikov a-palchikov force-pushed the dima/multiple-exporter-responses-dev branch from f060d21 to e752005 Compare December 4, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combining --output type=oci and type=docker results in invalid OCI image

4 participants