mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-21 19:27:46 +08:00
Merge pull request #1128 from crazy-max/rm
rm: display removed builder and disallow removing context builders
This commit is contained in:
commit
35f4268081
@ -81,9 +81,9 @@ func main() {
|
|||||||
s.Print(cmd.Err())
|
s.Print(cmd.Err())
|
||||||
}
|
}
|
||||||
if debug.IsEnabled() {
|
if debug.IsEnabled() {
|
||||||
fmt.Fprintf(cmd.Err(), "error: %+v", stack.Formatter(err))
|
fmt.Fprintf(cmd.Err(), "ERROR: %+v", stack.Formatter(err))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(cmd.Err(), "error: %v\n", err)
|
fmt.Fprintf(cmd.Err(), "ERROR: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -2,6 +2,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/buildx/store"
|
"github.com/docker/buildx/store"
|
||||||
@ -43,30 +44,41 @@ func runRm(dockerCli command.Cli, in rmOptions) error {
|
|||||||
return rmAllInactive(ctx, txn, dockerCli, in)
|
return rmAllInactive(ctx, txn, dockerCli, in)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ng *store.NodeGroup
|
||||||
if in.builder != "" {
|
if in.builder != "" {
|
||||||
ng, err := storeutil.GetNodeGroup(txn, dockerCli, in.builder)
|
ng, err = storeutil.GetNodeGroup(txn, dockerCli, in.builder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err1 := rm(ctx, dockerCli, in, ng)
|
} else {
|
||||||
if err := txn.Remove(ng.Name); err != nil {
|
ng, err = storeutil.GetCurrentInstance(txn, dockerCli)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return err1
|
}
|
||||||
|
if ng == nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ng, err := storeutil.GetCurrentInstance(txn, dockerCli)
|
ctxbuilders, err := dockerCli.ContextStore().List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if ng != nil {
|
for _, cb := range ctxbuilders {
|
||||||
err1 := rm(ctx, dockerCli, in, ng)
|
if ng.Driver == "docker" && len(ng.Nodes) == 1 && ng.Nodes[0].Endpoint == cb.Name {
|
||||||
if err := txn.Remove(ng.Name); err != nil {
|
return errors.Errorf("context builder cannot be removed, run `docker context rm %s` to remove this context", cb.Name)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err1 := rm(ctx, dockerCli, in, ng)
|
||||||
|
if err := txn.Remove(ng.Name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err1 != nil {
|
||||||
return err1
|
return err1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, _ = fmt.Fprintf(dockerCli.Err(), "%s removed\n", ng.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +164,7 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i
|
|||||||
if err := txn.Remove(b.ng.Name); err != nil {
|
if err := txn.Remove(b.ng.Name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, _ = fmt.Fprintf(dockerCli.Err(), "%s removed\n", b.ng.Name)
|
||||||
return rmerr
|
return rmerr
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user