I have a self-hosten GitLab CE Omnibus installation (version 11.5.2) running including the container registry. Now, the disk size needed to host all those containers increase quite fast. As an admin, I want to list all Docker images in this registry including their size, so I can maybe let those get deleted.
Maybe I haven't looked hard enough but currently, I couldn't find something in the Admin Panel of GitLab. Before I make myself the work of creating a script to compare that weird linking between repositories
and blobs
directories in /var/opt/gitlab/gitlab-rails/shared/registry/docker/registry/v2
and then aggregating the sizes based on the repositories, i wanted to ask:
Is there some CLI command or even a curl call to the registry to get the information I want?
There is a Gitlab Rails Console script that is documented here: https://docs.gitlab.com/ee/administration/packages/container_registry.html#registry-disk-space-usage-by-project
You can adapt that command to increase the number of projects it will find, as it's only looking at the 100 last projects.
For example, to list all projects and their sizes (may be slow for a large number of projects):
projects_and_size = [["project_id", "creator_id", "registry_size_bytes", "project path"]]
# You need to specify the projects that you want to look through. You can get these in any manner.
Project.find_each do |p|
project_total_size = 0
container_repositories = p.container_repositories
container_repositories.each do |c|
c.tags.each do |t|
project_total_size = project_total_size + t.total_size unless t.total_size.nil?
end
end
if project_total_size > 0
projects_and_size << [p.project_id, p.creator&.id, project_total_size, p.full_path]
end
end
# print it as comma separated output
projects_and_size.each do |ps|
puts "%s,%s,%s,%s" % ps
end
Note that Roger Lehmann's answer is deprecated. If your repositories are nested, you will miss projects. Additionally, from experience, it seems to under-count the disk space used by the the repositories it finds. It will also skip repositories that are created with Gitlab 14 and up.