Merge pull request #186 from tonistiigi/console-detect

buildctl: disable progressbar if no console
docker-18.09
Akihiro Suda 2017-12-02 17:28:00 +09:00 committed by GitHub
commit 1c345d7228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 21 deletions

View File

@ -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()

View File

@ -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)
}
}

View File

@ -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()