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

buildx: log errors in initializing builders #1206

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
}
}

ngOriginal := ng
if ngOriginal != nil {
ngOriginal = ngOriginal.Copy()
}

if ng == nil {
ng = &store.NodeGroup{
Name: name,
Expand Down Expand Up @@ -224,6 +229,30 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
return err
}

ngi := &nginfo{ng: ng}

timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()

if err = loadNodeGroupData(timeoutCtx, dockerCli, ngi); err != nil {
return err
}
for _, info := range ngi.drivers {
if err := info.di.Err; err != nil {
err := errors.Errorf("failed to initialize builder %s (%s): %s", ng.Name, info.di.Name, err)
var err2 error
if ngOriginal == nil {
err2 = txn.Remove(ng.Name)
} else {
err2 = txn.Save(ngOriginal)
}
if err2 != nil {
logrus.Warnf("Could not rollback to previous state: %s", err2)
}
return err
}
}

if in.use && ep != "" {
current, err := storeutil.GetCurrentEndpoint(dockerCli)
if err != nil {
Expand All @@ -234,15 +263,6 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
}
}

ngi := &nginfo{ng: ng}

timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()

if err = loadNodeGroupData(timeoutCtx, dockerCli, ngi); err != nil {
return err
}

if in.bootstrap {
if _, err = boot(ctx, ngi); err != nil {
return err
Expand Down
38 changes: 38 additions & 0 deletions store/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down