mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
debug: display build warnings after each build
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/docker/buildx/util/tracing"
|
"github.com/docker/buildx/util/tracing"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/moby/buildkit/util/appcontext"
|
"github.com/moby/buildkit/util/appcontext"
|
||||||
"github.com/moby/buildkit/util/progress/progressui"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -118,7 +117,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
|
|||||||
}
|
}
|
||||||
|
|
||||||
printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, cFlags.progress,
|
printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, cFlags.progress,
|
||||||
progressui.WithDesc(progressTextDesc, progressConsoleDesc),
|
progress.WithDesc(progressTextDesc, progressConsoleDesc),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -40,7 +40,6 @@ import (
|
|||||||
"github.com/moby/buildkit/solver/errdefs"
|
"github.com/moby/buildkit/solver/errdefs"
|
||||||
"github.com/moby/buildkit/util/appcontext"
|
"github.com/moby/buildkit/util/appcontext"
|
||||||
"github.com/moby/buildkit/util/grpcerrors"
|
"github.com/moby/buildkit/util/grpcerrors"
|
||||||
"github.com/moby/buildkit/util/progress/progressui"
|
|
||||||
"github.com/morikuni/aec"
|
"github.com/morikuni/aec"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -225,10 +224,16 @@ func runBuild(dockerCli command.Cli, options buildOptions) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, progressMode, progressui.WithDesc(
|
var printer *progress.Printer
|
||||||
fmt.Sprintf("building with %q instance using %s driver", b.Name, b.Driver),
|
printer, err = progress.NewPrinter(ctx2, os.Stderr, os.Stderr, progressMode,
|
||||||
fmt.Sprintf("%s:%s", b.Driver, b.Name),
|
progress.WithDesc(
|
||||||
))
|
fmt.Sprintf("building with %q instance using %s driver", b.Name, b.Driver),
|
||||||
|
fmt.Sprintf("%s:%s", b.Driver, b.Name),
|
||||||
|
),
|
||||||
|
progress.WithOnClose(func() {
|
||||||
|
printWarnings(os.Stderr, printer.Warnings(), progressMode)
|
||||||
|
}),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -244,7 +249,6 @@ func runBuild(dockerCli command.Cli, options buildOptions) (err error) {
|
|||||||
if err := printer.Wait(); retErr == nil {
|
if err := printer.Wait(); retErr == nil {
|
||||||
retErr = err
|
retErr = err
|
||||||
}
|
}
|
||||||
printWarnings(os.Stderr, printer.Warnings(), progressMode)
|
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
return retErr
|
return retErr
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,12 @@ func (p *Printer) ClearLogSource(v interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string, solveStatusOpt ...progressui.DisplaySolveStatusOpt) (*Printer, error) {
|
func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string, opts ...PrinterOpt) (*Printer, error) {
|
||||||
|
opt := &printerOpts{}
|
||||||
|
for _, o := range opts {
|
||||||
|
o(opt)
|
||||||
|
}
|
||||||
|
|
||||||
if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == PrinterModeAuto {
|
if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == PrinterModeAuto {
|
||||||
mode = v
|
mode = v
|
||||||
}
|
}
|
||||||
@ -119,10 +124,13 @@ func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string,
|
|||||||
|
|
||||||
resumeLogs := logutil.Pause(logrus.StandardLogger())
|
resumeLogs := logutil.Pause(logrus.StandardLogger())
|
||||||
// not using shared context to not disrupt display but let is finish reporting errors
|
// not using shared context to not disrupt display but let is finish reporting errors
|
||||||
pw.warnings, pw.err = progressui.DisplaySolveStatus(ctx, c, w, pw.status, solveStatusOpt...)
|
pw.warnings, pw.err = progressui.DisplaySolveStatus(ctx, c, w, pw.status, opt.displayOpts...)
|
||||||
resumeLogs()
|
resumeLogs()
|
||||||
close(pw.done)
|
close(pw.done)
|
||||||
|
|
||||||
|
if opt.onclose != nil {
|
||||||
|
opt.onclose()
|
||||||
|
}
|
||||||
if pw.paused == nil {
|
if pw.paused == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -135,3 +143,29 @@ func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string,
|
|||||||
<-pw.ready
|
<-pw.ready
|
||||||
return pw, nil
|
return pw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type printerOpts struct {
|
||||||
|
displayOpts []progressui.DisplaySolveStatusOpt
|
||||||
|
|
||||||
|
onclose func()
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrinterOpt func(b *printerOpts)
|
||||||
|
|
||||||
|
func WithPhase(phase string) PrinterOpt {
|
||||||
|
return func(opt *printerOpts) {
|
||||||
|
opt.displayOpts = append(opt.displayOpts, progressui.WithPhase(phase))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDesc(text string, console string) PrinterOpt {
|
||||||
|
return func(opt *printerOpts) {
|
||||||
|
opt.displayOpts = append(opt.displayOpts, progressui.WithDesc(text, console))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithOnClose(onclose func()) PrinterOpt {
|
||||||
|
return func(opt *printerOpts) {
|
||||||
|
opt.onclose = onclose
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user