How to clear obsolete docker images created via Jenkins CI/CD?
I have created a CI/CD Jenkins Pipeline which does the following tasks
- Run a gradle build. The gradle build does the next set of tasks
- Build several springboot microservices
- Create a docker image for each of the micro-service
- It pushes the images to a private Docker registry
- Execute helm templates to create/refresh the k8s deployments in a k8s cluster.
While the entire process works well. I am looking for a solution for a couple of scenarios.
- Since it is CI/CD the build is triggered for every code push. So, the docker images in the private registry will be created as well and eventually eat up all the disk space. How do I conditionally clear the docker images?
- If a script is developed to use the docker REST APIs to clear the images how do I conditionally skip to delete certain images (ex: images related to tagged Jenkins builds)
- Are there any recommendations or standards for this task?