move nginx conf files to /tmp/nginx/conf
This commit is contained in:
parent
dab8e5a17c
commit
7df3279cea
@ -10,7 +10,7 @@ http {
|
||||
log_format https_combined '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" HTTPS';
|
||||
log_format http_combined '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" HTTP';
|
||||
|
||||
include /tmp/nginx/*;
|
||||
include /tmp/nginx/conf/*;
|
||||
|
||||
server {
|
||||
listen *:80 default_server;
|
||||
|
@ -10,6 +10,7 @@ import os
|
||||
import logging
|
||||
|
||||
target_path = "/tmp/nginx/"
|
||||
config_path = target_path + "conf/"
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
non_location_template = """# proxy for container '$containername'
|
||||
server {
|
||||
@ -127,8 +128,8 @@ def handle_container(id):
|
||||
'body_size': get_if_available(proxy_data, 'body_size', '1m'),
|
||||
'listen': '*:80'
|
||||
}
|
||||
logging.info('writing to %sproxy_%s', target_path, id)
|
||||
with open(target_path + '/proxy_{id}_{code}'.format(id=id,code=env_key), 'w') as file:
|
||||
logging.info('writing to %sproxy_%s', config_path, id)
|
||||
with open(config_path + '/proxy_{id}_{code}'.format(id=id,code=env_key), 'w') as file:
|
||||
if substitutes['location'] == '':
|
||||
del substitutes['location']
|
||||
logging.info(Template(non_location_template).safe_substitute(substitutes))
|
||||
@ -192,9 +193,11 @@ if __name__ == '__main__':
|
||||
# prepare required stuff
|
||||
pid = get_pid()
|
||||
logging.info('nginx pid: %s', str(pid))
|
||||
if not os.path.exists(target_path):
|
||||
if not os.path.exists(config_path):
|
||||
logging.info('creating target path: %s', target_path)
|
||||
os.mkdir(target_path)
|
||||
logging.info('creating target path: %s', config_path)
|
||||
os.mkdir(config_path)
|
||||
|
||||
client = Client(base_url='unix://var/run/docker.sock', version='1.15')
|
||||
|
||||
@ -229,10 +232,10 @@ if __name__ == '__main__':
|
||||
# since a container can expose multiple ports per PROXY_DATA it
|
||||
# will generate multiple files. All names contain the container id.
|
||||
# This will be used to delete all relevant files for a container
|
||||
for filename in os.listdir(target_path):
|
||||
for filename in os.listdir(config_path):
|
||||
if container_id in filename:
|
||||
logging.info('removing file %s%s', target_path, container_id)
|
||||
os.remove(target_path + filename)
|
||||
logging.info('removing file %s%s', config_path, container_id)
|
||||
os.remove(config_path + filename)
|
||||
else:
|
||||
handle_container(container_id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user