Make sure that I don't duplicate servers or upstream, if their arguments come in different order they are considered different

This commit is contained in:
Jonathan Adami 2020-04-26 18:32:29 +10:00
parent a386ac668b
commit 1906c927f1

View file

@ -19,7 +19,27 @@ nodes = [f['parsed'] for f in swarm_config[1:-1]]
for node in nodes:
for statement in node:
if statement not in nginx_config:
if statement in nginx_config:
continue
if statement['directive'] == 'upstream':
all_upstream = [
s['args'][0]
for s in nginx_config if s['directive'] == 'upstream'
]
if statement['args'][0] in all_upstream:
continue
if statement['directive'] == 'server':
server_name = [
s['args'][0]
for s in statement['block'] if s['directive'] == 'server_name'
][0]
all_server_names = [
sl['args'][0]
for s in nginx_config if s['directive'] == 'server'
for sl in s['block'] if sl['directive'] == 'server_name'
]
if server_name in all_server_names:
continue
nginx_config.append(statement)
with open(NGINX_OUTPUT, 'w') as f: