2019-04-02 14:08:26 +02:00
|
|
|
import os, copy
|
2018-11-15 04:09:57 +01:00
|
|
|
|
|
|
|
from g import config_dir, templates_dir, DEFAULT_GID, DEFAULT_UID
|
|
|
|
from utils.misc import prepare_config_dir
|
|
|
|
from utils.jinja import render_jinja
|
|
|
|
|
|
|
|
|
|
|
|
registry_config_dir = os.path.join(config_dir, "registry")
|
|
|
|
registry_config_template_path = os.path.join(templates_dir, "registry", "config.yml.jinja")
|
|
|
|
registry_conf = os.path.join(config_dir, "registry", "config.yml")
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_registry(config_dict):
|
2019-04-02 14:08:26 +02:00
|
|
|
prepare_config_dir(registry_config_dir)
|
2018-11-15 04:09:57 +01:00
|
|
|
|
|
|
|
storage_provider_info = get_storage_provider_info(
|
|
|
|
config_dict['storage_provider_name'],
|
2019-04-02 14:08:26 +02:00
|
|
|
config_dict['storage_provider_config'])
|
2018-11-15 04:09:57 +01:00
|
|
|
|
|
|
|
render_jinja(
|
|
|
|
registry_config_template_path,
|
|
|
|
registry_conf,
|
|
|
|
uid=DEFAULT_UID,
|
|
|
|
gid=DEFAULT_GID,
|
|
|
|
storage_provider_info=storage_provider_info,
|
|
|
|
**config_dict)
|
|
|
|
|
|
|
|
|
2019-04-02 14:08:26 +02:00
|
|
|
def get_storage_provider_info(provider_name, provider_config):
|
|
|
|
provider_config_copy = copy.deepcopy(provider_config)
|
2018-11-15 04:09:57 +01:00
|
|
|
if provider_name == "filesystem":
|
2019-04-02 14:08:26 +02:00
|
|
|
if not (provider_config_copy and provider_config_copy.has_key('rootdirectory')):
|
|
|
|
provider_config_copy['rootdirectory'] = '/storage'
|
|
|
|
if provider_name == 'gcs' and provider_config_copy.get('keyfile'):
|
|
|
|
provider_config_copy['keyfile'] = '/etc/registry/gcs.key'
|
2018-11-15 04:09:57 +01:00
|
|
|
# generate storage configuration section in yaml format
|
|
|
|
storage_provider_conf_list = [provider_name + ':']
|
2019-04-02 14:08:26 +02:00
|
|
|
for config in provider_config_copy.items():
|
|
|
|
storage_provider_conf_list.append('{}: {}'.format(*config))
|
2018-11-15 04:09:57 +01:00
|
|
|
storage_provider_info = ('\n' + ' ' * 4).join(storage_provider_conf_list)
|
|
|
|
return storage_provider_info
|