Skip to content

Add published_at to ContainerRegistry::Tag

Adie (she/her) requested to merge 432724-add-published-at-registry-tag into master

Overview

Context: &10208 (comment 1662372558)

In #411387 (closed), we integrated the new list repository tags API from the container registry which returns 3 timestamps, created_at, updated_at and published_at. With this integration, we assign the created_at and updated_at return values of the registry to the created_at and updated_at attributes of the tag.

published_at is something that we don't use nor store in ContainerRegistry::Tag for now.

In this MR, we want to add published_at as an attribute to ContainerRegistry::Tag and expose this in GraphQL. We do this by:

  1. Adding a new attribute published_at to ContainerRegistry::Tag
  2. Filling up this new attribute from the API endpoint (if Gitlab.com)
  3. Adding the new field published_at to ContainerRepositoryTagType and make sure it is queryable from GraphQL

Note that using published_at in the frontend will be implemented in #432726 (closed).

How to set up and validate locally

Note: To run this, the metadata database should be setup.

Metadata database: local development setup guide

Once you have this setup, the Gitlab API should now be accessible and you can try the following command in the console:

ContainerRegistry::GitlabApiClient.supports_gitlab_api?
# => true

The API endpoint is only available for migrated container repositories which are gated with Gitlab.com? checks for now. To simulate this locally, we update the following function in app/models/container_repository.rb to have || true that sets our local setup to have migrated container registries.

def migrated?
  Gitlab.com_except_jh? || true
end

After that, we can head over to the GraphQL explorer and query the published_at of a tag, i.e. http://gdk.test:3000/-/graphql-explorer

Sample Query:

query {
  containerRepository(id: "gid://gitlab/ContainerRepository/13") {
  	tags(first: 10) {
      nodes {
        name
        createdAt
        publishedAt
      }
      pageInfo {
        hasNextPage
        endCursor
        startCursor
      }
    }
  }
}

Results:

{
  "data": {
    "containerRepository": {
      "tags": {
        "nodes": [
          {
            "name": "latest",
            "createdAt": "2023-10-01T11:52:34+00:00",
            "publishedAt": "2023-10-01T11:52:34+00:00"
          },
          {
            "name": "tag10",
            "createdAt": "2023-12-06T09:44:56+00:00",
            "publishedAt": "2023-12-06T09:44:56+00:00"
          },
          {
            "name": "tag5",
            "createdAt": "2023-12-06T08:58:49+00:00",
            "publishedAt": "2023-12-06T09:44:37+00:00"
          }
        ],
        "pageInfo": {
          "hasNextPage": false,
          "endCursor": null,
          "startCursor": null
        }
      }
    }
  }
}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #432724 (closed)

Edited by Adie (she/her)

Merge request reports