Merge branch 'multiple_domains' into 'master'

add support for multiple domains

See merge request !4
This commit is contained in:
Joachim Lusiardi 2017-01-01 09:06:32 +01:00
commit b292625c71

View File

@ -21,7 +21,7 @@ def analyse_proxy_data(data):
"""Extracts the data for the proxy configuration (envrionment variable """Extracts the data for the proxy configuration (envrionment variable
'PROXY_DATA' and converts it to a dictionary.""" 'PROXY_DATA' and converts it to a dictionary."""
proxy_data = {} proxy_data = {}
for proxy_var in data['PROXY_DATA'].split(','): for proxy_var in data.split(','):
t = proxy_var.split(":", 1) t = proxy_var.split(":", 1)
proxy_data[t[0]] = t[1] proxy_data[t[0]] = t[1]
return proxy_data return proxy_data
@ -31,11 +31,18 @@ def analyse_env_vars(inspect_data):
"""Extracts the environment variables from the given result of an 'inspect """Extracts the environment variables from the given result of an 'inspect
container' call.""" container' call."""
env_data = {} env_data = {}
counter = 0
if not 'Env' in inspect_data['Config'] or inspect_data['Config']['Env'] is None: if not 'Env' in inspect_data['Config'] or inspect_data['Config']['Env'] is None:
return env_data return env_data
for env_var in inspect_data['Config']['Env']: for env_var in inspect_data['Config']['Env']:
t = env_var.split("=") t = env_var.split("=")
env_data[t[0]] = t[1] key = t[0]
value = t[1]
if key == 'PROXY_DATA':
if key in env_data:
key = "{key}{postfix}".format(key=key, postfix=counter)
counter+=1
env_data[key] = value
return env_data return env_data
@ -45,11 +52,13 @@ def handle_container(docker_client, id):
written to the directory of temporary nginx files""" written to the directory of temporary nginx files"""
inspect_data = docker_client.inspect_container(id) inspect_data = docker_client.inspect_container(id)
env_vars = analyse_env_vars(inspect_data) env_vars = analyse_env_vars(inspect_data)
if 'PROXY_DATA' in env_vars: names = []
proxy_data = analyse_proxy_data(env_vars) for key in env_vars:
names = get_if_available(proxy_data, 'server_names', '').split(';') value = env_vars[key]
proxy_data = analyse_proxy_data(value)
names += get_if_available(proxy_data, 'server_names', '').split(';')
logging.info('list of domains on: %s', str(names))
return names return names
return []
def get_resolving_domains_from_containers(docker_client): def get_resolving_domains_from_containers(docker_client):