harbor/Deploy/prepare

73 lines
2.4 KiB
Python
Executable File

#!/usr/bin/python
## CONFIGURATIONS
#The endpoint for user to access UI and registry service
hostname = "mydomain.com"
#User can update the protocol if ssl has been setup
ui_url = "http://" + hostname
#Email settings for ui to send password resetting emails
email_server = "smtp.mydomain.com"
email_server_port = "25"
email_username = "sample_admin@mydomain.com"
email_password = "abc"
email_from = "admin <sample_admin@mydomain.com>"
##The password of harbor admin
harbor_admin_password= "Harbor12345"
##By default the auth mode is db_auth, i.e. the creadentials are stored in a databse
#please set it to ldap_auth if you want to verify user's credentials against an ldap server.
auth_mode = "db_auth"
#The url for ldap endpoint
ldap_url = "ldaps://ldap.mydomain.com"
#The basedn template for verifying the user's password
ldap_basedn = "uid=%s,ou=people,dc=mydomain,dc=com"
#####
import os
from string import Template
base_dir = os.path.dirname(__file__)
config_dir = os.path.join(base_dir, "config")
templates_dir = os.path.join(base_dir, "templates")
ui_config_dir = os.path.join(config_dir,"ui")
if not os.path.exists(ui_config_dir):
os.makedirs(os.path.join(config_dir, "ui"))
def render(src, dest, **kw):
t = Template(open(src, 'r').read())
with open(dest, 'w') as f:
f.write(t.substitute(**kw))
print "Generated configuration file: %s" % dest
ui_conf_env = os.path.join(config_dir, "ui", "env")
ui_conf = os.path.join(config_dir, "ui", "app.conf")
registry_conf = os.path.join(config_dir, "registry", "config.yml")
conf_files = [ ui_conf, ui_conf_env, registry_conf ]
for f in conf_files:
if os.path.exists(f):
print "Clearing the configuration file: %s" % f
os.remove(f)
render(os.path.join(templates_dir, "ui", "env"),
ui_conf_env,
hostname=hostname,
ui_url=ui_url,
auth_mode=auth_mode,
admin_pwd=harbor_admin_password,
ldap_url=ldap_url,
ldap_basedn=ldap_basedn)
render(os.path.join(templates_dir, "ui", "app.conf"),
ui_conf,
email_server=email_server,
email_server_port=email_server_port,
email_user_name=email_username,
email_user_password=email_password,
email_from=email_from,
ui_url=ui_url)
render(os.path.join(templates_dir, "registry", "config.yml"),
registry_conf,
ui_url=ui_url)
print "The configuration files are ready, please use docker-compose to start the service."