This is a tool that enables you automate digitalocean container registry cleanup to create more memory space. It deletes old images from the registry, deletes the manifests for the images, and starts the garbage collection process to clear and reset the container registry available memory hence saving you extra expenses.
This is perfect if you push updates constantly to the digitalocean container registry, and you need to manage the registry garbage collection process automatically. This can be setup to run automatically as part of your CI/CD process.
Golang installation
Ensure you have golang installed
Give Bash Scripts Permission
Give executable permission to the bash scripts
chmod 755 build.sh
chmod 755 run.shBuild executable script
run the command below to build the go program and creates an executable file.
./build.shRun executable script
run the command below to run the executable file.
./run.sh args1 args2 args3 args4The arguments to be specified are defined below:
args1 - digitalocean api token
args2 - container registry name
args3 - the minimum number of images to be left in your registry
args4 - the maximum percentage of memory used before cleaning can occur
There are two ways to run this program manually, either via the main golang program file or via the cli golang program file.
Via the main go file
Export the following variables to your environment:
export DIGITALOCEAN_TOKEN={Digitalocean api token}
export REGISTRY={Digitalocean container registry name}
export MAX_IMAGE_COUNT={Maximum number of images allowed to be left after cleaning}
export PERCENTAGE_THRESHOLD={Percentage threshold of memory used before cleaning can occur}Run go program
go run main.goVia the CLI go file
Navigate to CMD directory
cd cmdRun go program
go run clean_registry.go -token {Digitalocean api token} -registry {Digitalocean container registry name} -count {the minimum number of images to be left in your registry} -percentage {the maximum percentage of memory used before cleaning can occur}