logs: extract cue path from buildkit solve status
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
2ae395843e
commit
79b66e82fc
@ -22,8 +22,7 @@ import (
|
||||
bkgw "github.com/moby/buildkit/frontend/gateway/client"
|
||||
|
||||
// docker output
|
||||
"github.com/containerd/console"
|
||||
"github.com/moby/buildkit/util/progress/progressui"
|
||||
"dagger.io/go/pkg/progressui"
|
||||
|
||||
"dagger.io/go/dagger/compiler"
|
||||
)
|
||||
@ -56,18 +55,16 @@ func NewClient(ctx context.Context, host string) (*Client, error) {
|
||||
// FIXME: return completed *Env, instead of *compiler.Value
|
||||
func (c *Client) Compute(ctx context.Context, env *Env) (*compiler.Value, error) {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
eg, gctx := errgroup.WithContext(ctx)
|
||||
|
||||
// Spawn print function
|
||||
var events chan *bk.SolveStatus
|
||||
if os.Getenv("DOCKER_OUTPUT") != "" {
|
||||
events = make(chan *bk.SolveStatus)
|
||||
eg.Go(func() error {
|
||||
dispCtx := context.TODO()
|
||||
return c.dockerprintfn(dispCtx, events, lg)
|
||||
})
|
||||
}
|
||||
events := make(chan *bk.SolveStatus)
|
||||
eg.Go(func() error {
|
||||
// Create a background context so that logging will not be cancelled
|
||||
// with the main context.
|
||||
dispCtx := lg.WithContext(context.Background())
|
||||
return c.logSolveStatus(dispCtx, events)
|
||||
})
|
||||
|
||||
// Spawn build function
|
||||
outr, outw := io.Pipe()
|
||||
@ -196,8 +193,68 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, er
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *Client) dockerprintfn(ctx context.Context, ch chan *bk.SolveStatus, out io.Writer) error {
|
||||
var cons console.Console
|
||||
// FIXME: use smarter writer from blr
|
||||
return progressui.DisplaySolveStatus(ctx, "", cons, out, ch)
|
||||
func (c *Client) logSolveStatus(ctx context.Context, ch chan *bk.SolveStatus) error {
|
||||
parseName := func(v *bk.Vertex) (string, string) {
|
||||
// Pattern: `@name@ message`. Minimal length is len("@X@ ")
|
||||
if len(v.Name) < 2 || !strings.HasPrefix(v.Name, "@") {
|
||||
return "", v.Name
|
||||
}
|
||||
|
||||
prefixEndPos := strings.Index(v.Name[1:], "@")
|
||||
if prefixEndPos == -1 {
|
||||
return "", v.Name
|
||||
}
|
||||
|
||||
component := v.Name[1 : prefixEndPos+1]
|
||||
return component, v.Name[prefixEndPos+3 : len(v.Name)]
|
||||
}
|
||||
|
||||
return progressui.PrintSolveStatus(ctx, ch,
|
||||
func(v *bk.Vertex, index int) {
|
||||
component, name := parseName(v)
|
||||
lg := log.
|
||||
Ctx(ctx).
|
||||
With().
|
||||
Str("component", component).
|
||||
Logger()
|
||||
|
||||
lg.
|
||||
Debug().
|
||||
Msg(fmt.Sprintf("#%d %s\n", index, name))
|
||||
lg.
|
||||
Debug().
|
||||
Msg(fmt.Sprintf("#%d %s\n", index, v.Digest))
|
||||
},
|
||||
func(v *bk.Vertex, format string, a ...interface{}) {
|
||||
component, _ := parseName(v)
|
||||
lg := log.
|
||||
Ctx(ctx).
|
||||
With().
|
||||
Str("component", component).
|
||||
Logger()
|
||||
|
||||
lg.
|
||||
Debug().
|
||||
Msg(fmt.Sprintf(format, a...))
|
||||
},
|
||||
func(v *bk.Vertex, stream int, partial bool, format string, a ...interface{}) {
|
||||
component, _ := parseName(v)
|
||||
lg := log.
|
||||
Ctx(ctx).
|
||||
With().
|
||||
Str("component", component).
|
||||
Logger()
|
||||
|
||||
switch stream {
|
||||
case 1:
|
||||
lg.
|
||||
Info().
|
||||
Msg(fmt.Sprintf(format, a...))
|
||||
case 2:
|
||||
lg.
|
||||
Error().
|
||||
Msg(fmt.Sprintf(format, a...))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
5
go.mod
5
go.mod
@ -7,16 +7,21 @@ require (
|
||||
github.com/KromDaniel/jonson v0.0.0-20180630143114-d2f9c3c389db
|
||||
github.com/containerd/console v1.0.1
|
||||
github.com/emicklei/proto v1.9.0 // indirect
|
||||
github.com/jaguilar/vt100 v0.0.0-20150826170717-2703a27b14ea
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
|
||||
github.com/moby/buildkit v0.8.1
|
||||
github.com/morikuni/aec v1.0.0
|
||||
github.com/opencontainers/go-digest v1.0.0
|
||||
github.com/rs/zerolog v1.20.0
|
||||
github.com/spf13/cobra v1.1.3
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/tonistiigi/fsutil v0.0.0-20201103201449-0834f99b7b85
|
||||
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1
|
||||
golang.org/x/tools v0.1.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86
|
||||
)
|
||||
|
3
go.sum
3
go.sum
@ -609,6 +609,8 @@ github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88J
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
|
||||
@ -743,6 +745,7 @@ github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R
|
||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.0-20190522114515-bc1a522cf7b1/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8=
|
||||
github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
||||
|
Reference in New Issue
Block a user