Merge pull request #6610 from ninjadq/add_customized_location_to_nginx

Add customized config file for proxy
This commit is contained in:
Mia ZHOU 2018-12-26 15:41:41 +08:00 committed by GitHub
commit 9825711250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -33,6 +33,9 @@ http {
# disable any limits to avoid HTTP 413 for large image uploads # disable any limits to avoid HTTP 413 for large image uploads
client_max_body_size 0; client_max_body_size 0;
# costumized location config file can place to /etc/nginx/etc with prefix harbor.http. and suffix .conf
include /etc/nginx/conf.d/harbor.http.*.conf;
location / { location / {
proxy_pass http://portal/; proxy_pass http://portal/;
proxy_set_header Host $$host; proxy_set_header Host $$host;

View File

@ -50,6 +50,9 @@ http {
# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486) # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
chunked_transfer_encoding on; chunked_transfer_encoding on;
# costumized location config file can place to /etc/nginx dir with prefix harbor.https. and suffix .conf
include /etc/nginx/conf.d/harbor.https.*.conf;
location / { location / {
proxy_pass http://portal/; proxy_pass http://portal/;
proxy_set_header Host $$http_host; proxy_set_header Host $$http_host;

View File

@ -4,6 +4,7 @@ from __future__ import print_function, unicode_literals # We require Python 2.6
from string import Template from string import Template
import random import random
import os import os
from fnmatch import fnmatch
import sys import sys
import string import string
import argparse import argparse
@ -27,6 +28,8 @@ base_dir = os.path.dirname(__file__)
config_dir = os.path.join(base_dir, "common/config") config_dir = os.path.join(base_dir, "common/config")
templates_dir = os.path.join(base_dir, "common/templates") templates_dir = os.path.join(base_dir, "common/templates")
custom_nginx_location_file_pattern = 'harbor.https.*.conf'
def validate(conf, args): def validate(conf, args):
protocol = rcp.get("configuration", "ui_url_protocol") protocol = rcp.get("configuration", "ui_url_protocol")
@ -308,8 +311,28 @@ if protocol == "https":
ssl_cert = os.path.join("/etc/nginx/cert", os.path.basename(target_cert_path)), ssl_cert = os.path.join("/etc/nginx/cert", os.path.basename(target_cert_path)),
ssl_cert_key = os.path.join("/etc/nginx/cert", os.path.basename(target_cert_key_path))) ssl_cert_key = os.path.join("/etc/nginx/cert", os.path.basename(target_cert_key_path)))
else: else:
render(os.path.join(templates_dir, "nginx", "nginx.http.conf"), render(os.path.join(templates_dir, "nginx", "nginx.http.conf"), nginx_conf)
nginx_conf) custom_nginx_location_file_pattern = 'harbor.http.*.conf'
def add_additional_location_config(src, dst):
"""
This conf file is used for user that wanna add additional customized locations to harbor proxy
:params src: source of the file
:params dst: destination file path
"""
if not os.path.isfile(src):
return
print("Copying nginx configuration file {src} to {dst}".format(src=src, dst=dst))
shutil.copy2(src, dst)
mark_file(dst)
nginx_template_ext_dir = os.path.join(templates_dir, 'nginx', 'ext')
if os.path.exists(nginx_template_ext_dir):
map(lambda filename: add_additional_location_config(
os.path.join(nginx_template_ext_dir, filename),
os.path.join(nginx_conf_d, filename)),
[fname for fname in os.listdir(nginx_template_ext_dir) if fnmatch(fname, custom_nginx_location_file_pattern)])
#Use reload_key to avoid reload config after restart harbor #Use reload_key to avoid reload config after restart harbor
reload_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) if reload_config == "true" else "" reload_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) if reload_config == "true" else ""