From b1b316a97b2f84f6f9b953f2094f9a6494943ec1 Mon Sep 17 00:00:00 2001 From: Jesse Hu Date: Sun, 7 Jan 2018 17:23:18 +0800 Subject: [PATCH] Add registry storage config in harbor.cfg (#3918) Refer to https://docs.docker.com/registry/configuration/#storage for all available configuration. --- make/common/templates/registry/config.yml | 3 +- make/common/templates/registry/config_ha.yml | 2 +- make/harbor.cfg | 13 ++++-- make/prepare | 48 +++++++++++--------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/make/common/templates/registry/config.yml b/make/common/templates/registry/config.yml index c49805a04..e30dfb47c 100644 --- a/make/common/templates/registry/config.yml +++ b/make/common/templates/registry/config.yml @@ -6,8 +6,7 @@ log: storage: cache: layerinfo: inmemory - filesystem: - rootdirectory: /storage + $storage_provider_info maintenance: uploadpurging: enabled: false diff --git a/make/common/templates/registry/config_ha.yml b/make/common/templates/registry/config_ha.yml index f3b04fcb1..e4570db2c 100644 --- a/make/common/templates/registry/config_ha.yml +++ b/make/common/templates/registry/config_ha.yml @@ -6,7 +6,7 @@ log: storage: cache: layerinfo: redis - Place_holder_for_Storage_configureation + $storage_provider_info maintenance: uploadpurging: enabled: false diff --git a/make/harbor.cfg b/make/harbor.cfg index 156a6acfa..96032547e 100644 --- a/make/harbor.cfg +++ b/make/harbor.cfg @@ -133,14 +133,21 @@ clair_db_username = postgres #Clair default database clair_db = postgres - - ################### end of HA section ##################### + #************************END INITIAL PROPERTIES************************ + #The following attributes only need to be set when auth mode is uaa_auth uaa_endpoint = uaa.mydomain.org uaa_clientid = id uaa_clientsecret = secret uaa_verify_cert = true uaa_ca_cert = /path/to/ca.pem -############# + + +### Docker Registry setting ### +#registry_storage_provider can be: filesystem, s3, gcs, azure, etc. +registry_storage_provider_name = filesystem +#registry_storage_provider_config is a comma separated "key: value" pairs, e.g. "key1: value, key2: value2". +#Refer to https://docs.docker.com/registry/configuration/#storage for all available configuration. +registry_storage_provider_config = diff --git a/make/prepare b/make/prepare index ba5e7476c..6658de07e 100755 --- a/make/prepare +++ b/make/prepare @@ -23,13 +23,16 @@ def validate(conf, args): if args.ha_mode: db_host = rcp.get("configuration", "db_host") if db_host == "mysql": - raise Exception("Error: In HA mode, db_host in harbor.cfg needs to point to an external DB address") - registry_config_path = os.path.join(templates_dir,"registry","config_ha.yml") - if check_storage_config(registry_config_path): - raise Exception("Error: In HA model shared storage configuration is required registry, refer HA installation guide for detail.") + raise Exception("Error: In HA mode, db_host in harbor.cfg needs to point to an external DB address.") + registry_storage_provider_name = rcp.get("configuration", + "registry_storage_provider_name").strip() + if registry_storage_provider_name == "filesystem" and not args.yes: + msg = 'Is the Harbor Docker Registry configured to use shared storage (e.g. NFS, S3, GCS, etc.)? [yes/no]:' + if raw_input(msg).lower() != "yes": + raise Exception("Error: In HA mode, shared storage configuration for Docker Registry in harbor.cfg is required. Refer to HA installation guide for details.") redis_url = rcp.get("configuration", "redis_url") if redis_url is None or len(redis_url) < 1: - raise Exception("Error: In HA mode redis is required redis_url need to point to an redis cluster") + raise Exception("Error: In HA mode, redis_url in harbor.cfg needs to point to a Redis cluster.") if args.notary_mode: raise Exception("Error: HA mode doesn't support Notary currently") if args.clair_mode: @@ -117,11 +120,6 @@ def prepare_ha(conf, args): if os.path.isfile(secret_key): shutil.copy2(secret_key, shared_secret_key) -def check_storage_config(path): - if 'Place_holder_for_Storage_configureation' in open(path).read(): - return True - return False - def get_secret_key(path): secret_key = _get_secret(path, "secretkey") if len(secret_key) != 16: @@ -180,6 +178,7 @@ parser.add_argument('--conf', dest='cfgfile', default=base_dir+'/harbor.cfg',typ parser.add_argument('--with-notary', dest='notary_mode', default=False, action='store_true', help="the Harbor instance is to be deployed with notary") parser.add_argument('--with-clair', dest='clair_mode', default=False, action='store_true', help="the Harbor instance is to be deployed with clair") parser.add_argument('--ha', dest='ha_mode', default=False, action='store_true', help="the Harbor instance is to be deployed in HA mode") +parser.add_argument('--yes', dest='yes', default=False, action='store_true', help="Answer yes to all questions") args = parser.parse_args() delfile(config_dir) @@ -260,7 +259,6 @@ if rcp.has_option("configuration", "redis_url"): redis_url = rcp.get("configuration", "redis_url") else: redis_url = "" -######## ui_secret = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(16)) jobservice_secret = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(16)) @@ -357,17 +355,23 @@ render(os.path.join(templates_dir, "ui", "env"), jobservice_secret=jobservice_secret, redis_url = redis_url ) -if args.ha_mode: - render(os.path.join(templates_dir, "registry", - "config_ha.yml"), - registry_conf, - ui_url=ui_url, - redis_url=redis_url) -else: - render(os.path.join(templates_dir, "registry", - "config.yml"), - registry_conf, - ui_url=ui_url) + +registry_config_file = "config_ha.yml" if args.ha_mode else "config.yml" +storage_provider_name = rcp.get("configuration", "registry_storage_provider_name").strip() +storage_provider_config = rcp.get("configuration", "registry_storage_provider_config").strip() +if storage_provider_name == "filesystem": + if not storage_provider_config: + storage_provider_config = "rootdirectory: /storage" + elif "rootdirectory:" not in storage_provider_config: + storage_provider_config = "rootdirectory: /storage" + "," + storage_provider_config +# generate storage configuration section in yaml format +storage_provider_info = ('\n' + ' ' * 4).join( + [storage_provider_name + ':'] + map(string.strip, storage_provider_config.split(","))) +render(os.path.join(templates_dir, "registry", registry_config_file), + registry_conf, + storage_provider_info=storage_provider_info, + ui_url=ui_url, + redis_url=redis_url) render(os.path.join(templates_dir, "db", "env"), db_conf_env,