Add registry storage config in harbor.cfg (#3918)

Refer to https://docs.docker.com/registry/configuration/#storage
for all available configuration.
This commit is contained in:
Jesse Hu 2018-01-07 17:23:18 +08:00 committed by GitHub
parent f20103dc0c
commit b1b316a97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 28 deletions

View File

@ -6,8 +6,7 @@ log:
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /storage
$storage_provider_info
maintenance:
uploadpurging:
enabled: false

View File

@ -6,7 +6,7 @@ log:
storage:
cache:
layerinfo: redis
Place_holder_for_Storage_configureation
$storage_provider_info
maintenance:
uploadpurging:
enabled: false

View File

@ -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 =

View File

@ -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,