mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-20 10:27:46 +08:00
progress: avoid double logs when multiple targets build same step
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
6efcee28d5
commit
b77d7864fa
@ -8,14 +8,14 @@ import (
|
|||||||
|
|
||||||
func WithPrefix(w Writer, pfx string, force bool) Writer {
|
func WithPrefix(w Writer, pfx string, force bool) Writer {
|
||||||
return &prefixed{
|
return &prefixed{
|
||||||
main: w,
|
Writer: w,
|
||||||
pfx: pfx,
|
pfx: pfx,
|
||||||
force: force,
|
force: force,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type prefixed struct {
|
type prefixed struct {
|
||||||
main Writer
|
Writer
|
||||||
pfx string
|
pfx string
|
||||||
force bool
|
force bool
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ func (p *prefixed) Write(v *client.SolveStatus) {
|
|||||||
v.Name = addPrefix(p.pfx, v.Name)
|
v.Name = addPrefix(p.pfx, v.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.main.Write(v)
|
p.Writer.Write(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addPrefix(pfx, name string) string {
|
func addPrefix(pfx, name string) string {
|
||||||
|
@ -5,11 +5,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/docker/buildx/util/logutil"
|
"github.com/docker/buildx/util/logutil"
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
"github.com/moby/buildkit/util/progress/progressui"
|
"github.com/moby/buildkit/util/progress/progressui"
|
||||||
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,10 +23,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Printer struct {
|
type Printer struct {
|
||||||
status chan *client.SolveStatus
|
status chan *client.SolveStatus
|
||||||
done <-chan struct{}
|
done <-chan struct{}
|
||||||
err error
|
err error
|
||||||
warnings []client.VertexWarning
|
warnings []client.VertexWarning
|
||||||
|
logMu sync.Mutex
|
||||||
|
logSourceMap map[digest.Digest]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) Wait() error {
|
func (p *Printer) Wait() error {
|
||||||
@ -41,13 +45,39 @@ func (p *Printer) Warnings() []client.VertexWarning {
|
|||||||
return p.warnings
|
return p.warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Printer) ValidateLogSource(dgst digest.Digest, v interface{}) bool {
|
||||||
|
p.logMu.Lock()
|
||||||
|
defer p.logMu.Unlock()
|
||||||
|
src, ok := p.logSourceMap[dgst]
|
||||||
|
if ok {
|
||||||
|
if src == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p.logSourceMap[dgst] = v
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Printer) ClearLogSource(v interface{}) {
|
||||||
|
p.logMu.Lock()
|
||||||
|
defer p.logMu.Unlock()
|
||||||
|
for d := range p.logSourceMap {
|
||||||
|
if p.logSourceMap[d] == v {
|
||||||
|
delete(p.logSourceMap, d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string) *Printer {
|
func NewPrinter(ctx context.Context, w io.Writer, out console.File, mode string) *Printer {
|
||||||
statusCh := make(chan *client.SolveStatus)
|
statusCh := make(chan *client.SolveStatus)
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
|
|
||||||
pw := &Printer{
|
pw := &Printer{
|
||||||
status: statusCh,
|
status: statusCh,
|
||||||
done: doneCh,
|
done: doneCh,
|
||||||
|
logSourceMap: map[digest.Digest]interface{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == PrinterModeAuto {
|
if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == PrinterModeAuto {
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
type Writer interface {
|
type Writer interface {
|
||||||
Write(*client.SolveStatus)
|
Write(*client.SolveStatus)
|
||||||
|
ValidateLogSource(digest.Digest, interface{}) bool
|
||||||
|
ClearLogSource(interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write(w Writer, name string, f func() error) {
|
func Write(w Writer, name string, f func() error) {
|
||||||
@ -47,8 +49,20 @@ func NewChannel(w Writer) (chan *client.SolveStatus, chan struct{}) {
|
|||||||
v, ok := <-ch
|
v, ok := <-ch
|
||||||
if !ok {
|
if !ok {
|
||||||
close(done)
|
close(done)
|
||||||
|
w.ClearLogSource(done)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(v.Logs) > 0 {
|
||||||
|
logs := make([]*client.VertexLog, 0, len(v.Logs))
|
||||||
|
for _, l := range v.Logs {
|
||||||
|
if w.ValidateLogSource(l.Vertex, done) {
|
||||||
|
logs = append(logs, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.Logs = logs
|
||||||
|
}
|
||||||
|
|
||||||
w.Write(v)
|
w.Write(v)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user