Use the Container Registry API to fetch image details based on image_id
Problem to solve
Currently, the Container Registry API is able to:
- List container repository for a project: https://docs.gitlab.com/ee/api/container_registry.html#within-a-project
- List container repository for a group: https://docs.gitlab.com/ee/api/container_registry.html#within-a-group
But we need a way to fetch the container repository details based on id
, both for project
and groups
Proposal
Fetch the container repository details (with the tag list included) with the following URL:
-
/registry/repositories/:repository_id
(any level)
Further details
Implementation
@10io says:
By providing the
:repository_id
(the container repository id), we can find the linked GitLabproject
object (the container repository model is linked toproject
). With it, we can run all the permission checks againstcurrent_user
. The only caution to have here is to not reply404 Not found
when the container repo or the project is not found but something like403 Forbidden
.
This new API endpoint should return the same payload as:
Entities::ContainerRegistry::Repository, tags: true
and in addition have the bulk delete path ( the one returned by this: https://gitlab.com/gitlab-org/gitlab/blob/22c19861a6b2137e5b57ab04798b81c721349cf0/app/controllers/projects/registry/repositories_controller.rb#L34-35 )Most probably we want to hide that path for non-ui requests ( if is possible )
POC
In the POC, we made: !26503 (closed)
The API is provisorily implemented with:
desc 'Get repository details' do
detail 'This feature was introduced in GitLab 12.9.'
success Entities::ContainerRegistry::Repository
end
params do
requires :repository_id, type: Integer, desc: 'The ID of the repository'
end
get ':id/registry/repositories/:repository_id' do
present repository, with: Entities::ContainerRegistry::Repository, tags: true
end
in lib/api/project_container_repositories.rb
Why it's important
By expanding the API to allow listing images by ID, we will be able to implement:
Testing and Availability
Need to refactor:
- spec/requests/api/group_container_repositories_spec.rb
- spec/requests/api/project_container_repositories_spec.rb
This change can also impact the test design for the API tests at the feature/end-to-end level for the Container Registry