Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove containers cli flag #973

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/popper/commands/cmd_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
required=False,
is_flag=True,
)
@click.option(
"--remove",
help="Remove containers after execution.",
required=False,
is_flag=True,
)
@click.option(
"-e",
"--engine",
Expand Down Expand Up @@ -127,6 +133,7 @@ def cli(
log_file,
quiet,
reuse,
remove,
engine,
resource_manager,
skip,
Expand Down Expand Up @@ -184,6 +191,7 @@ def cli(
resman_name=resource_manager,
config_file=conf,
reuse=reuse,
remove=remove,
dry_run=dry_run,
skip_pull=skip_pull,
skip_clone=skip_clone,
Expand Down
2 changes: 2 additions & 0 deletions src/popper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def load(
config_file=None,
workspace_dir=os.getcwd(),
reuse=False,
remove=False,
dry_run=False,
quiet=False,
skip_pull=False,
Expand Down Expand Up @@ -44,6 +45,7 @@ def load(
pp_config = {
"workspace_dir": workspace_dir,
"reuse": reuse,
"remove": remove,
"dry_run": dry_run,
"quiet": quiet,
"skip_pull": skip_pull,
Expand Down
9 changes: 9 additions & 0 deletions src/popper/runner_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def __init__(self, **kw):
if self._config.reuse:
log.warning("Reuse not supported for HostRunner.")

if self._config.remove:
log.warning("Remove not supported for HostRunner.")

def __enter__(self):
return self

Expand Down Expand Up @@ -165,6 +168,9 @@ def run(self, step):
log.step_info(line.decode().rstrip())

e = container.wait()["StatusCode"]

if self._config.remove:
container.remove(force=True)
except Exception as exc:
log.fail(exc)
return e
Expand Down Expand Up @@ -254,6 +260,9 @@ class PodmanRunner(StepRunner):
def __init__(self, init_podman_client=True, **kw):
super(PodmanRunner, self).__init__(**kw)

if self._config.remove:
log.warning("Remove not supported for PodmanRunner.")

self._spawned_containers = set()

if not init_podman_client:
Expand Down
2 changes: 2 additions & 0 deletions src/popper/runner_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def __init__(self, **kw):
super(SingularityRunner, self).__init__(init_spython_client=False, **kw)
if self._config.reuse:
log.fail("Reuse not supported for SingularityRunner.")
if self._config.remove:
log.fail("Remove not supported for SingularityRunner.")

singularity_executables = ["singularity"]
for exe in singularity_executables:
Expand Down
2 changes: 2 additions & 0 deletions src/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_config_defaults(self):
"workspace_dir": os.getcwd(),
"quiet": False,
"reuse": False,
"remove": False,
"pty": False,
"allow_undefined_secrets_in_ci": False,
},
Expand All @@ -46,6 +47,7 @@ def test_config_non_defaults(self):
"workspace_dir": os.path.realpath("/tmp/foo"),
"quiet": True,
"reuse": True,
"remove": True,
"pty": True,
"allow_undefined_secrets_in_ci": True,
}
Expand Down