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

build: infer platform from first node if none set #2131

Merged
merged 4 commits into from
Dec 12, 2023

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Nov 20, 2023

closes #2124

If user doesn't specify any platform, it should be inferred from the first node instead of using the local platform. In follow-up we should also look at the rules suggested in #2119 (comment) to take into account the preferred platform as well.

@crazy-max crazy-max changed the title build: infer platform from first selected node if none set build: infer platform from first node if none set Nov 20, 2023
@crazy-max crazy-max marked this pull request as ready for review November 20, 2023 15:53
@@ -226,7 +226,7 @@ func TestSelectNodeCurrentPlatform(t *testing.T) {
require.NoError(t, err)
require.True(t, perfect)
require.Len(t, res, 1)
require.Equal(t, "bbb", res[0].Node().Builder)
require.Equal(t, "aaa", res[0].Node().Builder)
Copy link
Member

Choose a reason for hiding this comment

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

The real issue is that the platform in opt gets reset when it should not. We need to figure out a test to make sure it doesn't happen. Looks like the old build code only expect "resolveNode" to have a platform if it is an override to the existing platform but maybe this should be made safer (more explicit) somehow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Rebased on top of @jedevc changes in master...jedevc:buildx:fix-setting-wrong-platform-on-solve-opt to fix the solve opt case and remove the duplicated map.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not convinced we have to change this, I think we could leave the default to be the current platform - this change isn't actually needed to fix the regression.

However, no real objections, my use case for this was to ease some UX issues with docker cloud build, which I don't really have any more.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess you talk about the TestSelectNodeNoPlatform and default spec case right? It seems related to #2119 and proposed new rules in #2119 (comment) should cover this in follow-up iiuc.

jedevc and others added 3 commits November 28, 2023 10:10
This was more error prone, as opposed to the approach used prior to
616fb3e.

Signed-off-by: Justin Chadwell <[email protected]>
This regression was introduced in 616fb3e,
with the node resolution refactor.

The core issue here is just that we would unconditionally set the
solve opt's platform to the default current platform, which was
incorrect. We can prevent this easily by having a special case for the
default case, like we had before, and then not setting the platforms
field on this (which keeping the resolution behavior which was
introduced).

Signed-off-by: Justin Chadwell <[email protected]>
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

The logic side SGTM. Comment about the code organization.

build/driver.go Outdated
@@ -19,6 +19,8 @@ import (
)

type resolvedNode struct {
SolveOpt *client.SolveOpt
Copy link
Member

@tonistiigi tonistiigi Nov 29, 2023

Choose a reason for hiding this comment

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

I think @jedevc did not like the driverPair name, but this is the use case for why it was added. That we pass along a struct that contains both the driver (in here it is called resolver+platform, so driver for a specific node) and the request that create fixed 1-to-1 pairing.

I think even if we use embed structs, the separation of structs would be clearer this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

After discussing with @tonistiigi, the idea is to have a clear separation of concerns between drivers resolution and solve opts attached to the driver in build. Pushed an extra commit to move *client.SolveOpt to a local struct type in build.

build/build.go Outdated Show resolved Hide resolved
build/build.go Outdated Show resolved Hide resolved
build/build.go Outdated Show resolved Hide resolved
build/build.go Outdated Show resolved Hide resolved
*client.SolveOpt in driver code is only used by build code.
For a clear separation of concerns, move it to an internal
struct type only accessible by BuildWithResultHandler func.

Signed-off-by: CrazyMax <[email protected]>
@crazy-max crazy-max merged commit 57dc457 into docker:master Dec 12, 2023
61 checks passed
@crazy-max crazy-max deleted the fix-driver-infer-platform branch December 12, 2023 12:27
@crazy-max crazy-max added this to the v0.13.0 milestone Dec 23, 2023
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.

3 participants