Skip to content

Commit

Permalink
use podman create, init and rm instead of run and kill
Browse files Browse the repository at this point in the history
  • Loading branch information
ricffb committed Dec 9, 2024
1 parent d065835 commit 2aac8ce
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions contrib/vcloud/podman_containerized_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def _init_container(

# Create a container that does nothing but keeps running
command = (
["podman", "run", "--entrypoint", "tail", "--rm", "-d"]
["podman", "create", "--entrypoint", '[""]', "--rm"]
+ volumes
+ [image, "-F", "/dev/null"]
+ [image, "/bin/sh"]
)

logging.debug(
Expand All @@ -71,15 +71,26 @@ def _init_container(
res = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
check=True,
)

res.check_returncode()
container_id = res.stdout.decode().strip()

subprocess.run(
["podman", "init", container_id],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
)

container_pid = (
subprocess.run(
["podman", "inspect", "--format", "{{.State.Pid}}", container_id],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
)
.stdout.decode()
.strip()
Expand Down Expand Up @@ -161,7 +172,7 @@ def close(self):
return
try:
subprocess.run(
["podman", "kill", "--signal", "SIGKILL", self.container_id],
["podman", "rm", self.container_id],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
Expand Down

0 comments on commit 2aac8ce

Please sign in to comment.