-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-with-podman
executable file
·30 lines (23 loc) · 1022 Bytes
/
run-with-podman
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
import os
import subprocess
import sys
default_command = ["mvn", "spring-boot:run"]
command = sys.argv[1:] or default_command
p = subprocess.run(["systemctl", "show", "--user", "podman.socket"], check=True, stdout=subprocess.PIPE, encoding="utf8")
podman_socket_status = dict(map(lambda l: l.split("=", 1), p.stdout.splitlines()))
podman_socket_active = podman_socket_status["ActiveState"] == "active"
if not podman_socket_active:
print(f"podman socket active {podman_socket_active}, starting")
subprocess.run(["systemctl", "start", "--user", "podman.socket"], check=True)
try:
xdg_runtime_dir = os.environ["XDG_RUNTIME_DIR"]
env = {
"DOCKER_HOST": f"unix://{xdg_runtime_dir}/podman/podman.sock",
"TESTCONTAINERS_RYUK_DISABLED": "true",
}
subprocess.run(command, check=True, env=env)
finally:
if not podman_socket_active:
print(f"stopping podman socket")
subprocess.run(["systemctl", "stop", "--user", "podman.socket"], check=True)