Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quiet mode to progress printer #558

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions util/progress/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ package progress

import (
"context"
"io"
"io/ioutil"
"os"

"github.com/containerd/console"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/util/progress/progressui"
)

const (
PrinterModeAuto = "auto"
PrinterModeTty = "tty"
PrinterModePlain = "plain"
PrinterModeQuiet = "quiet"
ulyssessouza marked this conversation as resolved.
Show resolved Hide resolved
)

type Printer struct {
status chan *client.SolveStatus
done <-chan struct{}
Expand All @@ -34,17 +43,23 @@ func NewPrinter(ctx context.Context, out console.File, mode string) *Printer {
done: doneCh,
}

if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == "auto" {
if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == PrinterModeAuto {
mode = v
}

go func() {
var c console.Console
if cons, err := console.ConsoleFromFile(out); err == nil && (mode == "auto" || mode == "tty") {
c = cons
var w io.Writer = out
switch mode {
case PrinterModeQuiet:
w = ioutil.Discard
case PrinterModeAuto, PrinterModeTty:
if cons, err := console.ConsoleFromFile(out); err == nil {
c = cons
}
}
// not using shared context to not disrupt display but let is finish reporting errors
pw.err = progressui.DisplaySolveStatus(ctx, "", c, out, statusCh)
pw.err = progressui.DisplaySolveStatus(ctx, "", c, w, statusCh)
close(doneCh)
}()
return pw
Expand Down