mirror of
https://github.com/docker/buildx.git
synced 2024-11-22 15:37:16 +08:00
build: infer platform from first node if none set
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
aac7a47469
commit
54032316f9
@ -166,35 +166,34 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog
|
||||
|
||||
perfect := true
|
||||
nodeIdxs := make([]int, 0)
|
||||
if len(ps) == 0 {
|
||||
idx := r.get(platforms.DefaultSpec(), matcher, additional)
|
||||
for _, p := range ps {
|
||||
idx := r.get(p, matcher, additional)
|
||||
if idx == -1 {
|
||||
idx = 0
|
||||
perfect = false
|
||||
}
|
||||
nodeIdxs = append(nodeIdxs, idx)
|
||||
} else {
|
||||
for _, p := range ps {
|
||||
idx := r.get(p, matcher, additional)
|
||||
if idx == -1 {
|
||||
idx = 0
|
||||
perfect = false
|
||||
}
|
||||
nodeIdxs = append(nodeIdxs, idx)
|
||||
}
|
||||
}
|
||||
|
||||
var nodes []*resolvedNode
|
||||
for i, idx := range nodeIdxs {
|
||||
node := &resolvedNode{
|
||||
if len(nodeIdxs) == 0 {
|
||||
nodes = append(nodes, &resolvedNode{
|
||||
resolver: r,
|
||||
driverIndex: idx,
|
||||
driverIndex: 0,
|
||||
})
|
||||
} else {
|
||||
for i, idx := range nodeIdxs {
|
||||
node := &resolvedNode{
|
||||
resolver: r,
|
||||
driverIndex: idx,
|
||||
}
|
||||
if len(ps) > 0 {
|
||||
node.platforms = []specs.Platform{ps[i]}
|
||||
}
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
if len(ps) > 0 {
|
||||
node.platforms = []specs.Platform{ps[i]}
|
||||
}
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
|
||||
nodes = recombineNodes(nodes)
|
||||
if _, err := r.boot(ctx, nodeIdxs, pw); err != nil {
|
||||
return nil, false, err
|
||||
|
@ -217,7 +217,7 @@ func TestSelectNodePreferExact(t *testing.T) {
|
||||
require.Equal(t, "bbb", res[0].Node().Builder)
|
||||
}
|
||||
|
||||
func TestSelectNodeCurrentPlatform(t *testing.T) {
|
||||
func TestSelectNodeNoPlatform(t *testing.T) {
|
||||
r := makeTestResolver(map[string][]specs.Platform{
|
||||
"aaa": {platforms.MustParse("linux/foobar")},
|
||||
"bbb": {platforms.DefaultSpec()},
|
||||
@ -227,7 +227,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)
|
||||
require.Empty(t, res[0].platforms)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user