mirror of
https://github.com/moby/buildkit.git
synced 2026-06-30 19:57:39 +00:00
client: handle status log in client
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@@ -23,8 +23,8 @@ type VertexStatus struct {
|
||||
Total int64
|
||||
Current int64
|
||||
Timestamp time.Time
|
||||
Started *time.Time // StartedAt
|
||||
Completed *time.Time // StartedAt
|
||||
Started *time.Time
|
||||
Completed *time.Time
|
||||
}
|
||||
|
||||
type VertexLog struct {
|
||||
|
||||
@@ -6,14 +6,13 @@ import (
|
||||
"encoding/hex"
|
||||
"io"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/pkg/errors"
|
||||
controlapi "github.com/tonistiigi/buildkit_poc/api/services/control"
|
||||
"github.com/tonistiigi/buildkit_poc/client/llb"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (c *Client) Solve(ctx context.Context, r io.Reader) error {
|
||||
func (c *Client) Solve(ctx context.Context, r io.Reader, statusChan chan *SolveStatus) error {
|
||||
def, err := llb.ReadFrom(r)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to parse input")
|
||||
@@ -52,10 +51,40 @@ func (c *Client) Solve(ctx context.Context, r io.Reader) error {
|
||||
}
|
||||
return errors.Wrap(err, "failed to receive status")
|
||||
}
|
||||
logrus.Debugf("status: %+v", resp)
|
||||
s := SolveStatus{}
|
||||
for _, v := range resp.Vertexes {
|
||||
s.Vertexes = append(s.Vertexes, &Vertex{
|
||||
Digest: v.Digest,
|
||||
Inputs: v.Inputs,
|
||||
Name: v.Name,
|
||||
Started: v.Started,
|
||||
Completed: v.Completed,
|
||||
})
|
||||
}
|
||||
for _, v := range resp.Statuses {
|
||||
s.Statuses = append(s.Statuses, &VertexStatus{
|
||||
ID: v.ID,
|
||||
Vertex: v.Vertex,
|
||||
Name: v.Name,
|
||||
Total: v.Total,
|
||||
Current: v.Current,
|
||||
Timestamp: v.Timestamp,
|
||||
Started: v.Started,
|
||||
Completed: v.Completed,
|
||||
})
|
||||
}
|
||||
if statusChan != nil {
|
||||
statusChan <- &s
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
defer func() {
|
||||
if statusChan != nil {
|
||||
close(statusChan)
|
||||
}
|
||||
}()
|
||||
|
||||
return eg.Wait()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/tonistiigi/buildkit_poc/client"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var buildCommand = cli.Command{
|
||||
@@ -14,9 +18,29 @@ var buildCommand = cli.Command{
|
||||
}
|
||||
|
||||
func build(clicontext *cli.Context) error {
|
||||
client, err := resolveClient(clicontext)
|
||||
c, err := resolveClient(clicontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.Solve(context.TODO(), os.Stdin)
|
||||
|
||||
ch := make(chan *client.SolveStatus)
|
||||
eg, ctx := errgroup.WithContext(context.TODO()) // TODO: define appContext
|
||||
|
||||
eg.Go(func() error {
|
||||
return c.Solve(ctx, os.Stdin, ch)
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
for s := range ch {
|
||||
for _, v := range s.Vertexes {
|
||||
log.Print(spew.Sdump(v))
|
||||
}
|
||||
for _, v := range s.Statuses {
|
||||
log.Print(spew.Sdump(v))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return eg.Wait()
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ func (is *imageSource) Pull(ctx context.Context, id source.Identifier) (cache.Im
|
||||
|
||||
fetcher, err := is.resolver.Fetcher(ctx, ref)
|
||||
if err != nil {
|
||||
stopProgress()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -99,6 +100,7 @@ func (is *imageSource) Pull(ctx context.Context, id source.Identifier) (cache.Im
|
||||
images.ChildrenHandler(is.ContentStore),
|
||||
}
|
||||
if err := images.Dispatch(ctx, images.Handlers(handlers...), desc); err != nil {
|
||||
stopProgress()
|
||||
return nil, err
|
||||
}
|
||||
stopProgress()
|
||||
@@ -337,7 +339,6 @@ func oneOffProgress(ctx context.Context, id string) func(err error) error {
|
||||
pw, _, _ := progress.FromContext(ctx, id)
|
||||
now := time.Now()
|
||||
st := progress.Status{
|
||||
Action: id,
|
||||
Started: &now,
|
||||
}
|
||||
pw.Write(st)
|
||||
|
||||
Reference in New Issue
Block a user