From 06237fb143da63a348685f302e31a9bcc98e7de1 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Wed, 11 Feb 2026 09:59:54 -0600 Subject: [PATCH] Changed invoke commands to remove orphaned containers by default --- changes/810.housekeeping | 1 + tasks.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changes/810.housekeeping diff --git a/changes/810.housekeeping b/changes/810.housekeeping new file mode 100644 index 00000000..13dfe48d --- /dev/null +++ b/changes/810.housekeeping @@ -0,0 +1 @@ +Changed many invoke tasks to remove the container after running the command by default. \ No newline at end of file diff --git a/tasks.py b/tasks.py index 84805a24..86acbe74 100644 --- a/tasks.py +++ b/tasks.py @@ -66,13 +66,14 @@ def task_wrapper(function=None): return task_wrapper -def run_command(context, exec_cmd, port=None): +def run_command(context, exec_cmd, port=None, rm=True): """Wrapper to run the invoke task commands. Args: context ([invoke.task]): Invoke task object. exec_cmd ([str]): Command to run. port (int): Used to serve local docs. + rm (bool): Whether to remove the container after running the command. Returns: result (obj): Contains Invoke result from running task. @@ -86,12 +87,12 @@ def run_command(context, exec_cmd, port=None): ) if port: result = context.run( - f"docker run -it -p {port} -v {context.netutils.pwd}:/local {context.netutils.image_name}:{context.netutils.image_ver} sh -c '{exec_cmd}'", + f"docker run -it {'--rm' if rm else ''} -p {port} -v {context.netutils.pwd}:/local {context.netutils.image_name}:{context.netutils.image_ver} sh -c '{exec_cmd}'", pty=True, ) else: result = context.run( - f"docker run -it -v {context.netutils.pwd}:/local {context.netutils.image_name}:{context.netutils.image_ver} sh -c '{exec_cmd}'", + f"docker run -it {'--rm' if rm else ''} -v {context.netutils.pwd}:/local {context.netutils.image_name}:{context.netutils.image_ver} sh -c '{exec_cmd}'", pty=True, )