Google Cloud Platform is a great platform for hosting our clients application. We make use of Docker for our containers and Kubernetes for managing these containers.
We always have two GCP projects for a client application. One production and one development project. After each commit and push to Bitbucket we run a CircleCI workflow and pushing the created images to Google Cloud Container Registry. The development branch get pushed to the development project and the master branch get pushed to the production project.
The Container Registry stores the images in buckets and the amount of GB used is what you are charged for. So after 200 commits we have a lot of GB stored in that bucket and for that we are being charged. Especially the development project get filled up quickly.
Manually deleting these images is cumbersome work. So I’ve created a shell script to delete the old untagged and tagged images and leave a given number of images in tact.
My script is based on this neat little script: https://gist.github.com/ahmetb/7ce6d741bd5baa194a3fac6b1fec8bb7
You can find my script here: https://gist.github.com/DaanGeurts/d95f67578d0e6f39fee05ff5e2375dc3
I’m happy to receive feedback and improvements on the script.