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 <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed May 10, 2023
1 parent 9788615 commit 03d7669
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
23 changes: 13 additions & 10 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,17 +249,19 @@ func (b *Builder) MarshalJSON() ([]byte, error) {
err = 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,
Dynamic: b.Dynamic,
Nodes: b.nodes,
Err: err,
Name: b.Name,
Driver: b.Driver,
LastActivity: b.LastActivity,
Dynamic: b.Dynamic,
Nodes: b.nodes,
Err: err,
})
}

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 @@ -104,6 +109,7 @@ func lsFormatWrite(ctx formatter.Context, current *store.NodeGroup, builders []*
lsCtx.Header = formatter.SubHeaderContext{
"NameNode": lsNameNodeHeader,
"DriverEndpoint": lsDriverEndpointHeader,
"LastActivity": lsLastActivityHeader,
"Status": lsStatusHeader,
"Buildkit": lsBuildkitHeader,
"Platforms": lsPlatformsHeader,
Expand Down Expand Up @@ -156,6 +162,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 03d7669

Please sign in to comment.