Skip to content

Enable use of ContainerRegistry::GitlabApiClient.tags for self-managed

What does this MR do and why?

In this MR, we enable the use of ContainerRegistry::GitlabApiClient#tags for any instance that supports the GitLab API. Previously, we only had them for Gitlab.com but now as part of the efforts in encouraging self-managed to migrate, we also want to roll out these next-gen features to migrated self-managed as well.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

Prerequisites: Container registry up and running with the metadata database enabled

ContainerRegistry::GitlabApiClient.supports_gitlab_api?
# => true

Gitlab.com?
# => false
  1. Make sure you have a container repository with tags.
  2. You can run the following commands in the Rails console and there should also be a corresponding log in the container registry:
id = 42 # change this to the ID of your container repository

container_repository = ContainerRepository.find(id)
container_repository.gitlab_api_client.supports_gitlab_api?
# => true

# NOTE: notice that from_api is set to true
container_repository.tags
# => [#<ContainerRegistry::Tag:0x00000001792dd488
#  @from_api=true,
#  @manifest_digest="sha256:1892768fa6c1385",
#  @media_type="application/vnd.docker.distribution.manifest.v2+json",
# ...
# ]

# change tagname to a tag of the container repository
# NOTE: notice that from_api is set to true
container_repository.tag("tagname")
# => => #<ContainerRegistry::Tag:0x000000013fcb5c88
# @from_api=true,

container_repository.each_tags_page do |x|
  puts x.map(&:name)
end

container_repository.tags_page
  1. You can also try out calling the API that calls these methods:
http://gdk.test:3000/api/v4/projects/<project-id>/registry/repositories/<repository-id>/tags
http://gdk.test:3000/api/v4/projects/<project-id>/registry/repositories/<repository-id>/tags?pagination=keyset
http://gdk.test:3000/api/v4/projects/<project-id>/registry/repositories/<repository-id>/tags/<tag-name>

I used Postman and set PRIVATE-TOKEN as one of the headers and created an access token for its value. You can create an access token in http://gdk.test:3000/-/user_settings/personal_access_tokens.

The following curl command also works (replace the ids with what you have):

curl --location 'http://gdk.test:3000/api/v4/projects/19/registry/repositories/6/tags' \
--header 'PRIVATE-TOKEN: glpat-xxxxxxxx'

Related to #434602 (closed)

Edited by Adie (she/her)

Merge request reports

Loading