eggplants / ghcr-badge

Generate ghcr.io (GitHub Container Registory) container's status badge
https://ghcr-badge.egpl.dev
MIT License
38 stars 10 forks source link

/size doesn't work for images built for multiple platforms #13

Closed frysztak closed 2 years ago

frysztak commented 2 years ago

I have an image (frysztak/orpington-news) built for both amd64 and arm64. badge returns size 0: badge

I think that happens because GHCR API returns the following when querying for manifest:

$ curl -H "Authorization: Bearer $(echo "v1:frysztak/orpington-news:0" | base64)" "https://ghcr.io/v2/frysztak/orpington-news/manifests/latest"
{
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "schemaVersion": 2,
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "digest": "sha256:0d73ad2cd04d706bd51cfb5e5025050f2722d87d8b361db1d3503420baf52313",
         "size": 5535,
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "digest": "sha256:1c4b3de94974de6919bfc8ea83ef295f5ac5065c9f8b7d83ae5cd1fe8644ffbf",
         "size": 5535,
         "platform": {
            "architecture": "arm64",
            "os": "linux"
         }
      }
   ]
}

and generate.py expects it to be a "mediaType": "application/vnd.docker.distribution.manifest.v2+json"

frysztak commented 2 years ago

wow, that was quick. thanks! however, it now seems to return manifest size rather than sum of layer sizes. to fetch those, you need to do another call API with image digest as tag. for example, for amd64 image: https://ghcr.io/v2/frysztak/orpington-news/manifests/sha256:0d73ad2cd04d706bd51cfb5e5025050f2722d87d8b361db1d3503420baf52313

eggplants commented 2 years ago

Correct?

image

frysztak commented 2 years ago

yes! thanks :tada: