diff --git a/dagger/solver.go b/dagger/solver.go index 00790210..1764868a 100644 --- a/dagger/solver.go +++ b/dagger/solver.go @@ -2,9 +2,14 @@ package dagger import ( "context" + "encoding/json" "github.com/moby/buildkit/client/llb" 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 @@ -37,6 +42,18 @@ func (s Solver) Solve(ctx context.Context, st llb.State) (bkgw.Reference, error) if err != nil { return nil, err } + + llb, err := dumpLLB(def) + if err != nil { + return nil, err + } + + log. + Ctx(ctx). + Trace(). + RawJSON("llb", llb). + Msg("solving") + // call solve res, err := s.c.Solve(ctx, bkgw.SolveRequest{ 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) 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) +}