Skip to content

Commit

Permalink
ls: last activity template field
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed May 10, 2023
1 parent 20c0a66 commit d98eaca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 8 additions & 5 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"strings"
"sync"
"time"

"github.com/docker/buildx/driver"
"github.com/docker/buildx/store"
Expand Down Expand Up @@ -248,14 +249,16 @@ func (b *Builder) MarshalJSON() ([]byte, error) {
berr = strings.TrimSpace(b.err.Error())
}
return json.Marshal(struct {
Name string
Driver string
Dynamic bool
Nodes []Node
Err string `json:",omitempty"`
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,
Expand Down
13 changes: 13 additions & 0 deletions commands/ls_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"encoding/json"
"strings"
"time"

"github.com/docker/buildx/builder"
"github.com/docker/buildx/store"
Expand All @@ -15,6 +16,7 @@ const (
lsNameNodeHeader = "NAME/NODE"
lsDriverEndpointHeader = "DRIVER/ENDPOINT"
lsStatusHeader = "STATUS"
lsLastActivityHeader = "LAST ACTIVITY"
lsBuildkitHeader = "BUILDKIT"
lsPlatformsHeader = "PLATFORMS"

Expand All @@ -26,6 +28,9 @@ name: {{.NameNode}}
{{- if .DriverEndpoint }}
driver: {{.DriverEndpoint}}
{{- end }}
{{- if .LastActivity }}
last_activity: {{.LastActivity}}
{{- end }}
{{- if .Error }}
error: {{.Error}}
{{- else }}
Expand Down Expand Up @@ -98,6 +103,7 @@ func lsPrint(dockerCli command.Cli, current *store.NodeGroup, builders []*builde
lsCtx.Header = formatter.SubHeaderContext{
"NameNode": lsNameNodeHeader,
"DriverEndpoint": lsDriverEndpointHeader,
"LastActivity": lsLastActivityHeader,
"Status": lsStatusHeader,
"Buildkit": lsBuildkitHeader,
"Platforms": lsPlatformsHeader,
Expand Down Expand Up @@ -153,6 +159,13 @@ func (c *lsContext) DriverEndpoint() string {
return c.node.Endpoint
}

func (c *lsContext) LastActivity() string {
if c.IsNode() || c.builder.LastActivity.IsZero() {
return ""
}
return c.builder.LastActivity.UTC().Format(time.RFC3339)
}

func (c *lsContext) Status() string {
if !c.IsNode() {
if c.builder.Err() != nil {
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Valid placeholders for the Go template are listed below:
|-------------------|---------------------------------------------|
| `.NameNode` | Name of the builder or node |
| `.DriverEndpoint` | Driver (for builder) or Endpoint (for node) |
| `.LastActivity` | Builder last activity |
| `.Status` | Builder or node status |
| `.Buildkit` | BuildKit version of the node |
| `.Platforms` | Available node's platforms |
Expand Down

0 comments on commit d98eaca

Please sign in to comment.