copied from internal repo
This commit is contained in:
64
file_generator/generate_env.py
Normal file
64
file_generator/generate_env.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing env file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "env")
|
||||
template_env_directory = os.path.join(util.get_templates_path(), "env")
|
||||
|
||||
compose_prod = os.path.join(util.get_output_path(), "compose_prod")
|
||||
template_compose_prod = os.path.join(util.get_templates_path(), "compose_prod")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
os.makedirs(os.path.join(util.get_output_path(), "etc"), exist_ok=True)
|
||||
|
||||
shutil.rmtree(compose_prod, ignore_errors=True)
|
||||
shutil.copytree(template_compose_prod, compose_prod)
|
||||
|
||||
file = open(os.path.join(template_env_directory, "config.env"), 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
tenant_data = util.get_minimal_configuration()
|
||||
|
||||
util.copy_file(os.path.join(template_env_directory, "basic_conpeek.ini"), util.get_output_path())
|
||||
|
||||
kamailio_private_ip = config["new_machine_network"]["internal_ip"]
|
||||
if config.has_option('kamailio', 'private_ip'):
|
||||
kamailio_private_ip = config["kamailio"]["private_ip"]
|
||||
|
||||
kamailio_public_ip = config["new_machine_network"]["external_ip"]
|
||||
if config.has_option('kamailio', 'public_ip'):
|
||||
kamailio_public_ip = config["kamailio"]["public_ip"]
|
||||
|
||||
kamailio_nat = '1'
|
||||
if config.has_option('kamailio', 'nat'):
|
||||
kamailio_nat = config["kamailio"]["nat"]
|
||||
|
||||
data = {
|
||||
"MASTER_PASSWORD": config["machine_secrets"]["master_password"],
|
||||
"DEPLOYMENT_TAG": config["deployment_purpose"]["deployment_tag"],
|
||||
"APP_INSTALLATION_DOMAIN": config["new_machine_network"]["app_installation_domain"],
|
||||
"SYSTEM_APP_INSTALLATION_DOMAIN": config["new_machine_network"]["system_app_installation_domain"],
|
||||
"INTERNAL_IP": config["new_machine_network"]["internal_ip"],
|
||||
"EXTERNAL_IP": config["new_machine_network"]["external_ip"],
|
||||
"REPLICASET": config["new_machine_network"]["cluster_name"],
|
||||
"SYSTEM_TOKEN_SECRETKEY": util.get_token("system_token_secretkey"),
|
||||
"KAMAILIO_PRIVATE_IP": kamailio_private_ip,
|
||||
"KAMAILIO_PUBLIC_IP": kamailio_public_ip,
|
||||
"KAMAILIO_NAT": kamailio_nat
|
||||
}
|
||||
|
||||
data.update(tenant_data)
|
||||
|
||||
output_text = template.render(data)
|
||||
output_file = os.path.join(output_directory, "config.env")
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
file.write(output_text)
|
||||
Reference in New Issue
Block a user