-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
executable file
·103 lines (68 loc) · 2.55 KB
/
configure.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import os
from shutil import which
cwd = os.getcwd()
def command_exists(name):
"""Check whether `name` is in the PATH"""
return which(name, os.F_OK) is not None
def is_valid_csv_entry(L, Omitted):
"""Ensures L is not blank and is not `Omitted`"""
return L != Omitted and L not in ['\n', '\r\n'] and L != ''
def check_dependencies():
"""Iterate `dependencies.csv`, checking whether each line exists
on the system as an executable"""
print("Checking required dependencies...")
with open(f'{cwd}/dependencies.csv') as deps:
for d in deps:
d = d.strip()
valid_entry = is_valid_csv_entry(d, "dependency_name")
if not valid_entry:
continue
if command_exists(d) is False:
print(f"{d} Isn't installed. Install to continue")
exit(1)
print("All dependencies met")
def build_db_schema():
"""Converts dbml schema to sql file, which can be inserted into the db"""
# We can handle this dependency differently, as dbml2sql can be installed
# using npm
if not command_exists("dbml2sql"):
print("Installing dbml2sql")
os.system('npm i -g @dbml/cli')
print("Converting dbml to sql")
base_path = f"{cwd}/aimless/db"
in_path = f"{base_path}/db-schema.dbml"
out_path = f"{base_path}/db-schema.sql"
os.system(f"dbml2sql {in_path} --mysql -o {out_path}")
def build_container(container_name):
"""Builds Docker container from Dockefile in ./aimless/`container_name`"""
path = f"{cwd}/{container_name}"
tag = path.split('/')[-1]
tag = f"aimless-{tag}"
if not os.path.isdir(path):
print(f"ERROR: {path} does not exist when trying to build: {tag}")
exit(1)
print(f"Building service: {tag}")
try:
if os.system(f"docker build -t {tag} {path}") != 0:
raise Exception
except Exception:
print(f"Error occured whilst building: {tag}")
exit(1)
def build_all_containers():
"""Builds all containers found in `./service-names.csv`"""
with open(f"{cwd}/service-names.csv") as services:
for C in services:
C = C.strip()
valid_service = is_valid_csv_entry(C, "service_name")
# Skip blank lines and csv header
if not valid_service:
continue
build_container(C)
########################
# Start of main script #
########################
check_dependencies()
build_db_schema()
build_all_containers()
os.system('docker compose up -d')