From c4024271ff368de857f3ae9d9ecd8df72d35504a Mon Sep 17 00:00:00 2001 From: Ryan Roberts Date: Wed, 8 May 2024 11:00:51 +0100 Subject: [PATCH] runtime: Ensure container gets cleaned up on shutdown Recent refactoring to simplify the Runtime class inadvertantly removed the cleanup code. As a result, a container would not be stopped and removed when shrinkwrap exits but would linger, using system resources. Fix that by reintroducing the cleanup code. Fixes: 1db05f5 ("runtime: replace modal stack with singleton") Signed-off-by: Ryan Roberts --- shrinkwrap/utils/runtime.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shrinkwrap/utils/runtime.py b/shrinkwrap/utils/runtime.py index 9b564c0..52be694 100644 --- a/shrinkwrap/utils/runtime.py +++ b/shrinkwrap/utils/runtime.py @@ -131,17 +131,20 @@ print(ip) if res.returncode == 0: return res.stdout.strip() return '127.0.0.1' - + def __enter__(self): global _instance assert _instance is None _instance = self return self - + def __exit__(self, exc_type, exc_val, exc_tb): global _instance assert _instance == self _instance = None + if self._rt: + self._rt.cleanup() + self._rt = None def get(): -- GitLab