diff --git a/cmd/buildctl/dump.go b/cmd/buildctl/dump.go new file mode 100644 index 00000000..ba8ef28c --- /dev/null +++ b/cmd/buildctl/dump.go @@ -0,0 +1,51 @@ +package main + +import ( + "io" + "log" + "os" + + "github.com/davecgh/go-spew/spew" + digest "github.com/opencontainers/go-digest" + "github.com/pkg/errors" + "github.com/tonistiigi/buildkit_poc/client/llb" + "github.com/tonistiigi/buildkit_poc/solver/pb" + "github.com/urfave/cli" +) + +var dumpCommand = cli.Command{ + Name: "dump", + Usage: "dump LLB in human-readable format. LLB must be passed via stdin. This command does not require the daemon to be running.", + Action: dumpLLB, +} + +func dumpLLB(clicontext *cli.Context) error { + ops, err := loadLLB(os.Stdin) + if err != nil { + return err + } + log.Print(spew.Sdump(ops)) + return nil +} + +type llbOp struct { + Op pb.Op + Digest digest.Digest +} + +func loadLLB(r io.Reader) ([]llbOp, error) { + bs, err := llb.ReadFrom(r) + if err != nil { + return nil, err + } + var ops []llbOp + for _, dt := range bs { + var op pb.Op + if err := (&op).Unmarshal(dt); err != nil { + return nil, errors.Wrap(err, "failed to parse op") + } + dgst := digest.FromBytes(dt) + ops = append(ops, llbOp{Op: op, Digest: dgst}) + } + return ops, nil +} diff --git a/cmd/buildctl/main.go b/cmd/buildctl/main.go index ebc500f5..221765a6 100644 --- a/cmd/buildctl/main.go +++ b/cmd/buildctl/main.go @@ -29,6 +29,7 @@ func main() { app.Commands = []cli.Command{ diskUsageCommand, buildCommand, + dumpCommand, } app.Before = func(context *cli.Context) error {