From 598f1f0a621692bd4e0b78d5faac998ede43868b Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 10 Feb 2023 19:37:54 +0100 Subject: [PATCH] build: print instance being used Signed-off-by: CrazyMax --- commands/bake.go | 33 ++++++++++++++++++++------------- controller/build/build.go | 10 +++++++--- util/progress/printer.go | 4 ++-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/commands/bake.go b/commands/bake.go index 5ad2b995..23ac82ed 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -18,6 +18,7 @@ import ( "github.com/docker/buildx/util/tracing" "github.com/docker/cli/cli/command" "github.com/moby/buildkit/util/appcontext" + "github.com/moby/buildkit/util/progress/progressui" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -85,23 +86,11 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com ctx2, cancel := context.WithCancel(context.TODO()) defer cancel() - printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, cFlags.progress) - if err != nil { - return err - } - - defer func() { - if printer != nil { - err1 := printer.Wait() - if err == nil { - err = err1 - } - } - }() var nodes []builder.Node var files []bake.File var inp *bake.Input + var progressConsoleDesc, progressTextDesc string // instance only needed for reading remote bake files or building if url != "" || !in.printOnly { @@ -119,8 +108,26 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com if err != nil { return err } + progressConsoleDesc = fmt.Sprintf("%s:%s", b.Driver, b.Name) + progressTextDesc = fmt.Sprintf("building with %q instance using %s driver", b.Name, b.Driver) } + printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, cFlags.progress, + progressui.WithDesc(progressTextDesc, progressConsoleDesc), + ) + if err != nil { + return err + } + + defer func() { + if printer != nil { + err1 := printer.Wait() + if err == nil { + err = err1 + } + } + }() + if url != "" { files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer) } else { diff --git a/controller/build/build.go b/controller/build/build.go index 88cc8257..f9c659cc 100644 --- a/controller/build/build.go +++ b/controller/build/build.go @@ -33,6 +33,7 @@ import ( "github.com/moby/buildkit/session/auth/authprovider" "github.com/moby/buildkit/solver/errdefs" "github.com/moby/buildkit/util/grpcerrors" + "github.com/moby/buildkit/util/progress/progressui" "github.com/morikuni/aec" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -200,7 +201,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build return nil, err } - imageID, res, err := buildTargets(ctx, dockerCli, nodes, map[string]build.Options{defaultTargetName: opts}, progressMode, in.Opts.MetadataFile, statusChan) + imageID, res, err := buildTargets(ctx, dockerCli, b.NodeGroup, nodes, map[string]build.Options{defaultTargetName: opts}, progressMode, in.Opts.MetadataFile, statusChan) err = wrapBuildError(err, false) if err != nil { return nil, err @@ -212,11 +213,14 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build return res, nil } -func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.Node, opts map[string]build.Options, progressMode string, metadataFile string, statusChan chan *client.SolveStatus) (imageID string, res *build.ResultContext, err error) { +func buildTargets(ctx context.Context, dockerCli command.Cli, ng *store.NodeGroup, nodes []builder.Node, opts map[string]build.Options, progressMode string, metadataFile string, statusChan chan *client.SolveStatus) (imageID string, res *build.ResultContext, err error) { ctx2, cancel := context.WithCancel(context.TODO()) defer cancel() - printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, progressMode) + printer, err := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, progressMode, progressui.WithDesc( + fmt.Sprintf("building with %q instance using %s driver", ng.Name, ng.Driver), + fmt.Sprintf("%s:%s", ng.Driver, ng.Name), + )) if err != nil { return "", nil, err } diff --git a/util/progress/printer.go b/util/progress/printer.go index 1247a7aa..14adfca8 100644 --- a/util/progress/printer.go +++ b/util/progress/printer.go @@ -70,7 +70,7 @@ func (p *Printer) ClearLogSource(v interface{}) { } } -func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string) (*Printer, error) { +func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string, solveStatusOpt ...progressui.DisplaySolveStatusOpt) (*Printer, error) { statusCh := make(chan *client.SolveStatus) doneCh := make(chan struct{}) @@ -101,7 +101,7 @@ func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string) go func() { resumeLogs := logutil.Pause(logrus.StandardLogger()) // not using shared context to not disrupt display but let is finish reporting errors - pw.warnings, pw.err = progressui.DisplaySolveStatus(ctx, "", c, w, statusCh) + pw.warnings, pw.err = progressui.DisplaySolveStatus(ctx, c, w, statusCh, solveStatusOpt...) resumeLogs() close(doneCh) }()