npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gitlab-registry-cleaner-cli

v0.3.2

Published

Gitlab Registry Cleaner CLI

Downloads

13

Readme

Gitlab Registry Cleaner CLI (grc)

npm NPM npm

Hello there! :wave:

This is my first real (kinda) open source project. It is a container registry cleaner cli tool for Gitlab. You can get statistics about your image tags, or bulk-delete some of them based on suffixes. This tool is useful when you want to cleanup unused and old images within your self-hosted Gitlab instance in bulks. There are other projects like this one (mentioned below) but as far as i can see, all of them are focused on single project cleaning, which you need to setup per project and that is a lot of work! I needed a bulk-cleaner that i can run and clean all of the images in my Gitlab instance and this project was born.

Installation

You can download the tool via npm or yarn using the following commands:

# with npm
npm install --global gitlab-registry-cleaner-cli

# with yarn
yarn global add gitlab-registry-cleaner-cli

Or, you can get fetch the binary suitable for your OS from the Releases page.

Usage

You can use the tool with the grc command (grc --help for all the available commands and options).

Commands

  • stats: Get image statistics. Uses group-tags-regex option for calculating a group-by-summary
  • cleanup: Cleanup images according to options
  • check: Check options and Gitlab connection (debug command)

Options

You can provide options to the commands in various ways.

  • As command line arguments (eg. --gitlab-base-url)
  • As env variables (eg. GITLAB_BASE_URL)
  • From a JSON file either using the default config paths or providing a path with --config-path option. Default config file paths are .grc.json and $home/.grc.json so these files are picked up by default.

Here is a list of options with their env variable forms and default values:

  • gitlab-base-url or url: Base URL of the Gitlab instance. Env variable: GRC_GITLAB_BASE_URL. No default value. This option is required for the tool to function.
  • gitlab-token or token: Gitlab access token authorized for deleting images. Env variable: GRC_GITLAB_TOKEN. No default value. This option is required for the tool to function.
  • keen-n: Do not delete n number of latest image tags. Env variable: GRC_KEEP_N. Default value is 5.
  • older-than: Delete image tags older than given time (eg. 5d, 1h). Env variable: GRC_OLDER_THAN. Default value is 7d.
  • group-tags-regex: Group image tags by given regex when showing image stats or a list of groups to delete. Env variable: GRC_GROUP_TAGS_REGEX. Default value is /^[a-zA-Z0-9.]+(-[0-9]+)?-(.\*)$/.
  • delete-tags-regex: Delete image tags with the given regex. No list will be prompted if this option is provided and --group-tags-regex option will be ignored. Env variable: GRC_DELETE_TAGS_SUFFIX. No default value.
  • config-path: Config file path for getting the option values from. Env variable: GRC_CONFIG_PATH. Default value is $HOME/.grc.
  • dry-run: Do not actually delete the image tags. Env variable: GRC_DRY_RUN. Default value is false.
  • verbose or v: More detailed logs (3 levels: -v, -vv, -vvv).
  • yes: Do not ask for confirmation before deleting images. This can be used for non-interactive operations (ci/cd or cronjobs).

Example config file content:

{
  "gitlabBaseUrl": "https://git.mycompany.com", // or url (required)
  "gitlabToken": "abcdef", // or token (required)
  "keepN": 3,
  "olderThan": "3d",
  "groupTagsRegex": "/[a-zA-Z0-9.]+-(.*)/",
  "deleteTagsRegex": ".*-dev",
  "dryRun": true
}

Options are taken in the following order:

  1. Command line arguments
  2. Env variables
  3. Config file
  4. Default values

Credits

Credits are due for the following awesome libraries:

  • yargs - for easy cli creation (commands, options, help, etc.)
  • @clack/prompts - for beautiful, step-by-step style cli prompts
  • also chalk and boxen - for further styling

Also there are other alternatives as far as I can see like the ones below. But I haven't seen any that can delete images in bulk so I created yet another one :sweat_smile:

  • https://github.com/10up/Gitlab-Registry-Cleaner
  • https://github.com/sciapp/gitlab-registry-cleanup
  • https://github.com/n0madic/gitlab-registry-images-cleaner
  • https://github.com/ivanetchart/gitlab-registry-cleaner

Contributing

This is like a hobby project for me but I'm open to suggestions and contributions for making it more useful.