-
Notifications
You must be signed in to change notification settings - Fork 485
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: Allow annotations for OCI image index #1965
Conversation
6d283d0
to
42ee388
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for it! I tested it and it works fine:
$ ./bin/build/buildx imagetools create -t ghcr.io/eiffel-fl/inspektor-gadget:vtest ghcr.io/inspektor-gadget/inspektor-gadget:v0.18.1@sha256:c3780808973801b24c80f8b46835b882fe0d69c08a4460333f28143569665861 ghcr.io/inspektor-gadget/inspektor-gadget:v0.18.1@sha256:d6d5661b02002aa8035e035e9210e3476e0401a948a86fabf104f71c2cbe0efe --annotations foo="bar"
[+] Building 2.4s (1/1) FINISHED
=> [internal] pushing ghcr.io/eiffel-fl/inspektor-gadget:vtest
$ ./bin/build/buildx imagetools inspect --raw ghcr.io/eiffel-fl/inspektor-gadget:vtest qasim/oci-annotations u=
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:c3780808973801b24c80f8b46835b882fe0d69c08a4460333f28143569665861",
"size": 2963,
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:d6d5661b02002aa8035e035e9210e3476e0401a948a86fabf104f71c2cbe0efe",
"size": 2962,
"platform": {
"architecture": "arm64",
"os": "linux"
}
}
],
"annotations": {
"foo": "bar"
}
}
I think we are OK regarding the rules, as the reversed domain name is only an advise and due to using map we cannot have two times the same key.
42ee388
to
b071d65
Compare
@crazy-max @jedevc any thoughts on this? :) |
Hm, in general I think the idea for this is alright 🎉 However, I think we'd probably want to retain consistency with how buildkit sets annotations: https://github.com/moby/buildkit/blob/master/docs/annotations.md. There's not really any strong consensus on how we'd expose this in buildx build, but imagetools should probably follow an identical setup to avoid confusion. #1171 (comment) gets pretty close to an ideal syntax imo. With, that to annotate your multi-arch image, you'd instead have:
Would this kind of syntax work for you? I think we need consistency through buildx, so maybe good to continue the discussion there. |
For the sake of parity we should consider supporting labels as well in follow-up. |
Great
Agreed, we should have consistency through buildx. Also, I was already thinking how can we give user a hint that these annotations are for |
b071d65
to
e5e178f
Compare
@jedevc I have updated the PR to use the new syntax with |
I've opened #1978 that you can use as a base for adding integration tests for checking the |
e5e178f
to
f8d9676
Compare
@tonistiigi great thanks. I updated the PR to include |
f8d9676
to
95b6a2f
Compare
95b6a2f
to
11c0502
Compare
indexAnnotations := make(map[string]string) | ||
manifestDescriptorAnnotations := make(map[string]string) | ||
for k, v := range ann { | ||
groups := annotationRegexp.FindStringSubmatch(k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a regexp here, wdyt about using https://github.com/moby/buildkit/blob/dd0053cdce470b1355fdb0bd5a8f2b0fc506d842/exporter/containerimage/exptypes/annotations.go#L85 instead?
Obviously, it's not perfect, since we'd need to add the annotation-
prefix here, which might make the error message a bit odd, but we could always upstream a buildkit fix later that would rework the function to have the caller remove the prefix there (so we wouldn't have to do that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a regexp here, wdyt about using https://github.com/moby/buildkit/blob/dd0053cdce470b1355fdb0bd5a8f2b0fc506d842/exporter/containerimage/exptypes/annotations.go#L85 instead?
Initially I had the same idea but we are using :
as a separator for type
and annotation key compared to .
expected here. So it needs more work than just appending annotation-
prefix.
but we could always upstream a buildkit fix later that would rework the function
Does it make sense to make buildkit parser to also handle :
separator. It sounded specific to buildx so I feel we should keep it here. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd prefer the conversion to buildkit's form for now, so that we only have one source of truth for parsing these keys - I'm happy to follow up in buildkit to rework the logic to be a bit more reusable for this case.
I also just noticed (sorry), that we aren't handling platforms? manifest-descriptor
supports a platform, and should only be attached to the descriptor for those platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to follow up in buildkit to rework the logic to be a bit more reusable for this case.
Agreed. That should be the way moving forward. I added a comment regrading using buildkit once it supports our use-case here.
I also just noticed (sorry), that we aren't handling platforms?
Great Catch. Done.
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
11c0502
to
3ef93e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉 Thanks @mqasimsarfraz!
Can you please merge this ? or do we have any open items against it? :) |
We were using a specific version for docker buildx to have support for adding annotaions ( docker/buildx#1965). But it has been released into stable already so removing workaround. Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
We were using a specific version for docker buildx to have support for adding annotaions ( docker/buildx#1965). But it has been released into stable already so removing workaround. Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
Currently there isn't any way to add annotations to OCI image index for multi-arch. The use case is to have a description in "About this version" in GitHub. It will introduce an optional flag of
--annotation
toimagetools create
to allow adding OCI annotations.Related: #1171
Testing Done:
OCI Image Index (annotation added)
Manifest Descriptor
Docker manifest list (noop)