2018-11-15 04:09:57 +01:00
|
|
|
import os, shutil
|
|
|
|
|
|
|
|
from g import templates_dir, config_dir
|
|
|
|
from .jinja import render_jinja
|
|
|
|
|
|
|
|
chartm_temp_dir = os.path.join(templates_dir, "chartserver")
|
|
|
|
chartm_env_temp = os.path.join(chartm_temp_dir, "env.jinja")
|
|
|
|
|
|
|
|
chartm_config_dir = os.path.join(config_dir, "chartserver")
|
|
|
|
chartm_env = os.path.join(config_dir, "chartserver", "env")
|
|
|
|
|
|
|
|
def prepare_chartmuseum(config_dict):
|
|
|
|
|
|
|
|
core_secret = config_dict['core_secret']
|
|
|
|
redis_host = config_dict['redis_host']
|
|
|
|
redis_port = config_dict['redis_port']
|
|
|
|
redis_password = config_dict['redis_password']
|
|
|
|
redis_db_index_chart = config_dict['redis_db_index_chart']
|
|
|
|
storage_provider_name = config_dict['storage_provider_name']
|
2019-05-05 10:02:01 +02:00
|
|
|
storage_provider_config_map = config_dict['storage_provider_config']
|
2018-11-15 04:09:57 +01:00
|
|
|
|
|
|
|
if not os.path.isdir(chartm_config_dir):
|
|
|
|
print ("Create config folder: %s" % chartm_config_dir)
|
|
|
|
os.makedirs(chartm_config_dir)
|
|
|
|
|
|
|
|
# process redis info
|
|
|
|
cache_store = "redis"
|
|
|
|
cache_redis_password = redis_password
|
|
|
|
cache_redis_addr = "{}:{}".format(redis_host, redis_port)
|
|
|
|
cache_redis_db_index = redis_db_index_chart
|
|
|
|
|
|
|
|
|
|
|
|
# process storage info
|
|
|
|
#default using local file system
|
|
|
|
storage_driver = "local"
|
|
|
|
# storage provider configurations
|
|
|
|
# please be aware that, we do not check the validations of the values for the specified keys
|
|
|
|
# convert the configs to config map
|
|
|
|
storage_provider_config_options = []
|
2019-05-05 10:02:01 +02:00
|
|
|
if storage_provider_name == 's3':
|
2018-11-15 04:09:57 +01:00
|
|
|
# aws s3 storage
|
|
|
|
storage_driver = "amazon"
|
2019-05-05 10:02:01 +02:00
|
|
|
storage_provider_config_options.append("STORAGE_AMAZON_BUCKET=%s" % (storage_provider_config_map.get("bucket") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_AMAZON_PREFIX=%s" % (storage_provider_config_map.get("rootdirectory") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_AMAZON_REGION=%s" % (storage_provider_config_map.get("region") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_AMAZON_ENDPOINT=%s" % (storage_provider_config_map.get("regionendpoint") or '') )
|
|
|
|
storage_provider_config_options.append("AWS_ACCESS_KEY_ID=%s" % (storage_provider_config_map.get("accesskey") or '') )
|
|
|
|
storage_provider_config_options.append("AWS_SECRET_ACCESS_KEY=%s" % (storage_provider_config_map.get("secretkey") or '') )
|
|
|
|
elif storage_provider_name == 'gcs':
|
2018-11-15 04:09:57 +01:00
|
|
|
# google cloud storage
|
|
|
|
storage_driver = "google"
|
2019-05-05 10:02:01 +02:00
|
|
|
storage_provider_config_options.append("STORAGE_GOOGLE_BUCKET=%s" % ( storage_provider_config_map.get("bucket") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_GOOGLE_PREFIX=%s" % ( storage_provider_config_map.get("rootdirectory") or '') )
|
2018-11-15 04:09:57 +01:00
|
|
|
|
2019-05-05 10:02:01 +02:00
|
|
|
if storage_provider_config_map.get("keyfile"):
|
|
|
|
storage_provider_config_options.append('GOOGLE_APPLICATION_CREDENTIALS=%s' % '/etc/chartserver/gcs.key')
|
2019-05-15 12:25:34 +02:00
|
|
|
elif storage_provider_name == 'azure':
|
2018-11-15 04:09:57 +01:00
|
|
|
# azure storage
|
|
|
|
storage_driver = "microsoft"
|
2019-05-05 10:02:01 +02:00
|
|
|
storage_provider_config_options.append("STORAGE_MICROSOFT_CONTAINER=%s" % ( storage_provider_config_map.get("container") or '') )
|
|
|
|
storage_provider_config_options.append("AZURE_STORAGE_ACCOUNT=%s" % ( storage_provider_config_map.get("accountname") or '') )
|
|
|
|
storage_provider_config_options.append("AZURE_STORAGE_ACCESS_KEY=%s" % ( storage_provider_config_map.get("accountkey") or '') )
|
2018-11-15 04:09:57 +01:00
|
|
|
storage_provider_config_options.append("STORAGE_MICROSOFT_PREFIX=/azure/harbor/charts")
|
2019-05-05 10:02:01 +02:00
|
|
|
elif storage_provider_name == 'swift':
|
2018-11-15 04:09:57 +01:00
|
|
|
# open stack swift
|
|
|
|
storage_driver = "openstack"
|
2019-05-05 10:02:01 +02:00
|
|
|
storage_provider_config_options.append("STORAGE_OPENSTACK_CONTAINER=%s" % ( storage_provider_config_map.get("container") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_OPENSTACK_PREFIX=%s" % ( storage_provider_config_map.get("rootdirectory") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_OPENSTACK_REGION=%s" % ( storage_provider_config_map.get("region") or '') )
|
|
|
|
storage_provider_config_options.append("OS_AUTH_URL=%s" % ( storage_provider_config_map.get("authurl") or '') )
|
|
|
|
storage_provider_config_options.append("OS_USERNAME=%s" % ( storage_provider_config_map.get("username") or '') )
|
|
|
|
storage_provider_config_options.append("OS_PASSWORD=%s" % ( storage_provider_config_map.get("password") or '') )
|
|
|
|
storage_provider_config_options.append("OS_PROJECT_ID=%s" % ( storage_provider_config_map.get("tenantid") or '') )
|
|
|
|
storage_provider_config_options.append("OS_PROJECT_NAME=%s" % ( storage_provider_config_map.get("tenant") or '') )
|
|
|
|
storage_provider_config_options.append("OS_DOMAIN_ID=%s" % ( storage_provider_config_map.get("domainid") or '') )
|
|
|
|
storage_provider_config_options.append("OS_DOMAIN_NAME=%s" % ( storage_provider_config_map.get("domain") or '') )
|
|
|
|
elif storage_provider_name == 'oss':
|
2018-11-15 04:09:57 +01:00
|
|
|
# aliyun OSS
|
|
|
|
storage_driver = "alibaba"
|
2019-05-05 10:02:01 +02:00
|
|
|
storage_provider_config_options.append("STORAGE_ALIBABA_BUCKET=%s" % ( storage_provider_config_map.get("bucket") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_ALIBABA_PREFIX=%s" % ( storage_provider_config_map.get("rootdirectory") or '') )
|
|
|
|
storage_provider_config_options.append("STORAGE_ALIBABA_ENDPOINT=%s" % ( storage_provider_config_map.get("endpoint") or '') )
|
|
|
|
storage_provider_config_options.append("ALIBABA_CLOUD_ACCESS_KEY_ID=%s" % ( storage_provider_config_map.get("accesskeyid") or '') )
|
|
|
|
storage_provider_config_options.append("ALIBABA_CLOUD_ACCESS_KEY_SECRET=%s" % ( storage_provider_config_map.get("accesskeysecret") or '') )
|
2018-11-15 04:09:57 +01:00
|
|
|
else:
|
|
|
|
# use local file system
|
|
|
|
storage_provider_config_options.append("STORAGE_LOCAL_ROOTDIR=/chart_storage")
|
|
|
|
|
|
|
|
# generate storage provider configuration
|
|
|
|
all_storage_provider_configs = ('\n').join(storage_provider_config_options)
|
|
|
|
|
|
|
|
render_jinja(
|
|
|
|
chartm_env_temp,
|
|
|
|
chartm_env,
|
|
|
|
cache_store=cache_store,
|
|
|
|
cache_redis_addr=cache_redis_addr,
|
|
|
|
cache_redis_password=cache_redis_password,
|
|
|
|
cache_redis_db_index=cache_redis_db_index,
|
2019-05-06 12:36:33 +02:00
|
|
|
core_secret=config_dict['core_secret'],
|
2018-11-15 04:09:57 +01:00
|
|
|
storage_driver=storage_driver,
|
2019-05-06 12:36:33 +02:00
|
|
|
all_storage_driver_configs=all_storage_provider_configs,
|
2019-05-08 06:59:44 +02:00
|
|
|
public_url=config_dict['public_url'],
|
|
|
|
chart_absolute_url=config_dict['chart_absolute_url'])
|