buildx/util/progress/multiwriter.go
Justin Chadwell 0566e62995 progress: add prefix to vertex progress group
As buildkit now uses progress groups for the COPY --link instruction
we need to ensure that we additionally prefix the progress group name,
or the target name will be left off in bake commands with more than one
target.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-09-02 16:45:51 +01:00

41 lines
681 B
Go

package progress
import (
"strings"
"github.com/moby/buildkit/client"
)
func WithPrefix(w Writer, pfx string, force bool) Writer {
return &prefixed{
Writer: w,
pfx: pfx,
force: force,
}
}
type prefixed struct {
Writer
pfx string
force bool
}
func (p *prefixed) Write(v *client.SolveStatus) {
if p.force {
for _, v := range v.Vertexes {
v.Name = addPrefix(p.pfx, v.Name)
if v.ProgressGroup != nil {
v.ProgressGroup.Name = addPrefix(p.pfx, v.ProgressGroup.Name)
}
}
}
p.Writer.Write(v)
}
func addPrefix(pfx, name string) string {
if strings.HasPrefix(name, "[") {
return "[" + pfx + " " + name[1:]
}
return "[" + pfx + "] " + name
}