refactor(docker): move force_remove_container into the docker util module
The helper is a thin subprocess wrapper over `container_exists` + `docker rm -f`, so it belongs alongside the other docker primitives in util.py rather than as a private in launch.py. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -72,7 +72,7 @@ def launch(
|
||||
stack.callback(proxy.stop, pipelock_name)
|
||||
|
||||
container = _run_agent_container(plan, internal_network)
|
||||
stack.callback(_force_remove_container, container)
|
||||
stack.callback(docker_mod.force_remove_container, container)
|
||||
|
||||
prompt_path = provision(plan, container)
|
||||
|
||||
@@ -135,11 +135,3 @@ def _run_agent_container(plan: DockerBottlePlan, internal_network: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def _force_remove_container(name: str) -> None:
|
||||
if docker_mod.container_exists(name):
|
||||
subprocess.run(
|
||||
["docker", "rm", "-f", name],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=False,
|
||||
)
|
||||
|
||||
@@ -64,6 +64,19 @@ def container_exists(name: str) -> bool:
|
||||
return bool(result.stdout.strip())
|
||||
|
||||
|
||||
def force_remove_container(name: str) -> None:
|
||||
"""`docker rm -f` the named container if it exists. No-op if it
|
||||
doesn't — and the rm itself is best-effort (errors swallowed) so
|
||||
this is safe to register as a teardown callback."""
|
||||
if container_exists(name):
|
||||
subprocess.run(
|
||||
["docker", "rm", "-f", name],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=False,
|
||||
)
|
||||
|
||||
|
||||
def docker_exec_root(container: str, argv: list[str]) -> None:
|
||||
"""Run `docker exec -u 0` in the named container, check=True. Used
|
||||
by SSH provisioning to chown/chmod files that need root."""
|
||||
|
||||
Reference in New Issue
Block a user