mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
ls: format opt
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@ -2,9 +2,12 @@ package builder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/buildx/driver"
|
||||
"github.com/docker/buildx/store"
|
||||
@ -247,6 +250,28 @@ func (b *Builder) Factory(ctx context.Context, dialMeta map[string][]string) (_
|
||||
return b.driverFactory.Factory, err
|
||||
}
|
||||
|
||||
func (b *Builder) MarshalJSON() ([]byte, error) {
|
||||
var berr string
|
||||
if b.err != nil {
|
||||
berr = strings.TrimSpace(b.err.Error())
|
||||
}
|
||||
return json.Marshal(struct {
|
||||
Name string
|
||||
Driver string
|
||||
LastActivity time.Time `json:",omitempty"`
|
||||
Dynamic bool
|
||||
Nodes []Node
|
||||
Err string `json:",omitempty"`
|
||||
}{
|
||||
Name: b.Name,
|
||||
Driver: b.Driver,
|
||||
LastActivity: b.LastActivity,
|
||||
Dynamic: b.Dynamic,
|
||||
Nodes: b.nodes,
|
||||
Err: berr,
|
||||
})
|
||||
}
|
||||
|
||||
// GetBuilders returns all builders
|
||||
func GetBuilders(dockerCli command.Cli, txn *store.Txn) ([]*Builder, error) {
|
||||
storeng, err := txn.List()
|
||||
|
@ -2,8 +2,11 @@ package builder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/docker/buildx/driver"
|
||||
ctxkube "github.com/docker/buildx/driver/kubernetes/context"
|
||||
"github.com/docker/buildx/store"
|
||||
@ -199,6 +202,51 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
|
||||
return b.nodes, nil
|
||||
}
|
||||
|
||||
func (n *Node) MarshalJSON() ([]byte, error) {
|
||||
var status string
|
||||
if n.DriverInfo != nil {
|
||||
status = n.DriverInfo.Status.String()
|
||||
}
|
||||
var nerr string
|
||||
if n.Err != nil {
|
||||
status = "error"
|
||||
nerr = strings.TrimSpace(n.Err.Error())
|
||||
}
|
||||
var pp []string
|
||||
for _, p := range n.Platforms {
|
||||
pp = append(pp, platforms.Format(p))
|
||||
}
|
||||
return json.Marshal(struct {
|
||||
Name string
|
||||
Endpoint string
|
||||
Flags []string `json:",omitempty"`
|
||||
DriverOpts map[string]string `json:",omitempty"`
|
||||
Files map[string][]byte `json:",omitempty"`
|
||||
Status string `json:",omitempty"`
|
||||
ProxyConfig map[string]string `json:",omitempty"`
|
||||
Version string `json:",omitempty"`
|
||||
Err string `json:",omitempty"`
|
||||
IDs []string `json:",omitempty"`
|
||||
Platforms []string `json:",omitempty"`
|
||||
GCPolicy []client.PruneInfo `json:",omitempty"`
|
||||
Labels map[string]string `json:",omitempty"`
|
||||
}{
|
||||
Name: n.Name,
|
||||
Endpoint: n.Endpoint,
|
||||
Flags: n.Flags,
|
||||
DriverOpts: n.DriverOpts,
|
||||
Files: n.Files,
|
||||
Status: status,
|
||||
ProxyConfig: n.ProxyConfig,
|
||||
Version: n.Version,
|
||||
Err: nerr,
|
||||
IDs: n.IDs,
|
||||
Platforms: pp,
|
||||
GCPolicy: n.GCPolicy,
|
||||
Labels: n.Labels,
|
||||
})
|
||||
}
|
||||
|
||||
func (n *Node) loadData(ctx context.Context) error {
|
||||
if n.Driver == nil {
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user