Skip to content

Commit

Permalink
progressui: adds a json output that shows raw events for the solver s…
Browse files Browse the repository at this point in the history
…tatus

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 <jonathan.sternberg@docker.com>
  • Loading branch information
jsternberg committed Aug 22, 2023
1 parent 7f02969 commit d2f95b0
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 109 deletions.
63 changes: 32 additions & 31 deletions client/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,50 @@ import (
)

type Vertex struct {
Digest digest.Digest
Inputs []digest.Digest
Name string
Started *time.Time
Completed *time.Time
Cached bool
Error string
ProgressGroup *pb.ProgressGroup
Digest digest.Digest `json:"digest,omitempty"`
Inputs []digest.Digest `json:"inputs,omitempty"`
Name string `json:"name,omitempty"`
Started *time.Time `json:"started,omitempty"`
Completed *time.Time `json:"completed,omitempty"`
Cached bool `json:"cached,omitempty"`
Error string `json:"error,omitempty"`
ProgressGroup *pb.ProgressGroup `json:"progressGroup,omitempty"`
}

type VertexStatus struct {
ID string
Vertex digest.Digest
Name string
Total int64
Current int64
Timestamp time.Time
Started *time.Time
Completed *time.Time
ID string `json:"id"`
Vertex digest.Digest `json:"vertex,omitempty"`
Name string `json:"name,omitempty"`
Total int64 `json:"total,omitempty"`
Current int64 `json:"current"`
Timestamp time.Time `json:"timestamp,omitempty"`
Started *time.Time `json:"started,omitempty"`
Completed *time.Time `json:"completed,omitempty"`
}

type VertexLog struct {
Vertex digest.Digest
Stream int
Data []byte
Timestamp time.Time
Vertex digest.Digest `json:"vertex,omitempty"`
Stream int `json:"stream,omitempty"`
Data []byte `json:"data"`
Timestamp time.Time `json:"timestamp"`
}

type VertexWarning struct {
Vertex digest.Digest
Level int
Short []byte
Detail [][]byte
URL string
SourceInfo *pb.SourceInfo
Range []*pb.Range
Vertex digest.Digest `json:"vertex,omitempty"`
Level int `json:"level,omitempty"`
Short []byte `json:"short,omitempty"`
Detail [][]byte `json:"detail,omitempty"`
URL string `json:"url,omitempty"`

SourceInfo *pb.SourceInfo `json:"sourceInfo,omitempty"`
Range []*pb.Range `json:"range,omitempty"`
}

type SolveStatus struct {
Vertexes []*Vertex
Statuses []*VertexStatus
Logs []*VertexLog
Warnings []*VertexWarning
Vertexes []*Vertex `json:"vertexes,omitempty"`
Statuses []*VertexStatus `json:"statuses,omitempty"`
Logs []*VertexLog `json:"logs,omitempty"`
Warnings []*VertexWarning `json:"warnings,omitempty"`
}

type SolveResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/buildctl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var buildCommand = cli.Command{
},
cli.StringFlag{
Name: "progress",
Usage: "Set type of progress (auto, plain, tty). Use plain to show container output",
Usage: "Set type of progress (auto, plain, tty, raw:json). Use plain to show container output",
Value: "auto",
},
cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/buildctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ USAGE:
OPTIONS:
--output value, -o value Define exports for build result, e.g. --output type=image,name=docker.io/username/image,push=true
--progress value Set type of progress (auto, plain, tty). Use plain to show container output (default: "auto")
--progress value Set type of progress (auto, plain, tty, raw:json). Use plain to show container output (default: "auto")
--trace value Path to trace file. Defaults to no tracing.
--local value Allow build access to the local directory
--oci-layout value Allow build access to the local OCI layout
Expand Down
10 changes: 6 additions & 4 deletions examples/build-using-dockerfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ func action(clicontext *cli.Context) error {
return err
})
eg.Go(func() error {
var c console.Console
if cn, err := console.ConsoleFromFile(os.Stderr); err == nil {
c = cn
var d progressui.SolveStatusDisplay
if c, err := console.ConsoleFromFile(os.Stderr); err == nil {
d = progressui.NewConsoleDisplay(c)
} else {
d = progressui.NewPlainDisplay(os.Stdout)
}
// not using shared context to not disrupt display but let is finish reporting errors
_, err = progressui.DisplaySolveStatus(context.TODO(), c, os.Stdout, ch)
_, err = d.UpdateFrom(context.TODO(), ch)
return err
})
eg.Go(func() error {
Expand Down
Loading

0 comments on commit d2f95b0

Please sign in to comment.