Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildctl (du|prune|debug info): support --format {{json .}} #2992

Merged
merged 4 commits into from
Aug 2, 2022

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Jul 31, 2022

  • buildctl du --format '{{json .}}': the template is applied to []*UsageInfo
  • buildctl prune --format '{{json .}}': the template is applied to UsageInfo
  • buildctl debug info --format '{{json .}}': the template is applied to *Info
$ buildctl du --format '{{json .}}'
[{"id":"s1d9pk3439ap6e5tt67bndctk","mutable":false,"inUse":false,"size":8979670,"createdAt":"2022-07-31T06:57:11.046458864Z","lastUsedAt":"2022-07-31T06:57:13.862022729Z","usageCount":1,"parents":null,"description":"pulled from docker.io/library/alpine@sha256:7580ece7963bfa863801466c0a488f11c86f85d9988051a9f9c68cb27f6b7872","recordType":"regular","shared":false},{"id":"u0nmub83lksjb9qu04y23v48m","mutable":true,"inUse":false,"size":2805760,"createdAt":"2022-07-31T06:57:11.68658936Z","lastUsedAt":"2022-07-31T06:57:13.858709691Z","usageCount":1,"parents":["s1d9pk3439ap6e5tt67bndctk"],"description":"mount / from exec /bin/sh -c apk add --no-cache neofetch","recordType":"regular","shared":false},{"id":"jeppep0j1cguag5v53l4lvq49","mutable":true,"inUse":false,"size":8192,"createdAt":"2022-07-31T06:57:07.579255711Z","lastUsedAt":"2022-07-31T06:57:13.861316848Z","usageCount":1,"parents":null,"description":"local source for dockerfile","recordType":"source.local","shared":false},{"id":"ur25i8ylum9326x9nas2lfyej","mutable":true,"inUse":false,"size":4096,"createdAt":"2022-07-31T06:57:07.580579468Z","lastUsedAt":"2022-07-31T06:57:13.860030835Z","usageCount":1,"parents":null,"description":"local source for context","recordType":"source.local","shared":false}]

$ buildctl prune --format '{{json .}}'
{"id":"u0nmub83lksjb9qu04y23v48m","mutable":true,"inUse":false,"size":2805760,"createdAt":"2022-07-31T06:57:11.68658936Z","lastUsedAt":"2022-07-31T06:57:13.858709691Z","usageCount":1,"parents":["s1d9pk3439ap6e5tt67bndctk"],"description":"mount / from exec /bin/sh -c apk add --no-cache neofetch","recordType":"","shared":false}
{"id":"jeppep0j1cguag5v53l4lvq49","mutable":true,"inUse":false,"size":8192,"createdAt":"2022-07-31T06:57:07.579255711Z","lastUsedAt":"2022-07-31T06:57:13.861316848Z","usageCount":1,"parents":null,"description":"local source for dockerfile","recordType":"","shared":false}
{"id":"ur25i8ylum9326x9nas2lfyej","mutable":true,"inUse":false,"size":4096,"createdAt":"2022-07-31T06:57:07.580579468Z","lastUsedAt":"2022-07-31T06:57:13.860030835Z","usageCount":1,"parents":null,"description":"local source for context","recordType":"","shared":false}
{"id":"s1d9pk3439ap6e5tt67bndctk","mutable":false,"inUse":false,"size":8979670,"createdAt":"2022-07-31T06:57:11.046458864Z","lastUsedAt":"2022-07-31T06:57:13.862022729Z","usageCount":1,"parents":null,"description":"pulled from docker.io/library/alpine@sha256:7580ece7963bfa863801466c0a488f11c86f85d9988051a9f9c68cb27f6b7872","recordType":"","shared":false}

$ buildctl debug info --format '{{json .}}'
{"buildkitVersion":{"package":"github.com/moby/buildkit","version":"v0.10.0-380-g874eef9b","revision":"874eef9b70dbaf4f074d2bc8f4dc64237f8e83a0"}}

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>

func ParseTemplate(format string) (*template.Template, error) {
// aliases is from https://github.com/containerd/nerdctl/blob/v0.17.1/cmd/nerdctl/fmtutil.go#L116-L126 (Apache License 2.0)
aliases := map[string]string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? I think the examples in the PR work without this as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new in this PR, just moved from cmd/buildctl/debug/workers.go
405565c

@tonistiigi tonistiigi merged commit ca30ef2 into moby:master Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants