-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
35 lines (27 loc) · 939 Bytes
/
generate.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
import sys
import os
from yaml import load, BaseLoader
from jinja2 import FileSystemLoader, Environment, select_autoescape
def usage() -> str:
return """Usage: <context> <compose> <version>
context: path to the context
compose: output path for the compose file
version: the version used to tag the images
"""
if len(sys.argv) != 4:
print(usage())
exit(1)
context = sys.argv[1]
if not os.path.exists(context) or not os.path.isfile(context):
print("Context file not found.")
exit(1)
compose = sys.argv[2]
version = sys.argv[3]
version = "latest" if version == "master" else version
env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape(), trim_blocks=True, lstrip_blocks=True)
template = env.get_template("compose.tmpl")
with open(context, "r") as fd:
context = load(fd, BaseLoader)
context['version'] = version
with open(compose, "w") as fd:
fd.write(template.render(context))