diff --git a/cmd/buildctl/build.go b/cmd/buildctl/build.go index b2cd1fb1..bc811049 100644 --- a/cmd/buildctl/build.go +++ b/cmd/buildctl/build.go @@ -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,22 +169,25 @@ func build(clicontext *cli.Context) error { }) eg.Go(func() error { - if clicontext.Bool("no-progress") { - for s := range displayCh { - for _, v := range s.Vertexes { - logrus.Debugf("vertex: %s %s %v %v", v.Digest, v.Name, v.Started, v.Completed) - } - for _, s := range s.Statuses { - logrus.Debugf("status: %s %s %d", s.Vertex, s.ID, s.Current) - } - for _, l := range s.Logs { - logrus.Debugf("log: %s\n%s", l.Vertex, l.Data) - } + 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) } - return nil } - // not using shared context to not disrupt display but let is finish reporting errors - return progressui.DisplaySolveStatus(context.TODO(), 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) + } + for _, s := range s.Statuses { + logrus.Debugf("status: %s %s %d", s.Vertex, s.ID, s.Current) + } + for _, l := range s.Logs { + logrus.Debugf("log: %s\n%s", l.Vertex, l.Data) + } + } + return nil }) return eg.Wait() diff --git a/cmd/buildctl/main.go b/cmd/buildctl/main.go index 497c5ce5..1ea03800 100644 --- a/cmd/buildctl/main.go +++ b/cmd/buildctl/main.go @@ -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) } } diff --git a/util/progress/progressui/display.go b/util/progress/progressui/display.go index 2908277b..4533a87f 100644 --- a/util/progress/progressui/display.go +++ b/util/progress/progressui/display.go @@ -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()