2016-02-01 12:59:10 +01:00
|
|
|
#!/usr/bin/python
|
2016-04-15 11:23:40 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import print_function, unicode_literals # We require Python 2.6 or later
|
2016-02-01 12:59:10 +01:00
|
|
|
from string import Template
|
2016-04-15 11:23:40 +02:00
|
|
|
import os
|
2016-04-18 10:01:44 +02:00
|
|
|
import sys
|
2016-04-15 11:23:40 +02:00
|
|
|
from io import open
|
|
|
|
|
2016-04-18 10:01:44 +02:00
|
|
|
if sys.version_info[:3][0] == 2:
|
2016-04-15 11:23:40 +02:00
|
|
|
import ConfigParser as ConfigParser
|
|
|
|
import StringIO as StringIO
|
|
|
|
|
2016-04-18 10:01:44 +02:00
|
|
|
if sys.version_info[:3][0] == 3:
|
2016-04-15 11:23:40 +02:00
|
|
|
import configparser as ConfigParser
|
|
|
|
import io as StringIO
|
2016-02-22 03:00:42 +01:00
|
|
|
|
|
|
|
#Read configurations
|
|
|
|
conf = StringIO.StringIO()
|
|
|
|
conf.write("[configuration]\n")
|
|
|
|
conf.write(open("harbor.cfg").read())
|
|
|
|
conf.seek(0, os.SEEK_SET)
|
2016-04-15 11:23:40 +02:00
|
|
|
rcp = ConfigParser.RawConfigParser()
|
|
|
|
rcp.readfp(conf)
|
|
|
|
|
|
|
|
hostname = rcp.get("configuration", "hostname")
|
|
|
|
ui_url = rcp.get("configuration", "ui_url_protocol") + "://" + hostname
|
|
|
|
email_server = rcp.get("configuration", "email_server")
|
|
|
|
email_server_port = rcp.get("configuration", "email_server_port")
|
|
|
|
email_username = rcp.get("configuration", "email_username")
|
|
|
|
email_password = rcp.get("configuration", "email_password")
|
|
|
|
email_from = rcp.get("configuration", "email_from")
|
2016-04-21 07:03:12 +02:00
|
|
|
email_ssl = rcp.get("configuration", "email_ssl")
|
2016-04-15 11:23:40 +02:00
|
|
|
harbor_admin_password = rcp.get("configuration", "harbor_admin_password")
|
|
|
|
auth_mode = rcp.get("configuration", "auth_mode")
|
|
|
|
ldap_url = rcp.get("configuration", "ldap_url")
|
|
|
|
ldap_basedn = rcp.get("configuration", "ldap_basedn")
|
|
|
|
db_password = rcp.get("configuration", "db_password")
|
|
|
|
self_registration = rcp.get("configuration", "self_registration")
|
2016-02-22 03:00:42 +01:00
|
|
|
########
|
|
|
|
|
2016-04-15 11:23:40 +02:00
|
|
|
base_dir = os.path.dirname(__file__)
|
2016-02-01 12:59:10 +01:00
|
|
|
config_dir = os.path.join(base_dir, "config")
|
|
|
|
templates_dir = os.path.join(base_dir, "templates")
|
|
|
|
|
2016-02-22 03:00:42 +01:00
|
|
|
|
2016-02-01 12:59:10 +01:00
|
|
|
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"))
|
|
|
|
|
2016-02-22 03:00:42 +01:00
|
|
|
db_config_dir = os.path.join(config_dir, "db")
|
|
|
|
if not os.path.exists(db_config_dir):
|
|
|
|
os.makedirs(os.path.join(config_dir, "db"))
|
|
|
|
|
2016-02-01 12:59:10 +01:00
|
|
|
def render(src, dest, **kw):
|
|
|
|
t = Template(open(src, 'r').read())
|
|
|
|
with open(dest, 'w') as f:
|
|
|
|
f.write(t.substitute(**kw))
|
2016-04-15 11:23:40 +02:00
|
|
|
print("Generated configuration file: %s" % dest)
|
2016-02-01 12:59:10 +01:00
|
|
|
|
|
|
|
ui_conf_env = os.path.join(config_dir, "ui", "env")
|
2016-04-15 11:23:40 +02:00
|
|
|
ui_conf = os.path.join(config_dir, "ui", "app.conf")
|
2016-02-01 12:59:10 +01:00
|
|
|
registry_conf = os.path.join(config_dir, "registry", "config.yml")
|
2016-02-22 03:00:42 +01:00
|
|
|
db_conf_env = os.path.join(config_dir, "db", "env")
|
2016-02-01 12:59:10 +01:00
|
|
|
|
2016-02-22 03:00:42 +01:00
|
|
|
conf_files = [ ui_conf, ui_conf_env, registry_conf, db_conf_env ]
|
2016-02-01 12:59:10 +01:00
|
|
|
for f in conf_files:
|
|
|
|
if os.path.exists(f):
|
2016-04-15 11:23:40 +02:00
|
|
|
print("Clearing the configuration file: %s" % f)
|
2016-02-01 12:59:10 +01:00
|
|
|
os.remove(f)
|
|
|
|
|
|
|
|
render(os.path.join(templates_dir, "ui", "env"),
|
|
|
|
ui_conf_env,
|
|
|
|
hostname=hostname,
|
2016-04-01 12:54:21 +02:00
|
|
|
db_password=db_password,
|
2016-02-01 12:59:10 +01:00
|
|
|
ui_url=ui_url,
|
|
|
|
auth_mode=auth_mode,
|
|
|
|
admin_pwd=harbor_admin_password,
|
|
|
|
ldap_url=ldap_url,
|
2016-03-30 12:43:56 +02:00
|
|
|
ldap_basedn=ldap_basedn,
|
|
|
|
self_registration=self_registration)
|
2016-02-01 12:59:10 +01:00
|
|
|
|
|
|
|
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,
|
2016-04-21 07:03:12 +02:00
|
|
|
email_ssl=email_ssl,
|
2016-02-01 12:59:10 +01:00
|
|
|
ui_url=ui_url)
|
|
|
|
|
|
|
|
render(os.path.join(templates_dir, "registry", "config.yml"),
|
|
|
|
registry_conf,
|
|
|
|
ui_url=ui_url)
|
|
|
|
|
2016-02-22 03:00:42 +01:00
|
|
|
render(os.path.join(templates_dir, "db", "env"),
|
|
|
|
db_conf_env,
|
|
|
|
db_password=db_password)
|
|
|
|
|
2016-04-15 11:23:40 +02:00
|
|
|
print("The configuration files are ready, please use docker-compose to start the service.")
|