mirror of
https://github.com/docker/buildx.git
synced 2024-11-22 15:37:16 +08:00
build: move solveOpt to local struct type
*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 <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
54032316f9
commit
9d8ac1ce2d
@ -118,6 +118,11 @@ type NamedContext struct {
|
|||||||
State *llb.State
|
State *llb.State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type reqForNode struct {
|
||||||
|
*resolvedNode
|
||||||
|
so *client.SolveOpt
|
||||||
|
}
|
||||||
|
|
||||||
func filterAvailableNodes(nodes []builder.Node) ([]builder.Node, error) {
|
func filterAvailableNodes(nodes []builder.Node) ([]builder.Node, error) {
|
||||||
out := make([]builder.Node, 0, len(nodes))
|
out := make([]builder.Node, 0, len(nodes))
|
||||||
err := errors.Errorf("no drivers found")
|
err := errors.Errorf("no drivers found")
|
||||||
@ -519,6 +524,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
reqForNodes := make(map[string][]*reqForNode)
|
||||||
eg, ctx := errgroup.WithContext(ctx)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
for k, opt := range opt {
|
for k, opt := range opt {
|
||||||
@ -528,6 +534,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Warn("current commit information was not captured by the build")
|
logrus.WithError(err).Warn("current commit information was not captured by the build")
|
||||||
}
|
}
|
||||||
|
var reqn []*reqForNode
|
||||||
for _, np := range drivers[k] {
|
for _, np := range drivers[k] {
|
||||||
if np.Node().Driver.IsMobyDriver() {
|
if np.Node().Driver.IsMobyDriver() {
|
||||||
hasMobyDriver = true
|
hasMobyDriver = true
|
||||||
@ -548,8 +555,12 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
so.FrontendAttrs[k] = v
|
so.FrontendAttrs[k] = v
|
||||||
}
|
}
|
||||||
defers = append(defers, release)
|
defers = append(defers, release)
|
||||||
np.SolveOpt = so
|
reqn = append(reqn, &reqForNode{
|
||||||
|
resolvedNode: np,
|
||||||
|
so: so,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
reqForNodes[k] = reqn
|
||||||
for _, at := range opt.Session {
|
for _, at := range opt.Session {
|
||||||
if s, ok := at.(interface {
|
if s, ok := at.(interface {
|
||||||
SetLogger(progresswriter.Logger)
|
SetLogger(progresswriter.Logger)
|
||||||
@ -562,8 +573,8 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
|
|
||||||
// validate for multi-node push
|
// validate for multi-node push
|
||||||
if hasMobyDriver && multiDriver {
|
if hasMobyDriver && multiDriver {
|
||||||
for _, np := range drivers[k] {
|
for _, np := range reqForNodes[k] {
|
||||||
for _, e := range np.SolveOpt.Exports {
|
for _, e := range np.so.Exports {
|
||||||
if e.Type == "moby" {
|
if e.Type == "moby" {
|
||||||
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
||||||
return nil, errors.Errorf("multi-node push can't currently be performed with the docker driver, please switch to a different driver")
|
return nil, errors.Errorf("multi-node push can't currently be performed with the docker driver, please switch to a different driver")
|
||||||
@ -576,9 +587,9 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
|
|
||||||
// validate that all links between targets use same drivers
|
// validate that all links between targets use same drivers
|
||||||
for name := range opt {
|
for name := range opt {
|
||||||
dps := drivers[name]
|
dps := reqForNodes[name]
|
||||||
for i, dp := range dps {
|
for i, dp := range dps {
|
||||||
so := drivers[name][i].SolveOpt
|
so := reqForNodes[name][i].so
|
||||||
for k, v := range so.FrontendAttrs {
|
for k, v := range so.FrontendAttrs {
|
||||||
if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") {
|
if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") {
|
||||||
k2 := strings.TrimPrefix(v, "target:")
|
k2 := strings.TrimPrefix(v, "target:")
|
||||||
@ -606,7 +617,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
results := waitmap.New()
|
results := waitmap.New()
|
||||||
|
|
||||||
multiTarget := len(opt) > 1
|
multiTarget := len(opt) > 1
|
||||||
childTargets := calculateChildTargets(drivers, opt)
|
childTargets := calculateChildTargets(reqForNodes, opt)
|
||||||
|
|
||||||
for k, opt := range opt {
|
for k, opt := range opt {
|
||||||
err := func(k string) error {
|
err := func(k string) error {
|
||||||
@ -630,7 +641,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
for i, dp := range dps {
|
for i, dp := range dps {
|
||||||
i, dp := i, dp
|
i, dp := i, dp
|
||||||
node := dp.Node()
|
node := dp.Node()
|
||||||
so := drivers[k][i].SolveOpt
|
so := reqForNodes[k][i].so
|
||||||
if multiDriver {
|
if multiDriver {
|
||||||
for i, e := range so.Exports {
|
for i, e := range so.Exports {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
@ -1299,12 +1310,12 @@ func resultKey(index int, name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculateChildTargets returns all the targets that depend on current target for reverse index
|
// calculateChildTargets returns all the targets that depend on current target for reverse index
|
||||||
func calculateChildTargets(drivers map[string][]*resolvedNode, opt map[string]Options) map[string][]string {
|
func calculateChildTargets(reqs map[string][]*reqForNode, opt map[string]Options) map[string][]string {
|
||||||
out := make(map[string][]string)
|
out := make(map[string][]string)
|
||||||
for name := range opt {
|
for name := range opt {
|
||||||
dps := drivers[name]
|
dps := reqs[name]
|
||||||
for i, dp := range dps {
|
for i, dp := range dps {
|
||||||
so := drivers[name][i].SolveOpt
|
so := reqs[name][i].so
|
||||||
for k, v := range so.FrontendAttrs {
|
for k, v := range so.FrontendAttrs {
|
||||||
if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") {
|
if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") {
|
||||||
target := resultKey(dp.driverIndex, strings.TrimPrefix(v, "target:"))
|
target := resultKey(dp.driverIndex, strings.TrimPrefix(v, "target:"))
|
||||||
|
@ -19,8 +19,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type resolvedNode struct {
|
type resolvedNode struct {
|
||||||
SolveOpt *client.SolveOpt
|
|
||||||
|
|
||||||
resolver *nodeResolver
|
resolver *nodeResolver
|
||||||
driverIndex int
|
driverIndex int
|
||||||
platforms []specs.Platform
|
platforms []specs.Platform
|
||||||
|
Loading…
Reference in New Issue
Block a user