solver: trace LLB

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-02-05 15:05:41 -08:00
parent 89c7136f75
commit b0294e79d1

View File

@ -2,9 +2,14 @@ package dagger
import ( import (
"context" "context"
"encoding/json"
"github.com/moby/buildkit/client/llb" "github.com/moby/buildkit/client/llb"
bkgw "github.com/moby/buildkit/frontend/gateway/client" bkgw "github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/solver/pb"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
) )
// Polyfill for buildkit gateway client // Polyfill for buildkit gateway client
@ -37,6 +42,18 @@ func (s Solver) Solve(ctx context.Context, st llb.State) (bkgw.Reference, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
llb, err := dumpLLB(def)
if err != nil {
return nil, err
}
log.
Ctx(ctx).
Trace().
RawJSON("llb", llb).
Msg("solving")
// call solve // call solve
res, err := s.c.Solve(ctx, bkgw.SolveRequest{ res, err := s.c.Solve(ctx, bkgw.SolveRequest{
Definition: def.ToPB(), Definition: def.ToPB(),
@ -52,3 +69,23 @@ func (s Solver) Solve(ctx context.Context, st llb.State) (bkgw.Reference, error)
// always use single reference (ignore multiple outputs & metadata) // always use single reference (ignore multiple outputs & metadata)
return res.SingleRef() return res.SingleRef()
} }
type llbOp struct {
Op pb.Op
Digest digest.Digest
OpMetadata pb.OpMetadata
}
func dumpLLB(def *llb.Definition) ([]byte, error) {
ops := make([]llbOp, 0, len(def.Def))
for _, dt := range def.Def {
var op pb.Op
if err := (&op).Unmarshal(dt); err != nil {
return nil, errors.Wrap(err, "failed to parse op")
}
dgst := digest.FromBytes(dt)
ent := llbOp{Op: op, Digest: dgst, OpMetadata: def.Metadata[dgst]}
ops = append(ops, ent)
}
return json.Marshal(ops)
}