From 437a2d55c1e34a01e4c0802f02df733736931033 Mon Sep 17 00:00:00 2001 From: "Ciro S. Costa" Date: Sun, 4 Aug 2019 16:41:02 -0400 Subject: [PATCH] debug: add `fileop` to `--dot` Previously, `fileop`s where not included in the set of possible op types that were treated in the `dot` formatting in `buildctl debug dump-llb` when using the `--dot` flag. This commit add support for such fileop, allowing one to see basic properties associated with the op. Signed-off-by: Ciro S. Costa --- cmd/buildctl/debug/dumpllb.go | 20 ++++++++++++++++++++ examples/buildkit3/buildkit.go | 15 ++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/cmd/buildctl/debug/dumpllb.go b/cmd/buildctl/debug/dumpllb.go index be5c4af9..6ed33ae0 100644 --- a/cmd/buildctl/debug/dumpllb.go +++ b/cmd/buildctl/debug/dumpllb.go @@ -111,6 +111,26 @@ func attr(dgst digest.Digest, op pb.Op) (string, string) { return strings.Join(op.Exec.Meta.Args, " "), "box" case *pb.Op_Build: return "build", "box3d" + case *pb.Op_File: + names := []string{} + + for _, action := range op.File.Actions { + var name string + + switch act := action.Action.(type) { + case *pb.FileAction_Copy: + name = fmt.Sprintf("copy{src=%s, dest=%s}", act.Copy.Src, act.Copy.Dest) + case *pb.FileAction_Mkfile: + name = fmt.Sprintf("mkfile{path=%s}", act.Mkfile.Path) + case *pb.FileAction_Mkdir: + name = fmt.Sprintf("mkdir{path=%s}", act.Mkdir.Path) + case *pb.FileAction_Rm: + name = fmt.Sprintf("rm{path=%s}", act.Rm.Path) + } + + names = append(names, name) + } + return strings.Join(names, ","), "note" default: return dgst.String(), "plaintext" } diff --git a/examples/buildkit3/buildkit.go b/examples/buildkit3/buildkit.go index ece7cfa3..9cd435e6 100644 --- a/examples/buildkit3/buildkit.go +++ b/examples/buildkit3/buildkit.go @@ -9,10 +9,10 @@ import ( ) type buildOpt struct { - withContainerd bool + buildkit string containerd string runc string - buildkit string + withContainerd bool } func main() { @@ -112,10 +112,11 @@ func copyFrom(src llb.State, srcPath, destPath string) llb.StateOption { } } -// copy copies files between 2 states using cp until there is no copyOp +// copy copies files between 2 states using cp func copy(src llb.State, srcPath string, dest llb.State, destPath string) llb.State { - cpImage := llb.Image("docker.io/library/alpine:latest@sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe") - cp := cpImage.Run(llb.Shlexf("cp -a /src%s /dest%s", srcPath, destPath)) - cp.AddMount("/src", src, llb.Readonly) - return cp.AddMount("/dest", dest) + return dest.File(llb.Copy(src, srcPath, destPath, &llb.CopyInfo{ + AllowWildcard: true, + AttemptUnpack: true, + CreateDestPath: true, + })) }