This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.py
60 lines (48 loc) · 1.61 KB
/
launcher.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
import os
import subprocess
def launch_backend():
app_name = "backend"
app_config_path = os.path.join(app_name, "docker-compose.yaml")
print(f"Launching {app_name}...")
subprocess.run(["docker-compose", "-f", app_config_path, "up", "-d"])
print("App launched successfully!")
def launch_frontend():
try:
print("Launching frontend...")
os.chdir("./frontend")
subprocess.check_call(['npm', 'install'])
subprocess.Popen(['npm', 'start'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
os.chdir("../")
except subprocess.CalledProcessError as e:
print(f"An error occurred while running the Node.js application: {e}")
def launch_network():
pass
APP_CONFIGS = {
"backend": launch_backend,
"frontend": launch_frontend,
"network": launch_network
}
def display_menu():
print("=== Launcher ===")
print("Required: Docker, Docker Compose, Python 3.6+, node")
print("Select an app to launch:")
for idx, app_name in enumerate(APP_CONFIGS.keys(), start=1):
print(f"{idx}. {app_name}")
print("0. Exit")
def main():
while True:
display_menu()
choice = input("Enter your choice: ")
if choice == "0":
break
try:
choice_idx = int(choice)
if choice_idx < 1 or choice_idx > len(APP_CONFIGS):
raise ValueError
except ValueError:
print("Invalid choice. Please try again.")
continue
app_name = list(APP_CONFIGS.keys())[choice_idx - 1]
APP_CONFIGS[app_name]()
if __name__ == "__main__":
main()