buildctl: disable progressbar if no console
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-18.09
parent
9653c6079c
commit
ec389edb64
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/moby/buildkit/client"
|
||||
"github.com/moby/buildkit/client/llb"
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
|
@ -168,7 +169,13 @@ func build(clicontext *cli.Context) error {
|
|||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
if clicontext.Bool("no-progress") {
|
||||
if !clicontext.Bool("no-progress") {
|
||||
if c, err := console.ConsoleFromFile(os.Stdout); err == nil {
|
||||
// not using shared context to not disrupt display but let is finish reporting errors
|
||||
return progressui.DisplaySolveStatus(context.TODO(), c, displayCh)
|
||||
}
|
||||
}
|
||||
|
||||
for s := range displayCh {
|
||||
for _, v := range s.Vertexes {
|
||||
logrus.Debugf("vertex: %s %s %v %v", v.Digest, v.Name, v.Started, v.Completed)
|
||||
|
@ -181,9 +188,6 @@ func build(clicontext *cli.Context) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// not using shared context to not disrupt display but let is finish reporting errors
|
||||
return progressui.DisplaySolveStatus(context.TODO(), displayCh)
|
||||
})
|
||||
|
||||
return eg.Wait()
|
||||
|
|
|
@ -39,8 +39,11 @@ func main() {
|
|||
debugCommand,
|
||||
}
|
||||
|
||||
var debugEnabled bool
|
||||
|
||||
app.Before = func(context *cli.Context) error {
|
||||
if context.GlobalBool("debug") {
|
||||
debugEnabled = context.GlobalBool("debug")
|
||||
if debugEnabled {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
return nil
|
||||
|
@ -49,7 +52,11 @@ func main() {
|
|||
profiler.Attach(app)
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "buildd: %s\n", err)
|
||||
if debugEnabled {
|
||||
fmt.Fprintf(os.Stderr, "error: %+v\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,7 @@ import (
|
|||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
func DisplaySolveStatus(ctx context.Context, ch chan *client.SolveStatus) error {
|
||||
c, err := console.ConsoleFromFile(os.Stdout)
|
||||
if err != nil {
|
||||
return err // TODO: switch to log mode
|
||||
}
|
||||
func DisplaySolveStatus(ctx context.Context, c console.Console, ch chan *client.SolveStatus) error {
|
||||
disp := &display{c: c}
|
||||
|
||||
t := newTrace()
|
||||
|
|
Loading…
Reference in New Issue