docker / metadata-action

GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
https://github.com/marketplace/actions/docker-metadata-action
Apache License 2.0
911 stars 118 forks source link

Feature request and discussion: support of annotations #332

Closed favonia closed 11 months ago

favonia commented 1 year ago

Assuming that https://github.com/docker/build-push-action/issues/958 will be implemented, I hope annotations can be as well-supported as labels. That is, I wish in the JSON output would somehow contain one of the two values: either (for manifests)

org.opencontainers.image.created=...
org.opencontainers.image.description=...
org.opencontainers.image.licenses=...
org.opencontainers.image.revision=...
org.opencontainers.image.source=...
org.opencontainers.image.title=...
org.opencontainers.image.url=...
org.opencontainers.image.version=...

or (for indexes)

index:org.opencontainers.image.created=...
index:org.opencontainers.image.description=...
index:org.opencontainers.image.licenses=...
index:org.opencontainers.image.revision=...
index:org.opencontainers.image.source=...
index:org.opencontainers.image.title=...
index:org.opencontainers.image.url=...
index:org.opencontainers.image.version=...

However, I soon realized it is not easy to coherently extend the current UI to achieve this:

  1. Annotations can go anywhere, and for multi-arch images (arguably the most common use of indexes), at least ghcr.io specified that the annotations should go to the index. I'm not sure about other hosting services. Theoretically they can go anywhere.
  2. Buildkit will fail if there isn't an index for it to attach index annotations.
  3. It is not easy to predict whether Buildkit would generate an index; see https://github.com/docker/build-push-action/issues/755

Despite the above point 3, it seems one reasonable design is:

I don't want to claim this is a very good design because of the above points 2 and 3. The user will have to know whether there would be an index layer to pick the correct options. On the other hand, it doesn't seem to make things worse, and I'd like to start this conversation now because the automatic metadata generation is arguably the last piece of a smooth pipeline on GitHub.

crazy-max commented 1 year ago

Opened https://github.com/docker/build-push-action/pull/992 to add support for the new --annotation flag (see also upstream https://github.com/docker/buildx/pull/2020).

Would just need to do smth like https://github.com/docker/build-push-action/pull/992/files#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fR1174

But then we need to set the proper prefix to each "labels" either on the manifest or index. I'm working to make this possible with the metadata-action.

kroese commented 11 months ago

So how does it work with index:?

I am currently doing:

labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.labels }}

But that won't work if I need to prepend index: to each entry? Is there an easy way to do this?

Is there a flag that you can set if you want them to be added to both?

favonia commented 11 months ago

@kroese It's already documented in README. However, I did feel the current README could help the users more and thus opened a PR #359. It still requires you to read through the documentation, though.

kroese commented 11 months ago

@favonia Sorry, I missed that, you are right!