GitLab-Registry-Cleanup
Introduction
GitLab-Registry-Cleanup is a Python package for finding and (soft) deleting untagged Docker images in a GitLab Docker registry. Currently (April 2018), Docker registries only cleanup data if the removal of an image is requested explicitly by the user. Therefore, the registry will keep on growing if users only push new images. Overwriting existing tags is not sufficient since images could be referenced by their SHA256 hash by an external resource. This tool assumes that untagged images are not needed any more and deletes them explicitly. It can only be used for the embedded registry of a GitLab server.
NOTE: registry garbage-collect will have a -m flag in 2.7.0, see issue #1844 and pull request #2302.
Installation
The latest version is available from PyPI and needs Python 3.3+:
python3 -m pip install gitlab-registry-cleanup
This package can only be used on a GitLab server, since it needs read access to the Docker registry files stored on disk. The script needs root privileges, so either use the root account or the sudo utility. The actual deletion of images is done via the GitLab web api to prevent any data loss.
If you use the recommended operating system for GitLab (Ubuntu Server), you can install Python 3 and pip with
apt install python3-pip
if not already installed.
Usage
Command Line Interface
After installing with pip, a gitlab-registry-cleanup command is available:
usage: gitlab-registry-cleanup [-h] [-g GITLAB_SERVER] [-r REGISTRY_SERVER]
[-p LOCAL_REGISTRY_ROOT] [-c CREDENTIALS_FILE]
[-u USERNAME] [-n] [-k] [-V]
gitlab-registry-cleanup is a utility for cleaning up a GitLab registry by soft deleting untagged images.
optional arguments:
-h, --help show this help message and exit
-g GITLAB_SERVER, --gitlab-server GITLAB_SERVER
GitLab server hostname (for example `mygitlab.com`)
-r REGISTRY_SERVER, --registry-server REGISTRY_SERVER
GitLab registry server hostname (for example
`registry.mygitlab.com`)
-p LOCAL_REGISTRY_ROOT, --registry-path LOCAL_REGISTRY_ROOT
Path to the registry directory on the GitLab server
(default: /var/opt/gitlab/gitlab-
rails/shared/registry)
-c CREDENTIALS_FILE, --credentials-file CREDENTIALS_FILE
path to a file containing username and password/access
token (on two separate lines)
-u USERNAME, --user USERNAME
user account for querying the GitLab API (default:
root)
-n, --dry-run only print which images would be deleted
-k, --insecure allow insecure connections over plain HTTP
-V, --version print the version number and exit
You 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).
Final disk cleanup
gitlab-registry-cleanup only soft deletes images. As a result, images are removed but their data (the image layers) are still stored on disk. To delete unused image layers, you must run the Docker registry garbage collector. If you have installed the GitLab omnibus package, you can run the following commands:
sudo gitlab-ctl registry-garbage-collect
Metadata
Release files for gitlab-registry-cleanup 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gitlab-registry-cleanup-0.1.7.tar.gz | 8.3 kB | Without provenance | Details for gitlab-registry-cleanup-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gitlab_registry_cleanup-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for gitlab_registry_cleanup-0.1.7-py3-none-any.whl |
Total release size: 16.7 kB
Release files / gitlab-registry-cleanup-0.1.7.tar.gz
| Download URL | gitlab-registry-cleanup-0.1.7.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c223fb72c942d0ece51e2981d4a17f9cf3676329572272f070d7d38dae574b52
|
|
BLAKE2b-256 checksum How to use checksums |
8cae2a3898ab813c63553c165910ca6265132382e2f4b47de043c04b0958db8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
|
Release files / gitlab_registry_cleanup-0.1.7-py3-none-any.whl
| Download URL | gitlab_registry_cleanup-0.1.7-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bb61ac6d33c7a1a00056c9c82e548b187bd51ea438605914d37dc23ca31e459
|
|
BLAKE2b-256 checksum How to use checksums |
ae03b6e7268b8ebba7c8636f56249597877fb9763880aa26051a00c3b34ab8ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
|
Security for gitlab-registry-cleanup 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.