2019-12-28 22:52:01 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-10-23 00:18:38 +02:00
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import yaml
|
2019-12-28 22:52:01 +01:00
|
|
|
import jinja2
|
|
|
|
|
2023-10-23 00:18:38 +02:00
|
|
|
# Load settings file
|
|
|
|
with open("DockerSettings.yaml", 'r') as yaml_file:
|
|
|
|
yaml_data = yaml.safe_load(yaml_file)
|
|
|
|
|
|
|
|
settings_env = jinja2.Environment(
|
|
|
|
loader=jinja2.FileSystemLoader(os.getcwd()),
|
|
|
|
)
|
|
|
|
settings_yaml = yaml.safe_load(settings_env.get_template("DockerSettings.yaml").render(yaml_data))
|
|
|
|
|
2019-12-28 22:52:01 +01:00
|
|
|
args_parser = argparse.ArgumentParser()
|
|
|
|
args_parser.add_argument('template_file', help='Jinja2 template file to render.')
|
|
|
|
args_parser.add_argument('render_vars', help='JSON-encoded data to pass to the templating engine.')
|
|
|
|
cli_args = args_parser.parse_args()
|
|
|
|
|
2023-10-23 00:18:38 +02:00
|
|
|
# Merge the default config yaml with the json arguments given.
|
2019-12-28 22:52:01 +01:00
|
|
|
render_vars = json.loads(cli_args.render_vars)
|
2023-10-23 00:18:38 +02:00
|
|
|
settings_yaml.update(render_vars)
|
|
|
|
|
2019-12-28 22:52:01 +01:00
|
|
|
environment = jinja2.Environment(
|
|
|
|
loader=jinja2.FileSystemLoader(os.getcwd()),
|
|
|
|
trim_blocks=True,
|
|
|
|
)
|
2023-10-23 00:18:38 +02:00
|
|
|
print(environment.get_template(cli_args.template_file).render(settings_yaml))
|