feat: Add task to clean up containers with deleted roles #1524
+59
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This merge request introduces a new task, app:deleted_roles, to the deploy process. This task is designed to address an existing issue where containers associated with roles that have been deleted from the configuration persist indefinitely on the server.
Currently, when a role is removed from the application configuration, any running containers previously assigned that role are not automatically cleaned up. This can lead to an accumulation of orphaned containers over time, which is not only inefficient but also poses a potential security risk as these containers might be running outdated or vulnerable code.
The app:deleted_roles task identifies these orphaned containers by comparing the roles present in the current configuration with the roles inferred from the names of existing containers. Containers whose roles are no longer defined in the configuration are then targeted for removal.
This task is strategically placed in the deploy process to run after the stale_containers task, ensuring a comprehensive cleanup of both stale and orphaned containers during a normal deployment.
Implementation Details
The current implementation infers the deleted role name from the container name. While this approach is not ideal and relies on consistent naming conventions, it provides a functional solution for the immediate problem. At this time, i cannot foresee situations where this guessing mechanism would lead to incorrect container identification and deletion, given our current deployment patterns. Future improvements could involve storing role information more explicitly with the container metadata.