Skip to content

Commit 3713178

Browse files
committed
progressui: adds a json output that shows raw events for the solver status
This adds an additional display output for the progress indicator to support a json output. It refators the progressui package a bit to add a new method that takes in a `SolveStatusDisplay`. This `SolveStatusDisplay` can be created by the user using `NewDisplay` with the various modes as input parameters. The json output will print the raw events as JSON blobs. It will not throttle the messages or limit the display. It is meant as a pure raw marshaling of the underlying event stream. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent fdacdb7 commit 3713178

File tree

6 files changed

+268
-119
lines changed

6 files changed

+268
-119
lines changed

client/graph.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,50 @@ import (
88
)
99

1010
type Vertex struct {
11-
Digest digest.Digest
12-
Inputs []digest.Digest
13-
Name string
14-
Started *time.Time
15-
Completed *time.Time
16-
Cached bool
17-
Error string
18-
ProgressGroup *pb.ProgressGroup
11+
Digest digest.Digest `json:"digest,omitempty"`
12+
Inputs []digest.Digest `json:"inputs,omitempty"`
13+
Name string `json:"name,omitempty"`
14+
Started *time.Time `json:"started,omitempty"`
15+
Completed *time.Time `json:"completed,omitempty"`
16+
Cached bool `json:"cached,omitempty"`
17+
Error string `json:"error,omitempty"`
18+
ProgressGroup *pb.ProgressGroup `json:"progressGroup,omitempty"`
1919
}
2020

2121
type VertexStatus struct {
22-
ID string
23-
Vertex digest.Digest
24-
Name string
25-
Total int64
26-
Current int64
27-
Timestamp time.Time
28-
Started *time.Time
29-
Completed *time.Time
22+
ID string `json:"id"`
23+
Vertex digest.Digest `json:"vertex,omitempty"`
24+
Name string `json:"name,omitempty"`
25+
Total int64 `json:"total,omitempty"`
26+
Current int64 `json:"current"`
27+
Timestamp time.Time `json:"timestamp,omitempty"`
28+
Started *time.Time `json:"started,omitempty"`
29+
Completed *time.Time `json:"completed,omitempty"`
3030
}
3131

3232
type VertexLog struct {
33-
Vertex digest.Digest
34-
Stream int
35-
Data []byte
36-
Timestamp time.Time
33+
Vertex digest.Digest `json:"vertex,omitempty"`
34+
Stream int `json:"stream,omitempty"`
35+
Data []byte `json:"data"`
36+
Timestamp time.Time `json:"timestamp"`
3737
}
3838

3939
type VertexWarning struct {
40-
Vertex digest.Digest
41-
Level int
42-
Short []byte
43-
Detail [][]byte
44-
URL string
45-
SourceInfo *pb.SourceInfo
46-
Range []*pb.Range
40+
Vertex digest.Digest `json:"vertex,omitempty"`
41+
Level int `json:"level,omitempty"`
42+
Short []byte `json:"short,omitempty"`
43+
Detail [][]byte `json:"detail,omitempty"`
44+
URL string `json:"url,omitempty"`
45+
46+
SourceInfo *pb.SourceInfo `json:"sourceInfo,omitempty"`
47+
Range []*pb.Range `json:"range,omitempty"`
4748
}
4849

4950
type SolveStatus struct {
50-
Vertexes []*Vertex
51-
Statuses []*VertexStatus
52-
Logs []*VertexLog
53-
Warnings []*VertexWarning
51+
Vertexes []*Vertex `json:"vertexes,omitempty"`
52+
Statuses []*VertexStatus `json:"statuses,omitempty"`
53+
Logs []*VertexLog `json:"logs,omitempty"`
54+
Warnings []*VertexWarning `json:"warnings,omitempty"`
5455
}
5556

5657
type SolveResponse struct {

cmd/buildctl/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var buildCommand = cli.Command{
4646
},
4747
cli.StringFlag{
4848
Name: "progress",
49-
Usage: "Set type of progress (auto, plain, tty). Use plain to show container output",
49+
Usage: "Set type of progress (auto, plain, tty, rawjson). Use plain to show container output",
5050
Value: "auto",
5151
},
5252
cli.StringFlag{

docs/reference/buildctl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ USAGE:
6363
6464
OPTIONS:
6565
--output value, -o value Define exports for build result, e.g. --output type=image,name=docker.io/username/image,push=true
66-
--progress value Set type of progress (auto, plain, tty). Use plain to show container output (default: "auto")
66+
--progress value Set type of progress (auto, plain, tty, rawjson). Use plain to show container output (default: "auto")
6767
--trace value Path to trace file. Defaults to no tracing.
6868
--local value Allow build access to the local directory
6969
--oci-layout value Allow build access to the local OCI layout

examples/build-using-dockerfile/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"github.com/containerd/console"
1312
"github.com/moby/buildkit/client"
1413
dockerfile "github.com/moby/buildkit/frontend/dockerfile/builder"
1514
"github.com/moby/buildkit/util/appcontext"
@@ -102,12 +101,14 @@ func action(clicontext *cli.Context) error {
102101
return err
103102
})
104103
eg.Go(func() error {
105-
var c console.Console
106-
if cn, err := console.ConsoleFromFile(os.Stderr); err == nil {
107-
c = cn
104+
d, err := progressui.NewDisplay(os.Stderr, progressui.TtyMode)
105+
if err != nil {
106+
// If an error occurs while attempting to create the tty display,
107+
// fallback to using plain mode on stdout (in contrast to stderr).
108+
d, _ = progressui.NewDisplay(os.Stdout, progressui.PlainMode)
108109
}
109110
// not using shared context to not disrupt display but let is finish reporting errors
110-
_, err = progressui.DisplaySolveStatus(context.TODO(), c, os.Stdout, ch)
111+
_, err = d.UpdateFrom(context.TODO(), ch)
111112
return err
112113
})
113114
eg.Go(func() error {

0 commit comments

Comments
 (0)