Querying Docker image creation date from GH Packages Registry

My use case: delete docker images older than N days from Github Packages.

I’m trying to write a cleanup Github Action that automatically removes old docker images from the Github Packages registry. Currently, there’s no reliable way to get the creation date of an image tag using the APIs available. Existing Actions on the Marketplace don’t work for docker images either.

This is the list of image versions as displayed on the Github page:


I underlined the data I want to obtain.

Trying the official Github Packages API:

query {
  repository(owner:"aedm", name:"actiontest") {
    packages(names: "gat", first: 5) {
      nodes {
        versions(first:10) {
          nodes {
            version
            files(first: 100) {
              nodes {
                updatedAt
              } 
            }
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "repository": {
      "packages": {
        "nodes": [
          {
            "versions": {
              "nodes": [
                {
                  "version": "5a8476dee6e2c66fcc0a371f8c9fc53d4bf46d2f",
                  "files": {
                    "nodes": [
                      {
                        "updatedAt": "2020-07-07T14:53:00Z"
                      },
                      {
                        "updatedAt": "2020-07-07T14:53:00Z"
                      },
                      {
                        "updatedAt": "2020-07-07T14:53:00Z"
                      },
                      {
                        "updatedAt": "2020-07-07T14:53:00Z"
                      },
                      {
                        "updatedAt": "2020-07-07T14:53:00Z"
                      }
                    ]
                  }
                },
                {
                  "version": "7d9ef75fa5935764f83997bb96787754a8da0b92",
                  "files": {
                    "nodes": [] // <-- FILES LIST EMPTY, BUT THE IMAGE EXISTS, POSSIBLE BUG?
                  }
                },
                {
                  "version": "ce61ead195caf8737b1934688af8e3b2599a083a",
                  "files": {
                    "nodes": [] // <-- FILES LIST EMPTY, BUT THE IMAGE EXISTS, POSSIBLE BUG?
                  }
                },
  // snip

Only the first image contains a list of files (probably docker image layers) and their respective updatedAt fields.

I believe this is a bug in the Github Packages API.

Trying the Docker Registry V2 API:

I can also query the Docker manifest for a certain image tag:

https://docker.pkg.github.com/v2/aedm/actiontest/gat/manifests/ed9715a28211cfc0a73c5a6cd2d78cece85fa278

Response:

{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
   "config": {
      "mediaType": "application/vnd.docker.container.image.v1+json",
      "size": 7015,
      "digest": "sha256:89ec9da682137d6b18ab8244ca263b6771067f251562f884c7510c8f1e5ac910"
   },
   "layers": [
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 2813316,
         "digest": "sha256:cbdbe7a5bc2a134ca8ec91be58565ec07d037386d1f1d8385412d224deafca08"
      },
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 5765370,
         "digest": "sha256:c554c602ff329d94bcb532a7f3c97c27af3abcbb678bdd809e4e894135bb88c9"
      }
   ]
}

No image creation date there either.
Note: on Docker Hub, this information is available.

Is there a way to programmatically get the image tag creation date?

@aedm,

In the GitHub Actions, generally we can execute the related APIs to get the detailed information of packages from GitHub Packages.
However, as you have mentioned, there seem are some defects in the response. The problem should occur on the API itself, not GitHub Actions.

I recommend that you can report your questions about the GitHub API into the “GitHub API Development and Support” category.
In this category, you will get more detailed and in-depth support about GitHub API.

Thank you.

If anyone finds this post, I reposted the question in that topic: Querying Docker image creation date from Packages

@aedm,

Usually there will be some special technical supporters or the appropriate engineering team to view these posted tickets, and provide help as much as possible.

If you need help with anything related to workflow configuration, such as syntax, GitHub-hosted runners, or building actions, you can post tickets in the “GitHub Actions” category. And we also will help you solve the related questions as possible as we can.