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: add --format flag #854

Merged
merged 2 commits into from
Feb 25, 2022

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Nov 20, 2021

follow-up docker/roadmap#243 (comment)

adds --format flag to imagetools inspect command. Currently supported values are manifest (default and current behavior) and buildinfo.

buildinfo is the new one to retrieve build information for an image in the registry.

$ docker buildx imagetools inspect --format buildinfo crazymax/buildkit-buildsources-test:buildx
Name:    docker.io/crazymax/buildkit-buildsources-test:buildx

Sources:
  Type: docker-image
  Ref:  docker.io/docker/buildx-bin:0.6.1@sha256:a652ced4a4141977c7daaed0a074dcd9844a78d7d2615465b12f433ae6dd29f0
  Pin:  sha256:a652ced4a4141977c7daaed0a074dcd9844a78d7d2615465b12f433ae6dd29f0

  Type: docker-image
  Ref:  docker.io/library/alpine:3.13
  Pin:  sha256:026f721af4cf2843e07bba648e158fb35ecc876d822130633cc49f707f0fc88c

  Type: docker-image
  Ref:  docker.io/moby/buildkit:v0.9.0
  Pin:  sha256:8dc668e7f66db1c044aadbed306020743516a94848793e0f81f94a087ee78cab

  Type: docker-image
  Ref:  docker.io/tonistiigi/xx@sha256:21a61be4744f6531cb5f33b0e6f40ede41fa3a1b8c82d5946178f80cc84bfc04
  Pin:  sha256:21a61be4744f6531cb5f33b0e6f40ede41fa3a1b8c82d5946178f80cc84bfc04

  Type: git
  Ref:  https://github.com/crazy-max/buildkit-buildsources-test.git#master
  Pin:  c7f9447d38471b486e248857a89143776d27096c

  Type: http
  Ref:  https://github.com/raw/moby/moby/master/README.md
  Pin:  sha256:419455202b0ef97e480d7f8199b26a721a417818bc0e2d106975f74323f25e6c

cc @JamieMagee

Signed-off-by: CrazyMax crazy-max@users.noreply.github.com

@crazy-max crazy-max marked this pull request as ready for review November 20, 2021 09:28
// needs to discard containerd logger otherwise it will print
// unnecessary info during image reference resolution like
// https://github.com/containerd/containerd/blob/1a88cf5242445657258e0c744def5017d7cfb492/remotes/docker/resolver.go#L288
ctx = bxctx.WithLoggerDiscarded(ctx)
Copy link
Member Author

Choose a reason for hiding this comment

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

needs to discard containerd logger otherwise it will print unnecessary info during image reference resolution:

$ docker buildx imagetools inspect alpinefoo
INFO[0001] trying next host                              error="pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed" host=registry-1.docker.io
error: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

now:

$ docker buildx imagetools inspect alpinefoo
error: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

@crazy-max crazy-max force-pushed the buildinfo-cmd branch 2 times, most recently from a210432 to 09894eb Compare November 20, 2021 12:22
@crazy-max
Copy link
Member Author

crazy-max commented Nov 20, 2021

In addition, wondering if we could add another flag to display buildinfo from a metadata file (--metadata-file) generated by the build command.

@JamieMagee
Copy link

@crazy-max Thanks for this!

What's the typical release cadence for buildx? And when could I expect to see this functionality in a docker cli or docker ce release?

@crazy-max crazy-max changed the title imagetools: buildinfo cmd imagetools inspect: add --format flag Nov 23, 2021
@crazy-max crazy-max force-pushed the buildinfo-cmd branch 3 times, most recently from 1330560 to 90f7d4b Compare November 23, 2021 12:05
@crazy-max
Copy link
Member Author

crazy-max commented Nov 23, 2021

@tonistiigi As discussed, --format flag has been added to the imagetools inspect command to handle build information. In a follow-up we could add a config format to display the image configuration.

@JamieMagee

What's the typical release cadence for buildx? And when could I expect to see this functionality in a docker cli or docker ce release?

The buildinfo feature is only available in the main branch of the BuildKit repo atm. Not sure when the first 0.10 RC of BuildKit will be released. I think @tonistiigi and @sipsma want to consolidate the MergeOp feature and provide COPY with merge semantics.

About buildx, there will be a patch release on wednesday (0.7.1) to fix the current issues. This PR will probably be available in the next minor release but you can already download the artifacts in staging from the GitHub workflow if you want to try it.

@tonistiigi
Copy link
Member

I'd expect the template format like other commands. Eg. {{json .Config}}, {{json .BuildInfo}}

@@ -85,7 +134,8 @@ func inspectCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command {
}

flags := cmd.Flags()
flags.BoolVar(&options.raw, "raw", false, "Show original JSON manifest")
flags.StringVar(&options.format, "format", "manifest", "Format the output")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
flags.StringVar(&options.format, "format", "manifest", "Format the output")
flags.StringVar(&options.format, "format", "manifest", "Format the output (\"manifest\", or \"buildinfo\")")

@crazy-max
Copy link
Member Author

crazy-max commented Nov 24, 2021

I'd expect the template format like other commands. Eg. {{json .Config}}, {{json .BuildInfo}}

Agree but then --raw should be removed if we want to be strict and follow the current behavior of docker/cli like image inspect.

@tonistiigi
Copy link
Member

--raw is not the same as {{json .}}. It is the data that can be used to validate the checksum. We could move it to another field but it does have a very specific use case.

@crazy-max
Copy link
Member Author

crazy-max commented Nov 24, 2021

Ok so {{json .}} would print manifest + config + buildinfo right? Currently we display the manifest in raw format so I would guess the default value for format would be {{raw .Manifest}} for backward compat. I guess we should implement a formatter like the one from #830. WDYT?

@tonistiigi
Copy link
Member

{{json .}} printing all in json format, {{.buildinfo}} printing the buildinfo block. {{json .config}} printing the config as json would seem logical to me. {{.manifest}} I guess is the same but a bit weird that it is either index or manifest.

For --raw I think we can make it just incompatible with --format. Theoretically --raw --format {{json .config}}` could print the raw value of config, but that seems too special case to be worth of a custom implementation.

Is the config taking the first item from the index atm?

@crazy-max crazy-max marked this pull request as draft December 9, 2021 11:43
@crazy-max
Copy link
Member Author

@tonistiigi

Sorry didn't see your comment!

{{json .}} printing all in json format, {{.buildinfo}} printing the buildinfo block. {{json .config}} printing the config as json would seem logical to me. {{.manifest}} I guess is the same but a bit weird that it is either index or manifest.

For --raw I think we can make it just incompatible with --format. Theoretically --raw --format {{json .config}}` could print the raw value of config, but that seems too special case to be worth of a custom implementation.

Ok sgtm

Is the config taking the first item from the index atm?

Atm I don't handle config, only buildinfo and manifest.

@crazy-max crazy-max force-pushed the buildinfo-cmd branch 6 times, most recently from b4b65de to b1019c7 Compare February 24, 2022 15:33
@crazy-max crazy-max marked this pull request as ready for review February 24, 2022 15:40
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

» docker buildx imagetools inspect --raw alpine
error: format and raw cannot be used together

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

For multi-platform this breaks:

docker buildx imagetools inspect  mysql
error: no match for platform in manifest sha256:0962b771c2398c6dcddbbe77b3cf6658408396229b612035d938fb7c8d11c23c: not found

Should also make sure that without format we don't make these requests at all.

util/imagetools/printers.go Outdated Show resolved Hide resolved
@tonistiigi
Copy link
Member

As a follow-up, looks like some pkg reorganization is needed as these functions definitely should not require importing ttrpc etc.

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>

* `.Name`: provides the reference of the image
* `.Manifest`: provides manifest or manifest list
* `.Image`: provides the image config as `application/vnd.oci.image.config.v1+json` mediatype
Copy link
Member

@tonistiigi tonistiigi Feb 25, 2022

Choose a reason for hiding this comment

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

what does this "as mediatype" mean? I expect it is just the full config as it is in registry?

Copy link
Member Author

Choose a reason for hiding this comment

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

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
@crazy-max crazy-max added this to the v0.8.0 milestone Feb 25, 2022
@tonistiigi tonistiigi merged commit 7af2980 into docker:master Feb 25, 2022
@crazy-max crazy-max deleted the buildinfo-cmd branch February 26, 2022 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants