mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
buildx: rollback configuration if create fails
This builds on the added warnings from initialized builders, now erroring the command, and additionally attempting to revert to the previous configuration. To preserve the previous configuration, we add a deep Copy() function to the NodeGroup and Node so that we can easily restore it later if we encounter a failure. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@ -110,6 +110,44 @@ func (ng *NodeGroup) Update(name, endpoint string, platforms []string, endpoints
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ng *NodeGroup) Copy() *NodeGroup {
|
||||
nodes := make([]Node, len(ng.Nodes))
|
||||
for i, node := range ng.Nodes {
|
||||
nodes[i] = *node.Copy()
|
||||
}
|
||||
return &NodeGroup{
|
||||
Name: ng.Name,
|
||||
Driver: ng.Driver,
|
||||
Nodes: nodes,
|
||||
Dynamic: ng.Dynamic,
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Node) Copy() *Node {
|
||||
platforms := []specs.Platform{}
|
||||
copy(platforms, n.Platforms)
|
||||
flags := []string{}
|
||||
copy(flags, n.Flags)
|
||||
driverOpts := map[string]string{}
|
||||
for k, v := range n.DriverOpts {
|
||||
driverOpts[k] = v
|
||||
}
|
||||
files := map[string][]byte{}
|
||||
for k, v := range n.Files {
|
||||
vv := []byte{}
|
||||
copy(vv, v)
|
||||
files[k] = vv
|
||||
}
|
||||
return &Node{
|
||||
Name: n.Name,
|
||||
Endpoint: n.Endpoint,
|
||||
Platforms: platforms,
|
||||
Flags: flags,
|
||||
DriverOpts: driverOpts,
|
||||
Files: files,
|
||||
}
|
||||
}
|
||||
|
||||
func (ng *NodeGroup) validateDuplicates(ep string, idx int) error {
|
||||
i := 0
|
||||
for _, n := range ng.Nodes {
|
||||
|
Reference in New Issue
Block a user