planetary-social / ansible-scripts

Ansible automation scripts used at Planetary
MIT License
2 stars 3 forks source link

Prune docker images when running image update service #69

Closed cooldracula closed 6 months ago

cooldracula commented 6 months ago

This PR addresses https://github.com/planetary-social/infrastructure/issues/98

For the services that are deployed with docker images, we include a set of tasks that add a systemd service for checking the latest docker image and updating if necessary. It made the most sense to add a pruning step to this service, so the service will poll our registry, pull an new image if it's necessary, update the deployment to the new image, and then run docker system prune -af to remove any older, dangling images.

I realized in this issue that there was room for improvement in the ansible scripts, as each service included this basically identical systemd task, and to make the change above I'd need to change it across multiple roles. So instead, I created a small role specifically for the image update service, and then include that role in the relevant service roles: nos-crossposting-service, nos-notification-service, nos-event-service, nostrface, and rsslay.

While updating these roles, I did some further refinements where needed. This PR ended up bigger than initially intended, but all work is relevant to the task and did not make sense to include in smaller separate PR's.

The image update service can be read here

An example of it's inclusion in a larger role can be seen here