Package: gitlab-registry-usage
GitLab-Registry-UsageIntroductionGitLab-Registry-Usageis a package for querying the sizes of Docker repositories stored in a GitLab registry. The
package has been created because it is not possible to monitor sizes of GitLab registry repositories with GitLab web
monitoring tools (GitLab version <= 10.5.4).InstallationThe latest version is available from PyPI:pipinstallgitlab-registry-usageIf you use Arch Linux or one of its derivatives, you can also installgitlab-registry-usagefrom theAUR:yay-Spython-gitlab-registry-usageOptionally, you can also use Docker:dockerbuild-tgitlab-registry-usage.
dockerrun--rm-itgitlab-registry-usage--helpUsageCommand Line InterfaceAfter installing withpip, agitlab-registry-usagecommand is available:$gitlab-registry-usage--help
usage:gitlab-registry-usage[-h][-gGITLAB_SERVER][-rREGISTRY_SERVER][-s{name,size,disksize}][-cCREDENTIALS_FILE][-uUSERNAME][-V][-v|--debug]gitlab-registry-usageisautilityforqueryingthememoryusageofrepositoriesinaGitLabregistry.

optionalarguments:-h,--helpshowthishelpmessageandexit-gGITLAB_SERVER,--gitlab-serverGITLAB_SERVERGitLabserverhostname(forexample`mygitlab.com`)-rREGISTRY_SERVER,--registry-serverREGISTRY_SERVERGitLabregistryserverhostname(forexample`registry.mygitlab.com`)-s{name,size,disksize},--sort{name,size,disksize}sortingorder(default:name)-cCREDENTIALS_FILE,--credentials-fileCREDENTIALS_FILEpathtoafilecontainingusernameandpassword/accesstoken(ontwoseparatelines)-uUSERNAME,--userUSERNAMEuseraccountforqueryingtheGitLabAPI(default:root)-V,--versionprinttheversionnumberandexit-v,--verbosebeverbose--debugprintdebugmessagesYou should specify a GitLab server hostname (-g), a GitLab registry server hostname (-r) and either a credentials
file (-c) or username (-u) and password (read from stdin).APIThe module offers a high levelGitLabRegistryclass to query the repository catalog and repository sizes. This example
prints all repositories, tags and their sizes:fromgitlab_registry_usageimportGitLabRegistry# TODO: set these values!gitlab_base_url=''registry_base_url=''username='root'access_token='0000000000'gitlab_registry=GitLabRegistry(gitlab_base_url,registry_base_url,username,access_token)forrepositoryingitlab_registry.repository_tags.keys():repository_tags=gitlab_registry.repository_tags[repository]repository_size=gitlab_registry.repository_sizes[repository]repository_disk_size=gitlab_registry.repository_disk_sizes[repository]tag_sizes=gitlab_registry.tag_sizes[repository]tag_disk_sizes=gitlab_registry.tag_disk_sizes[repository]if(repository_tagsisnotNoneandrepository_sizeisnotNoneandrepository_disk_sizeisnotNoneandtag_sizesisnotNoneandtag_disk_sizesisnotNone):print('{}: repository size:{}, repository disk size:{}'.format(repository,repository_size,repository_disk_size))fortaginrepository_tags:print('{}: tag size:{}, tag disk size:{}'.format(tag,tag_sizes[tag],tag_disk_sizes[tag]))else:print('{}: no further information available'.format(repository))print()print(('total size:{}, total disk size:{}').format(gitlab_registry.total_size,gitlab_registry.total_disk_size))The methoddelete_imagecan be used to delete a particular image if the corresponding SHA256 hash is known.