Querying Docker image creation date from Packages

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.

Hi @aedm,

Could you try running the following command and let me see what it returns?

($READ_PACKAGES_TOKEN is a PAT with the read:packages scope)

docker run jcansdale/gpr files aedm/actiontest -k $READ_PACKAGES_TOKEN 

Regards,
Jamie.