diff --git a/build/build.go b/build/build.go index 35e60ae2..b80b40cc 100644 --- a/build/build.go +++ b/build/build.go @@ -149,7 +149,7 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, pw opt.Exports[i].Type = "moby" if e.Attrs["push"] != "" { if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok { - return nil, errors.Errorf("auto-push is currently not implemented for moby driver") + return nil, errors.Errorf("auto-push is currently not implemented for docker driver") } } } diff --git a/commands/ls.go b/commands/ls.go index 525ffdf5..c15c9d39 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -1,48 +1,140 @@ package commands import ( + "context" "fmt" + "io" + "os" + "strings" + "text/tabwriter" + "time" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" + "github.com/moby/buildkit/util/appcontext" "github.com/spf13/cobra" + "github.com/tonistiigi/buildx/store" + "golang.org/x/sync/errgroup" ) type lsOptions struct { } func runLs(dockerCli command.Cli, in lsOptions) error { - ep, err := getCurrentEndpoint(dockerCli) - fmt.Printf("current endpoint: %+v %v\n", ep, err) + ctx := appcontext.Context() - fmt.Printf("current config file: %+v\n", dockerCli.ConfigFile()) - fmt.Printf("current config file: %+v\n", dockerCli) + txn, release, err := getStore(dockerCli) + if err != nil { + return err + } + defer release() + + ctx, cancel := context.WithTimeout(ctx, 7*time.Second) + defer cancel() + + ll, err := txn.List() + if err != nil { + return err + } + + builders := make([]*nginfo, len(ll)) + for i, ng := range ll { + builders[i] = &nginfo{ng: ng} + } list, err := dockerCli.ContextStore().ListContexts() if err != nil { return err } + ctxbuilders := make([]*nginfo, len(list)) for i, l := range list { - fmt.Printf("context%d: %+v\n", i, l) + ctxbuilders[i] = &nginfo{ng: &store.NodeGroup{ + Name: l.Name, + Nodes: []store.Node{{ + Name: l.Name, + Endpoint: l.Name, + }}, + }} } - txn, release, err := getStore(dockerCli) - if err != nil { + builders = append(builders, ctxbuilders...) + + eg, _ := errgroup.WithContext(ctx) + + for _, b := range builders { + func(b *nginfo) { + eg.Go(func() error { + err = loadNodeGroupData(ctx, dockerCli, b) + if b.err == nil && err != nil { + b.err = err + } + return nil + }) + }(b) + } + + if err := eg.Wait(); err != nil { return err } - defer release() - ll, err := txn.List() + currentName := "default" + current, err := getCurrentInstance(txn, dockerCli) if err != nil { return err } - for i, l := range ll { - fmt.Printf("store %d: %+v\n", i, l) + if current != nil { + currentName = current.Name + if current.Name == "default" { + currentName = current.Nodes[0].Endpoint + } + } + + w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) + fmt.Fprintf(w, "NAME\tDRIVER/ENDPOINT\tSTATUS\tPLATFORMS\n") + + currentSet := false + for _, b := range builders { + if !currentSet && b.ng.Name == currentName { + b.ng.Name += " *" + currentSet = true + } + printngi(w, b) } + w.Flush() + return nil } +func printngi(w io.Writer, ngi *nginfo) { + var err string + if ngi.err != nil { + err = ngi.err.Error() + } + fmt.Fprintf(w, "%s\t%s\t%s\t\n", ngi.ng.Name, ngi.ng.Driver, err) + if ngi.err == nil { + for idx, n := range ngi.ng.Nodes { + d := ngi.drivers[idx] + var err string + if d.err != nil { + err = d.err.Error() + } else if d.di.Err != nil { + err = d.di.Err.Error() + } + var status string + if d.info != nil { + status = d.info.Status.String() + } + p := append(n.Platforms, d.platforms...) + if err != "" { + fmt.Fprintf(w, " %s\t%s\t%s\n", n.Name, n.Endpoint, err) + } else { + fmt.Fprintf(w, " %s\t%s\t%s\t%s\n", n.Name, n.Endpoint, status, strings.Join(p, ", ")) + } + } + } +} + func lsCmd(dockerCli command.Cli) *cobra.Command { var options lsOptions @@ -55,11 +147,5 @@ func lsCmd(dockerCli command.Cli) *cobra.Command { }, } - flags := cmd.Flags() - - // flags.StringArrayVarP(&options.outputs, "output", "o", []string{}, "Output destination (format: type=local,dest=path)") - - _ = flags - return cmd } diff --git a/commands/util.go b/commands/util.go index 324407cb..41bd3d87 100644 --- a/commands/util.go +++ b/commands/util.go @@ -88,6 +88,10 @@ func getCurrentInstance(txn *store.Txn, dockerCli command.Cli) (*store.NodeGroup if err != nil { return nil, err } + if ng == nil { + ng, _ = getNodeGroup(txn, dockerCli, dockerCli.CurrentContext()) + } + return ng, nil } diff --git a/go.mod b/go.mod index ff5d1149..dea01013 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( github.com/prometheus/client_model v0.0.0-20170216185247-6f3806018612 // indirect github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 // indirect github.com/prometheus/procfs v0.0.0-20180612222113-7d6f385de8be // indirect - github.com/sirupsen/logrus v1.4.0 // indirect + github.com/sirupsen/logrus v1.4.0 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 github.com/spf13/viper v1.3.2 // indirect diff --git a/store/nodegroup.go b/store/nodegroup.go index a040ffa6..56a489b2 100644 --- a/store/nodegroup.go +++ b/store/nodegroup.go @@ -100,7 +100,7 @@ func (ng *NodeGroup) nextNodeName() string { i := 0 for { name := fmt.Sprintf("%s%d", ng.Name, i) - if i := ng.findNode(name); i != -1 { + if ii := ng.findNode(name); ii != -1 { i++ continue } diff --git a/vendor/modules.txt b/vendor/modules.txt index e39546d8..27fdb729 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -103,16 +103,16 @@ github.com/docker/cli/cli-plugins/plugin github.com/docker/cli/cli/command github.com/docker/cli/cli/flags github.com/docker/cli/cli +github.com/docker/cli/cli/context/docker +github.com/docker/cli/opts github.com/docker/cli/cli/compose/interpolation github.com/docker/cli/cli/compose/schema github.com/docker/cli/cli/compose/template -github.com/docker/cli/opts github.com/docker/cli/cli/config github.com/docker/cli/cli/config/configfile github.com/docker/cli/cli/connhelper github.com/docker/cli/cli/config/types github.com/docker/cli/cli/context -github.com/docker/cli/cli/context/docker github.com/docker/cli/cli/context/kubernetes github.com/docker/cli/cli/context/store github.com/docker/cli/cli/debug @@ -169,13 +169,13 @@ github.com/docker/docker/pkg/homedir github.com/docker/docker/pkg/system github.com/docker/docker/pkg/term github.com/docker/docker/registry +github.com/docker/docker/api/types/blkiodev +github.com/docker/docker/api/types/swarm github.com/docker/docker/api github.com/docker/docker/api/types/image -github.com/docker/docker/api/types/swarm github.com/docker/docker/api/types/time github.com/docker/docker/api/types/volume github.com/docker/docker/errdefs -github.com/docker/docker/api/types/blkiodev github.com/docker/docker/api/types/strslice github.com/docker/docker/pkg/jsonmessage github.com/docker/docker/pkg/idtools