Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to use a custom progress printer for the build progress output #11625

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/api/api.go
Expand Up @@ -19,6 +19,7 @@ package api
import (
"context"
"fmt"
"io"
"strings"
"time"

Expand Down Expand Up @@ -147,6 +148,8 @@ type BuildOptions struct {
Memory int64
// Builder name passed in the command line
Builder string
// OutPrinter used for printing the progress output
OutPrinter io.Writer
}

// Apply mutates project according to build options
Expand Down
35 changes: 34 additions & 1 deletion pkg/compose/build.go
Expand Up @@ -20,12 +20,14 @@ import (
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"

"github.com/moby/buildkit/util/progress/progressui"

"github.com/compose-spec/compose-go/v2/types"
"github.com/containerd/console"
"github.com/containerd/containerd/platforms"
"github.com/docker/buildx/build"
"github.com/docker/buildx/builder"
Expand Down Expand Up @@ -127,10 +129,15 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
progressCtx, cancel := context.WithCancel(context.Background())
defer cancel()

var outPrinter io.Writer = os.Stdout
if options.OutPrinter != nil {
outPrinter = options.OutPrinter
}

if options.Quiet {
options.Progress = progress.ModeQuiet
}
w, err = xprogress.NewPrinter(progressCtx, os.Stdout, progressui.DisplayMode(options.Progress),
w, err = xprogress.NewPrinter(progressCtx, progressPrinter(outPrinter), progressui.DisplayMode(options.Progress),
xprogress.WithDesc(
fmt.Sprintf("building with %q instance using %s driver", b.Name, b.Driver),
fmt.Sprintf("%s:%s", b.Driver, b.Name),
Expand Down Expand Up @@ -567,3 +574,29 @@ func parsePlatforms(service types.ServiceConfig) ([]specs.Platform, error) {

return ret, nil
}

type pPrinter struct {
io.Writer
}

func (p *pPrinter) Read(_ []byte) (n int, err error) {
return 0, errors.New("not implemented")
}

func (p *pPrinter) Close() error {
return nil
}

func (p *pPrinter) Fd() uintptr {
return 0
}

func (p *pPrinter) Name() string {
return "pPrinter"
}

func progressPrinter(w io.Writer) console.File {
return &pPrinter{
Writer: w,
}
}