-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch.py
63 lines (52 loc) · 1.59 KB
/
launch.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import subprocess
import os
import logging
logger = logging.getLogger("launch")
logging.basicConfig(level=logging.INFO, format='%(message)s')
class SystemLaunched:
def __init__(self, dir):
self.path = dir
self.oldpath = os.getcwd()
def __enter__(self):
logger.debug("Launch environment...")
os.chdir(self.path)
self.unlaunch()
self.launch()
def __exit__(self, *args):
logger.debug("Undeploy environment...")
self.unlaunch()
os.chdir(self.oldpath)
def unlaunch(self):
proc = subprocess.run(
[
"podman-compose", "-f", "launch.yaml",
"down", "-v", "-t", "0"
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
if proc.returncode != 0:
raise RuntimeError("Clearout failed")
def launch(self):
logger.debug("Pulling containers...")
proc = subprocess.run(
[
"podman-compose", "-f", "launch.yaml",
"pull"
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
logger.debug("Deploy containers...")
proc = subprocess.run(
[
"podman-compose", "-f", "launch.yaml",
"up", "-d"
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
if proc.returncode != 0:
raise RuntimeError("Clearout failed")
if proc.returncode != 0:
raise RuntimeError("Clearout failed")