Skip to content

🐞 WithAnnotations does not work for multiarch images #10330

Closed

Description

@cbochula

What is the issue?

When including annotations on an image using WithAnnotation, I've found that annotations do not appear when publishing a multiarch image. From what I can tell annotations are supported by the image index spec. Not sure if would this be considered a Dagger or Buildkit issue?

Dagger version

v0.18.5

Steps to reproduce

Can't use the Dagger shell to reproduce, but here is a small module function which would demonstrate the issue:

func (m Example) PublishTest(ctx context.Context) (string, error) {
	ctr_amd64 := dag.Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/amd64")}).From("alpine")
	ctr_arm64 := dag.Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/arm64")}).From("alpine")
	return dag.Container().
		WithAnnotation("org.opencontainers.image.revision", "asdf").
		Publish(ctx, "localhost:5000/test", dagger.ContainerPublishOpts{PlatformVariants: []*dagger.Container{ctr_amd64, ctr_arm64}})
}

Call with

dagger call publish-test

Log output

As shown below, inspecting the manifest shows that the image index does not contain an annotations field for itself or any of it's listed images.

$ docker manifest inspect localhost:5000/test@sha256:cf34128603020ac3e631194f8e94a75d38dd0c2a8a2c3bf61590710e61d1f782
{
   "schemaVersion": 2,
   "mediaType": "application/vnd.oci.image.index.v1+json",
   "manifests": [
      {
         "mediaType": "application/vnd.oci.image.manifest.v1+json",
         "size": 480,
         "digest": "sha256:ac5b65813865592e25d308561d903fea8eeed8181365fc536f244610e9ffd710",
         "platform": {
            "architecture": "arm64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.oci.image.manifest.v1+json",
         "size": 480,
         "digest": "sha256:6b61b75959d34ce64ea6d9cce4a284ccc79eb680f66916aca05e9ed4c4dc21c2",
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      }
   ]
}

Activity

  1. jedevc commented on May 7, 2025

    @jedevc
    Contributor

    Ah, so I suspect the annotations are actually appearing, but docker manifest is pretty much legacy at this point - it's not including any annotations (since it was built before OCI actually became a thing really).

    You can see this on alpine:

    $ docker manifest inspect alpine
    {
       "schemaVersion": 2,
       "mediaType": "application/vnd.oci.image.index.v1+json",
       "manifests": [
          {
             "mediaType": "application/vnd.oci.image.manifest.v1+json",
             "size": 1022,
             "digest": "sha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474",
             "platform": {
                "architecture": "amd64",
                "os": "linux"
             }
          },
          ....
    

    vs docker buildx which does display this information:

    $ docker buildx imagetools inspect alpine --raw | jq
    {
      "manifests": [
        {
          "annotations": {
            "com.docker.official-images.bashbrew.arch": "amd64",
            "org.opencontainers.image.base.name": "scratch",
            "org.opencontainers.image.created": "2025-02-14T18:27:58Z",
            "org.opencontainers.image.revision": "17fe3d1e2d2cbf54d745139eab749c252e35b883",
            "org.opencontainers.image.source": "https://github.com/alpinelinux/docker-alpine.git#17fe3d1e2d2cbf54d745139eab749c252e35b883:x86_64",
            "org.opencontainers.image.url": "https://hub.docker.com/_/alpine",
            "org.opencontainers.image.version": "3.21.3"
          },
          "digest": "sha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474",
          "mediaType": "application/vnd.oci.image.manifest.v1+json",
          "platform": {
            "architecture": "amd64",
            "os": "linux"
          },
          "size": 1022
        },
        {
          "annotations": {
            "com.docker.official-images.bashbrew.arch": "amd64",
            "vnd.docker.reference.digest": "sha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474",
            "vnd.docker.reference.type": "attestation-manifest"
          },
          "digest": "sha256:f5fb419236878e25e11358970412e1aa64413c412398739d747e1333d3e1f6d1",
          "mediaType": "application/vnd.oci.image.manifest.v1+json",
          "platform": {
            "architecture": "unknown",
            "os": "unknown"
          },
          "size": 838
        },
    
  2. jedevc commented on May 7, 2025

    @jedevc
    Contributor

    Closing, since I think the issue is with the command used to inspect the image.

    But will re-open if the right command still doesn't include the right annotations, just let me know @cbochula! 💜

  3. cbochula commented on May 7, 2025

    @cbochula
    Author

    Thanks @jedevc! Can confirm `docker manifest inspect omitted the platform-specific annotations. However, with this example below, I'm not able to see annotations for the image index itself.

    func (m Example) T(ctx context.Context) (string, error) {
    	ctr_amd64 := dag.Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/amd64")}).From("alpine").WithAnnotation("example", "amd64")
    	ctr_arm64 := dag.Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/arm64")}).From("alpine").WithAnnotation("example", "arm64")
    	return dag.Container().
    		WithAnnotation("example", "index").
    		Publish(ctx, "localhost:5000/test", dagger.ContainerPublishOpts{PlatformVariants: []*dagger.Container{ctr_amd64, ctr_arm64}})
    }
    $ dagger call t
    ...
    localhost:5000/test@sha256:72da62f631a26b8425476c57f12beccc3e6f820c665d36e893cd8b0469f9d898
    

    After calling, I see the example annotation for the arm64 and amd64 platforms, but not seeing an annotations field for the image index itself:

    $ docker docker buildx imagetools inspect localhost:5000/test@sha256:72da62f631a26b8425476c57f12beccc3e6f820c665d36e893cd8b0469f9d898 --raw | jq
    
    {
      "schemaVersion": 2,
      "mediaType": "application/vnd.oci.image.index.v1+json",
      "manifests": [
        {
          "mediaType": "application/vnd.oci.image.manifest.v1+json",
          "digest": "sha256:87e839e0bdae17eb1e48bd8a963eb6130a6d9fb26247846975f2cf50ac2bf729",
          "size": 527,
          "annotations": {
            "example": "amd64"
          },
          "platform": {
            "architecture": "amd64",
            "os": "linux"
          }
        },
        {
          "mediaType": "application/vnd.oci.image.manifest.v1+json",
          "digest": "sha256:1e1db1fd5544ab0c7de1e9004373e133993c2616cf0f8bf5229507b48f5fd00a",
          "size": 527,
          "annotations": {
            "example": "arm64"
          },
          "platform": {
            "architecture": "arm64",
            "os": "linux"
          }
        }
      ]
    }
    

    This seems to be part of the OCI spec, but I'm not sure how broad the support for the annotations field in an image index is. It doesn't appear that the alpine image uses index-level annotations. Maybe it's too niche, but Is this something that could be supported in Dagger?

  4. jedevc commented on May 12, 2025

    @jedevc
    Contributor

    Yeah, the annotations we put are both on the manifest descriptor in the index, and on the manifest object itself - by design! We don't put them onto the index - curious what your use case is for that!

    The reasoning is: Container.withAnnotation applies to a single-platform container-object - when you publish a multi-platform image, it wouldn't be correct to just merge all of those and put them on the top-level object. There's not really an obvious way to handle collisions, etc.

    We have discussed previously what a multi-platform container would look like: #6675. Then it would make sense to have a MultiPlatformContainer.withAnnotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions