Skip to content

Clean docker images and manifests with custom rules from the registry.

License

Notifications You must be signed in to change notification settings

onuryartasi/registry-cleaner

Repository files navigation

Registry Cleaner

Easy delete manifests and images from your own registry
Explore the docs »

View Demo · Report Bug · Request Feature

GitHub GitHub tag (latest SemVer) GitHub issues

About The Project

This project's aim is to delete unnecessary images and manifests from your own docker registry. Azure container registry (aka ACR) has purge command, Gitlab registry has a cleanup policy, etc. Registry-cleaner has a configuration for custom rules like GitLab cleanup policy.

Getting Started

Prerequisite

Go

Installation

  1. Get a release compatible your system from github.

Or

  1. Clone the repo
    git clone https://github.com/onuryartasi/regitry-cleaner.git
  2. Install go modules.
     go mod download
  3. Build source code.
     go build -o registry-cleaner main.go 
  4. Configure your rules config.yaml
     regex:
     enable: true
     pattern:
       - group/image-name

Usage

Before usage this tool enable delete function from registry.(https://docs.docker.com/registry/configuration/#delete). You can use env variable REGISTRY_STORAGE_DELETE_ENABLED=true for deletable registry from api.

See parameters.

  -config-file string
        Config file path. (default "config.yaml")
  -dry-run
        Print deletable images, don't remove.
  -host string
        Registry host (default "localhost")
  -password string
        Registry password
  -username string
        Registry username

Before use to registry-cleaner configure your own rules for according to your needs. There is a example config file.

#Regex pattern, you can run own regex rules for images.
regex: 
  # If you enable false can't apply this pattern on your images.
  enable: true 
  pattern:
    # Delete images to match those pattern. Multi pattern accaptable.
    - g1/hello-world
    - g2*

# Until-date pattern, when give a date delete all images before this date.
until-date: 
  enable: true
  #### Example date layout
  ###  02.01.2006 15:04:05
  ###  02.01.2006 15:04
  ###  02.01.2006
  date: "31.05.2021"

# N pattern, just latest n images  will be stored. other images will be delete.
n: 
  enable: false
  size: 10 # Number of to image to keeping.
registry-cleaner -host http://localhost:5000 -config-file="config.yaml"

registry-cleaner -host http://localhost:5000 -username admin -password changeme -config-file="config.yaml"

After all of them, manually run a garbage collector in your registry if you want to immediately delete images.

registry garbage-collect /etc/docker/registry/config.yml

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazinFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.md for more information.

About

Clean docker images and manifests with custom rules from the registry.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published