From 1e71a3ffa7d19330ceb8d3dad7dc169247085a13 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 20 May 2022 10:59:25 +0200 Subject: [PATCH 1/3] rm: disallow removing context builders Signed-off-by: CrazyMax --- commands/rm.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/commands/rm.go b/commands/rm.go index 73f33be95f8..6e387ed4659 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -43,31 +43,37 @@ func runRm(dockerCli command.Cli, in rmOptions) error { return rmAllInactive(ctx, txn, dockerCli, in) } + var ng *store.NodeGroup if in.builder != "" { - ng, err := storeutil.GetNodeGroup(txn, dockerCli, in.builder) + ng, err = storeutil.GetNodeGroup(txn, dockerCli, in.builder) if err != nil { return err } - err1 := rm(ctx, dockerCli, in, ng) - if err := txn.Remove(ng.Name); err != nil { + } else { + ng, err = storeutil.GetCurrentInstance(txn, dockerCli) + if err != nil { return err } - return err1 + } + if ng == nil { + return nil } - ng, err := storeutil.GetCurrentInstance(txn, dockerCli) + ctxbuilders, err := dockerCli.ContextStore().List() if err != nil { return err } - if ng != nil { - err1 := rm(ctx, dockerCli, in, ng) - if err := txn.Remove(ng.Name); err != nil { - return err + for _, cb := range ctxbuilders { + if ng.Driver == "docker" && len(ng.Nodes) == 1 && ng.Nodes[0].Endpoint == cb.Name { + return errors.Errorf("context builder cannot be removed, run `docker context rm %s` to remove this context", cb.Name) } - return err1 } - return nil + err1 := rm(ctx, dockerCli, in, ng) + if err := txn.Remove(ng.Name); err != nil { + return err + } + return err1 } func rmCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { From d611bbe60973dcbf5250e5d5ea5fdc2ae219b7b8 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 15 May 2022 06:10:42 +0200 Subject: [PATCH 2/3] rm: display name of removed builder Signed-off-by: CrazyMax --- commands/rm.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/rm.go b/commands/rm.go index 6e387ed4659..73144066cdb 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -2,6 +2,7 @@ package commands import ( "context" + "fmt" "time" "github.com/docker/buildx/store" @@ -73,7 +74,12 @@ func runRm(dockerCli command.Cli, in rmOptions) error { if err := txn.Remove(ng.Name); err != nil { return err } - return err1 + if err1 != nil { + return err1 + } + + _, _ = fmt.Fprintf(dockerCli.Err(), "%s removed\n", ng.Name) + return nil } func rmCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { @@ -158,6 +164,7 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i if err := txn.Remove(b.ng.Name); err != nil { return err } + _, _ = fmt.Fprintf(dockerCli.Err(), "%s removed\n", b.ng.Name) return rmerr } return nil From 54a2a0c49f158c75d84d47c78549f6b2d9f71d48 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 13 May 2022 18:00:52 +0200 Subject: [PATCH 3/3] cli: uppercase level to match logrus one Signed-off-by: CrazyMax --- cmd/buildx/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/buildx/main.go b/cmd/buildx/main.go index c4e59be014d..b3048c751f5 100644 --- a/cmd/buildx/main.go +++ b/cmd/buildx/main.go @@ -81,9 +81,9 @@ func main() { s.Print(cmd.Err()) } if debug.IsEnabled() { - fmt.Fprintf(cmd.Err(), "error: %+v", stack.Formatter(err)) + fmt.Fprintf(cmd.Err(), "ERROR: %+v", stack.Formatter(err)) } else { - fmt.Fprintf(cmd.Err(), "error: %v\n", err) + fmt.Fprintf(cmd.Err(), "ERROR: %v\n", err) } os.Exit(1)