build: add experimental --no-console flag to support non-tty human-readable output with buildkit

Unfortunately, this is for now the only way to see the output of RUN commands when using buildkit.
It is equivalent to `DOCKER_BUILDKIT=1 docker build . 2>&1 | cat`

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass
2018-06-09 01:07:42 +00:00
parent 584d59d8f5
commit ed75f6202b
22 changed files with 667 additions and 118 deletions

View File

@ -57,6 +57,7 @@ type buildOptions struct {
isolation string
quiet bool
noCache bool
noConsole bool
rm bool
forceRm bool
pull bool
@ -151,6 +152,9 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation("stream", "experimental", nil)
flags.SetAnnotation("stream", "version", []string{"1.31"})
flags.BoolVar(&options.noConsole, "no-console", false, "Show non-console output (with buildkit only)")
flags.SetAnnotation("no-console", "experimental", nil)
flags.SetAnnotation("no-console", "version", []string{"1.38"})
return cmd
}

View File

@ -212,23 +212,15 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
ssArr := []*client.SolveStatus{}
displayStatus := func(displayCh chan *client.SolveStatus) {
if c, err := console.ConsoleFromFile(os.Stderr); err == nil {
// not using shared context to not disrupt display but let is finish reporting errors
eg.Go(func() error {
return progressui.DisplaySolveStatus(context.TODO(), c, displayCh)
})
} else {
// read from t.displayCh and send json to Stderr
eg.Go(func() error {
enc := json.NewEncoder(os.Stderr)
for ss := range displayCh {
if err := enc.Encode(ss); err != nil {
return err
}
}
return nil
})
var c console.Console
out := os.Stderr
if cons, err := console.ConsoleFromFile(out); err == nil && !options.noConsole {
c = cons
}
// not using shared context to not disrupt display but let is finish reporting errors
eg.Go(func() error {
return progressui.DisplaySolveStatus(context.TODO(), c, out, displayCh)
})
}
if options.quiet {