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

imagetools inspect --format ignores formatting unless json is used #1175

Open
thaJeztah opened this issue Jun 21, 2022 · 7 comments · May be fixed by #1882
Open

imagetools inspect --format ignores formatting unless json is used #1175

thaJeztah opened this issue Jun 21, 2022 · 7 comments · May be fixed by #1882
Labels
help wanted Extra attention is needed

Comments

@thaJeztah
Copy link
Member

thaJeztah commented Jun 21, 2022

Was writing a reply to docker/hub-feedback#2043, and noticed this.

Reproduced on;

docker buildx version
github.com/docker/buildx v0.8.2-docker 6224def4dd2c3d347eee19db595348c50d7cb491

When using the -f / --format option, the template is ignored, unless it's using the json function;

docker buildx imagetools inspect --format '{{.Manifest.Digest}}' tensorflow/tensorflow:1.13.1-gpu-py3
Name:      docker.io/tensorflow/tensorflow:1.13.1-gpu-py3
MediaType: application/vnd.docker.distribution.manifest.v2+json
Digest:    sha256:0f949ccc690d9c50e9b46b16d9030c2c6845af621c2e7e82c4bf59803edc69b5
docker buildx imagetools inspect --format '{{json .Manifest.Digest}}' tensorflow/tensorflow:1.13.1-gpu-py3
"sha256:0f949ccc690d9c50e9b46b16d9030c2c6845af621c2e7e82c4bf59803edc69b5"

This is inconsistent with other commands, for example, here's docker image inspect (difference between using json and without is that the json output uses JSON quoting for the output);

docker image inspect -f '{{.ID}}' busybox
sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8

docker image inspect -f '{{json .ID}}' busybox
"sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8"

Also note that the json output does not print a newline at the end, which can make it a bit cumbersome to use; here's the full output (notice that the prompt is appended to the output, because there's no trailing newline)

root@swarm-test-01:~# docker buildx imagetools inspect --format '{{json .Manifest.Digest}}' tensorflow/tensorflow:1.13.1-gpu-py3
"sha256:0f949ccc690d9c50e9b46b16d9030c2c6845af621c2e7e82c4bf59803edc69b5"root@swarm-test-01:~#
@thaJeztah
Copy link
Member Author

/cc @crazy-max @jedevc

@crazy-max
Copy link
Member

@thaJeztah Since docker/cli#2936 has been merged I will revisit the format output to be aligned.

@thaJeztah
Copy link
Member Author

Thanks! Yeah, I was mostly surprised it was silently ignored 😅. w.r.t. the newline at the end; technically it's "correct" (the newline doesn't have to be there (also not when using it for scripting), but ISTR the newline was added to make it slightly easier to use interactively.

@uhthomas
Copy link

Hey! It looks like this issue is coming up on a year old, is this fixable now given the aforementioned PR was merged? I still see this behaviour today.

❯ docker buildx imagetools inspect debian:bullseye --format="{{.Manifest.Digest}}"
Name:      docker.io/library/debian:bullseye
MediaType: application/vnd.docker.distribution.manifest.list.v2+json
Digest:    sha256:1e5f2d70c9441c971607727f56d0776fb9eecf23cd37b595b26db7a974b2301d
           
Manifests:
...

@thaJeztah
Copy link
Member Author

The linked PR was implementing changes in the docker CLI itself; this probably hasn't been worked on for buildx. Contributions welcome though if someone is interested working on this.

@thaJeztah thaJeztah added the help wanted Extra attention is needed label Jun 13, 2023
@uhthomas
Copy link

uhthomas commented Jun 14, 2023

Sure, I'm taking a look now. There's definitely something funky going on given it doesn't seem that Go templates for {{.Manifest are respected and includes duplicate logic.

@uhthomas
Copy link

Cool, I removed that logic and it seems to work as expected. I'll clean it up and submit a PR.

❯ go run ./cmd/buildx imagetools inspect --format="{{.Manifest.Digest}}" alpine
sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11

uhthomas added a commit to uhthomas/buildx that referenced this issue Jun 14, 2023
Use the formatting packages provided by docker/cli to comply with the official
formatting documentation.

https://docs.docker.com/config/formatting/

The use of the official formatting packages also fixes the format templating.

Fixes: docker#1175
@uhthomas uhthomas linked a pull request Jun 14, 2023 that will close this issue
uhthomas added a commit to uhthomas/buildx that referenced this issue Jun 14, 2023
Use the formatting packages provided by docker/cli to comply with the official
formatting documentation.

https://docs.docker.com/config/formatting/

The use of the official formatting packages also fixes the format templating.

Fixes: docker#1175

Signed-off-by: Thomas Way <thomas@6f.io>
uhthomas added a commit to uhthomas/buildx that referenced this issue Jun 14, 2023
Use the formatting packages provided by docker/cli to comply with the official
formatting documentation.

https://docs.docker.com/config/formatting/

The use of the official formatting packages also fixes the format templating.

Fixes: docker#1175

Signed-off-by: Thomas Way <thomas@6f.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants