mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:27:49 +08:00
Merge pull request #1131 from crazy-max/ls-dedup
ls: dedup instances from store and context
This commit is contained in:
commit
4a215a943b
@ -101,6 +101,19 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !in.actionLeave && !in.actionAppend {
|
||||||
|
contexts, err := dockerCli.ContextStore().List()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, c := range contexts {
|
||||||
|
if c.Name == name {
|
||||||
|
logrus.Warnf("instance name %q already exists as context builder", name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ng, err := txn.NodeGroupByName(name)
|
ng, err := txn.NodeGroupByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(errors.Cause(err)) {
|
if os.IsNotExist(errors.Cause(err)) {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
@ -45,22 +46,29 @@ func runLs(dockerCli command.Cli, in lsOptions) error {
|
|||||||
builders[i] = &nginfo{ng: ng}
|
builders[i] = &nginfo{ng: ng}
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := dockerCli.ContextStore().List()
|
contexts, err := dockerCli.ContextStore().List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctxbuilders := make([]*nginfo, len(list))
|
sort.Slice(contexts, func(i, j int) bool {
|
||||||
for i, l := range list {
|
return contexts[i].Name < contexts[j].Name
|
||||||
ctxbuilders[i] = &nginfo{ng: &store.NodeGroup{
|
})
|
||||||
Name: l.Name,
|
for _, c := range contexts {
|
||||||
|
ngi := &nginfo{ng: &store.NodeGroup{
|
||||||
|
Name: c.Name,
|
||||||
Nodes: []store.Node{{
|
Nodes: []store.Node{{
|
||||||
Name: l.Name,
|
Name: c.Name,
|
||||||
Endpoint: l.Name,
|
Endpoint: c.Name,
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
// if a context has the same name as an instance from the store, do not
|
||||||
|
// add it to the builders list. An instance from the store takes
|
||||||
|
// precedence over context builders.
|
||||||
|
if hasNodeGroup(builders, ngi) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
builders = append(builders, ngi)
|
||||||
}
|
}
|
||||||
|
|
||||||
builders = append(builders, ctxbuilders...)
|
|
||||||
|
|
||||||
eg, _ := errgroup.WithContext(ctx)
|
eg, _ := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
|
@ -390,6 +390,15 @@ func loadNodeGroupData(ctx context.Context, dockerCli command.Cli, ngi *nginfo)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasNodeGroup(list []*nginfo, ngi *nginfo) bool {
|
||||||
|
for _, l := range list {
|
||||||
|
if ngi.ng.Name == l.ng.Name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func dockerAPI(dockerCli command.Cli) *api {
|
func dockerAPI(dockerCli command.Cli) *api {
|
||||||
return &api{dockerCli: dockerCli}
|
return &api{dockerCli: dockerCli}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user