From d918b28961974e4ee9c0dd43cf3fd36aa9ce2142 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 29 Jun 2017 16:22:37 -0700 Subject: [PATCH] progress: show logs for a failed vertex Signed-off-by: Tonis Tiigi --- examples/buildkit/buildkit.go | 17 ++++++++++++----- util/progress/progressui/display.go | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/examples/buildkit/buildkit.go b/examples/buildkit/buildkit.go index 6048bc6b..6100a549 100644 --- a/examples/buildkit/buildkit.go +++ b/examples/buildkit/buildkit.go @@ -8,11 +8,18 @@ import ( "github.com/moby/buildkit/util/system" ) +type buildOpt struct { + target string + containerd string +} + func main() { - target := flag.String("target", "containerd", "target (standalone, containerd)") + var opt buildOpt + flag.StringVar(&opt.target, "target", "containerd", "target (standalone, containerd)") + flag.StringVar(&opt.containerd, "containerd", "master", "containerd version") flag.Parse() - bk := buildkit(*target == "containerd") + bk := buildkit(opt) out := bk.Run(llb.Shlex("ls -l /bin")) // debug output dt, err := out.Marshal() @@ -45,7 +52,7 @@ func containerd(version string) *llb.State { Run(llb.Shlex("make bin/containerd")).Root() } -func buildkit(withContainerd bool) *llb.State { +func buildkit(opt buildOpt) *llb.State { src := goBuildBase().With(goFromGit("github.com/moby/buildkit", "master")) builddStandalone := src. @@ -62,9 +69,9 @@ func buildkit(withContainerd bool) *llb.State { copyFrom(runc("v1.0.0-rc3"), "/usr/bin/runc", "/bin/"), ) - if withContainerd { + if opt.target == "containerd" { return r.With( - copyFrom(containerd("master"), "/go/src/github.com/containerd/containerd/bin/containerd", "/bin/"), + copyFrom(containerd(opt.containerd), "/go/src/github.com/containerd/containerd/bin/containerd", "/bin/"), copyFrom(builddContainerd, "/bin/buildd-containerd", "/bin/")) } return r.With(copyFrom(builddStandalone, "/bin/buildd-standalone", "/bin/")) diff --git a/util/progress/progressui/display.go b/util/progress/progressui/display.go index 2b04abad..1ccc7249 100644 --- a/util/progress/progressui/display.go +++ b/util/progress/progressui/display.go @@ -45,6 +45,7 @@ func DisplaySolveStatus(ctx context.Context, ch chan *client.SolveStatus) error if done { disp.print(t.displayInfo(), true) + t.printErrorLogs() return nil } else if displayLimiter.Allow() { disp.print(t.displayInfo(), false) @@ -78,6 +79,7 @@ type vertex struct { *client.Vertex statuses []*status byID map[string]*status + logs []*client.VertexLog } type status struct { @@ -120,6 +122,31 @@ func (t *trace) update(s *client.SolveStatus) { } v.byID[s.ID].VertexStatus = s } + for _, l := range s.Logs { + v, ok := t.byDigest[l.Vertex] + if !ok { + continue // shouldn't happen + } + v.logs = append(v.logs, l) + } +} + +func (t *trace) printErrorLogs() { + for _, v := range t.vertexes { + if v.Error != "" && !strings.HasSuffix(v.Error, context.Canceled.Error()) { + fmt.Println("------") + fmt.Printf(" > %s:\n", v.Name) + for _, l := range v.logs { + switch l.Stream { + case 1: + os.Stdout.Write(l.Data) + case 2: + os.Stderr.Write(l.Data) + } + } + fmt.Println("------") + } + } } func (t *trace) displayInfo() (d displayInfo) {