Skip to content

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

Merged
tonistiigi merged 4 commits into
moby:masterfrom
AkihiroSuda:du-json
Aug 2, 2022
Merged

buildctl (du|prune|debug info): support --format {{json .}}#2992
tonistiigi merged 4 commits into
moby:masterfrom
AkihiroSuda:du-json

Conversation

@AkihiroSuda
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
emmanuelguerin pushed a commit to emmanuelguerin/buildkit that referenced this pull request Mar 31, 2025
vendor: docker, docker/cli v28.0.0-rc.1
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.

2 participants