Detect added packages in CI/CD pipeline using docker and GitLab

i am currently working on deploying an R application via a CI/CD pipeline. Right now i have an DockerfileBase, which builds to an image containing all the R libraries needed for the project. Now i want to somehow integrate the functionality that somehow it is detected when a library is added to the DockerfileBase and only then this image is rebuild. Does anybody have an idea on how to do a thing like that?

Thank you for your help!

Source: Docker Questions