2018-11-15 04:09:57 +01:00
|
|
|
import shutil, os
|
|
|
|
|
2019-08-30 07:40:49 +02:00
|
|
|
from g import config_dir, templates_dir, data_dir, DEFAULT_GID, DEFAULT_UID
|
2019-08-01 10:02:08 +02:00
|
|
|
from utils.misc import prepare_dir, generate_random_string
|
2018-11-15 04:09:57 +01:00
|
|
|
from utils.jinja import render_jinja
|
|
|
|
|
|
|
|
core_config_dir = os.path.join(config_dir, "core", "certificates")
|
|
|
|
core_env_template_path = os.path.join(templates_dir, "core", "env.jinja")
|
|
|
|
core_conf_env = os.path.join(config_dir, "core", "env")
|
|
|
|
core_conf_template_path = os.path.join(templates_dir, "core", "app.conf.jinja")
|
|
|
|
core_conf = os.path.join(config_dir, "core", "app.conf")
|
|
|
|
|
2019-08-30 07:40:49 +02:00
|
|
|
ca_download_dir = os.path.join(data_dir, 'ca_download')
|
|
|
|
psc_dir = os.path.join(data_dir, 'psc')
|
|
|
|
|
|
|
|
|
2019-02-20 11:01:48 +01:00
|
|
|
def prepare_core(config_dict, with_notary, with_clair, with_chartmuseum):
|
2019-08-30 07:40:49 +02:00
|
|
|
prepare_dir(psc_dir, uid=DEFAULT_UID, gid=DEFAULT_GID)
|
|
|
|
prepare_dir(ca_download_dir, uid=DEFAULT_UID, gid=DEFAULT_GID)
|
|
|
|
prepare_dir(core_config_dir)
|
2018-11-15 04:09:57 +01:00
|
|
|
# Render Core
|
|
|
|
# set cache for chart repo server
|
|
|
|
# default set 'memory' mode, if redis is configured then set to 'redis'
|
|
|
|
if len(config_dict['redis_host']) > 0:
|
|
|
|
chart_cache_driver = "redis"
|
2019-02-20 11:01:48 +01:00
|
|
|
else:
|
|
|
|
chart_cache_driver = "memory"
|
|
|
|
|
2018-11-15 04:09:57 +01:00
|
|
|
render_jinja(
|
|
|
|
core_env_template_path,
|
|
|
|
core_conf_env,
|
|
|
|
chart_cache_driver=chart_cache_driver,
|
2019-05-05 12:13:20 +02:00
|
|
|
with_notary=with_notary,
|
|
|
|
with_clair=with_clair,
|
|
|
|
with_chartmuseum=with_chartmuseum,
|
2018-11-15 04:09:57 +01:00
|
|
|
**config_dict)
|
|
|
|
|
|
|
|
# Copy Core app.conf
|
|
|
|
copy_core_config(core_conf_template_path, core_conf)
|
|
|
|
|
|
|
|
|
|
|
|
def copy_core_config(core_templates_path, core_config_path):
|
|
|
|
shutil.copyfile(core_templates_path, core_config_path)
|
2019-02-20 11:01:48 +01:00
|
|
|
print("Generated configuration file: %s" % core_config_path)
|