forked from OpenOlitor/openolitor-docker-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
118 lines (99 loc) · 5.56 KB
/
generator.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
import json
import sys, getopt
from jinja2 import Environment, FileSystemLoader
def main(argv):
try:
opts, args = getopt.getopt(argv,"h:e:",["env="])
except getopt.GetoptError:
print ('generator.py -e [demo|test|testprod|prod|all]')
sys.exit(2)
if not opts:
print ('generator.py -e [demo|test|testprod|prod|all]')
else:
for opt, arg in opts:
if opt == '-h':
print ('generator.py -e [test|testprod|prod|all]')
sys.exit()
elif opt in ("-e", "--environment"):
if (arg == "all"):
createTemplates("test")
createTemplates("testprod")
createTemplates("prod")
createTemplates("demo")
else:
createTemplates(arg)
else:
print ('generator.py -e [demo|test|testprod|prod|all]')
def createTemplates(environment):
with open(environment + ".json") as environment_description:
environmentDescription = json.load(environment_description)
#create the docker compose file
file_loader = FileSystemLoader('.')
env = Environment(loader=file_loader)
template = env.get_template('docker-compose.template.yml')
output = template.render(s3 = environmentDescription["s3"],
csas = environmentDescription["csas"],
release_adminportal = environmentDescription["release_adminportal"],
release_kundenportal = environmentDescription["release_kundenportal"],
release_server = environmentDescription["release_server"],
smtpProxy = environmentDescription["smtpProxy"],
db = environmentDescription["db"],
environment = environment)
with open("docker-compose." + environment + ".yml", "w") as dockerComposeFile:
dockerComposeFile.write(output)
#create the db initialization file
file_loader = FileSystemLoader('./config/db')
env = Environment(loader=file_loader)
template = env.get_template('db_schema.template.sql')
output = template.render(csas = environmentDescription["csas"], db = environmentDescription["db"])
with open("./config/db/db_schema." + environment + ".sql", "w") as dbInitialScript:
dbInitialScript.write(output)
#create the admin portal configuration files
file_loader = FileSystemLoader('./config/client/admin')
env = Environment(loader=file_loader)
template = env.get_template('config.template.js')
output = template.render(csas = environmentDescription["csas"],
domain = environmentDescription["domain"],
release_adminportal = environmentDescription["release_adminportal"],
frontendAirbreakApiKey = environmentDescription["frontendAirbreakApiKey"],
airbreakUrl = environmentDescription["airbreakUrl"],
env = environmentDescription["env"])
with open("./config/client/admin/config." + environment + ".js", "w") as dockerAdminPortalConfig:
dockerAdminPortalConfig.write(output)
#create the client portal configuration files
file_loader = FileSystemLoader('./config/client/kundenportal')
env = Environment(loader=file_loader)
template = env.get_template('config.template.js')
output = template.render(csas = environmentDescription["csas"],
domain = environmentDescription["domain"],
release_kundenportal = environmentDescription["release_kundenportal"],
frontendAirbreakApiKey = environmentDescription["frontendAirbreakApiKey"],
airbreakUrl = environmentDescription["airbreakUrl"],
env = environmentDescription["env"])
with open("./config/client/kundenportal/config." + environment + ".js", "w") as dockerKundenPortalConfig:
dockerKundenPortalConfig.write(output)
#create the server configuration file
file_loader = FileSystemLoader('./config/server')
env = Environment(loader=file_loader)
template = env.get_template('openolitor-server.template.conf')
output = template.render(csas = environmentDescription["csas"],
s3 = environmentDescription["s3"],
backendAirbreakApiKey = environmentDescription["backendAirbreakApiKey"],
airbreakUrlShort = environmentDescription["airbreakUrlShort"],
domain = environmentDescription["domain"],
)
with open("./config/server/openolitor-server." + environment + ".conf", "w") as openolitorServerConfigFile:
openolitorServerConfigFile.write(output)
#create the nginx configuration file
file_loader = FileSystemLoader('./config/nginx')
env = Environment(loader=file_loader)
template = env.get_template('nginx.template.conf')
output = template.render(csas = environmentDescription["csas"],
smtpProxy = environmentDescription["smtpProxy"],
exposeSmtpProxy = environmentDescription["exposeSmtpProxy"],
exposePdfTool = environmentDescription["exposePdfTool"])
with open("./config/nginx/nginx." + environment + ".conf", "w") as openolitorNginxConfigFile:
openolitorNginxConfigFile.write(output)
if __name__ == "__main__":
main(sys.argv[1:])