Make spotter-appmgr update proxy target IP directly in nginx
This commit is contained in:
parent
e52fbfd1f2
commit
dd2a936cc7
@ -7,7 +7,6 @@ import os
|
||||
import subprocess
|
||||
|
||||
CONF_FILE = '/etc/spotter/apps.json'
|
||||
HOSTS_FILE = '/etc/hosts'
|
||||
ISSUE_FILE = '/etc/issue'
|
||||
NGINX_DIR = '/etc/nginx/conf.d'
|
||||
|
||||
@ -19,7 +18,7 @@ NGINX_TEMPLATE = '''server {{
|
||||
error_log /var/log/nginx/{app}.error.log;
|
||||
|
||||
location / {{
|
||||
proxy_pass http://{app}:8080;
|
||||
proxy_pass http://{ip}:8080;
|
||||
}}
|
||||
}}
|
||||
'''
|
||||
@ -103,8 +102,6 @@ class SpotterManager:
|
||||
self.add_app_to_conf(app, args)
|
||||
if args.url:
|
||||
self.update_app_conf(app)
|
||||
self.add_app_to_nginx(app)
|
||||
self.reload_nginx()
|
||||
|
||||
def add_app_to_conf(self, app, args):
|
||||
self.conf[app] = {}
|
||||
@ -123,22 +120,18 @@ class SpotterManager:
|
||||
host = '{}.{}'.format(app, self.domain)
|
||||
subprocess.call([script_path, host, self.port])
|
||||
|
||||
def update_proxy(self, app):
|
||||
self.add_app_to_nginx(app)
|
||||
self.reload_nginx()
|
||||
|
||||
def add_app_to_nginx(self, app):
|
||||
ip = get_container_ip(app)
|
||||
with open(os.path.join(NGINX_DIR, '{}.conf'.format(app)), 'w') as f:
|
||||
f.write(NGINX_TEMPLATE.format(app=app, domain=self.domain, port=self.port))
|
||||
f.write(NGINX_TEMPLATE.format(app=app, ip=ip, domain=self.domain, port=self.port))
|
||||
|
||||
def reload_nginx(self):
|
||||
subprocess.call(['service', 'nginx', 'reload'])
|
||||
|
||||
def update_hosts(self, app):
|
||||
with open(HOSTS_FILE, 'r') as f:
|
||||
lines = f.readlines()
|
||||
with open(HOSTS_FILE, 'w') as f:
|
||||
for line in lines:
|
||||
if not line.strip().endswith(' {}'.format(app)):
|
||||
f.write(line)
|
||||
f.write('{} {}\n'.format(get_container_ip(app), app))
|
||||
|
||||
def update_domain(self, domain, port):
|
||||
self.domain = self.conf["_"]["domain"] = domain
|
||||
self.port = self.conf["_"]["port"] = port
|
||||
@ -179,7 +172,7 @@ if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Spotter VM application manager')
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
parser_add_app = subparsers.add_parser('add-app', help='Registers a new application and creates hosts and nginx definition for it')
|
||||
parser_add_app = subparsers.add_parser('add-app', help='Registers a new application')
|
||||
parser_add_app.set_defaults(action='add-app')
|
||||
parser_add_app.add_argument('app', help='Application name')
|
||||
parser_add_app.add_argument('url', nargs='?', help='URL to the application. Use "{host}" as a host placeholder')
|
||||
@ -187,9 +180,9 @@ if __name__ == '__main__':
|
||||
parser_add_app.add_argument('password', nargs='?', help='Administrative password')
|
||||
parser_add_app.add_argument('-p', '--property', nargs=2, action='append', help='Add arbitrary key-value to the application properties')
|
||||
|
||||
parser_update_app = subparsers.add_parser('update-hosts', help='Updates hosts definition for application container')
|
||||
parser_update_app.set_defaults(action='update-hosts')
|
||||
parser_update_app.add_argument('app', help='Application name')
|
||||
parser_update_proxy = subparsers.add_parser('update-proxy', help='Updates nginx proxy target for an application container')
|
||||
parser_update_proxy.set_defaults(action='update-proxy')
|
||||
parser_update_proxy.add_argument('app', help='Application name')
|
||||
|
||||
parser_update_domain = subparsers.add_parser('update-domain', help='Rebuilds domain structure of VM with new domain name and new HTTPS port')
|
||||
parser_update_domain.set_defaults(action='update-domain')
|
||||
@ -200,7 +193,7 @@ if __name__ == '__main__':
|
||||
sm = SpotterManager()
|
||||
if args.action == 'add-app':
|
||||
sm.add_app(args.app, args)
|
||||
elif args.action == 'update-hosts':
|
||||
sm.update_hosts(args.app)
|
||||
elif args.action == 'update-proxy':
|
||||
sm.update_proxy(args.app)
|
||||
elif args.action == 'update-domain':
|
||||
sm.update_domain(args.domain, args.port)
|
||||
|
@ -18,7 +18,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts ccleanup
|
||||
/usr/local/bin/spotter-appmgr update-proxy ccleanup
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -23,7 +23,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts ckan
|
||||
/usr/local/bin/spotter-appmgr update-proxy ckan
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -17,7 +17,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts cts
|
||||
/usr/local/bin/spotter-appmgr update-proxy cts
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -18,7 +18,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts gnuhealth
|
||||
/usr/local/bin/spotter-appmgr update-proxy gnuhealth
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -19,7 +19,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts kanboard
|
||||
/usr/local/bin/spotter-appmgr update-proxy kanboard
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -19,7 +19,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts mifosx
|
||||
/usr/local/bin/spotter-appmgr update-proxy mifosx
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -19,7 +19,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts motech
|
||||
/usr/local/bin/spotter-appmgr update-proxy motech
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -20,7 +20,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts odk
|
||||
/usr/local/bin/spotter-appmgr update-proxy odk
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -17,7 +17,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts odkbuild
|
||||
/usr/local/bin/spotter-appmgr update-proxy odkbuild
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -17,7 +17,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts omk
|
||||
/usr/local/bin/spotter-appmgr update-proxy omk
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -20,7 +20,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts pandora
|
||||
/usr/local/bin/spotter-appmgr update-proxy pandora
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -21,7 +21,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts sahana-demo
|
||||
/usr/local/bin/spotter-appmgr update-proxy sahana-demo
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -21,7 +21,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts sahana
|
||||
/usr/local/bin/spotter-appmgr update-proxy sahana
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -21,7 +21,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts sambro
|
||||
/usr/local/bin/spotter-appmgr update-proxy sambro
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -19,7 +19,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts seeddms
|
||||
/usr/local/bin/spotter-appmgr update-proxy seeddms
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -20,7 +20,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts sigmah
|
||||
/usr/local/bin/spotter-appmgr update-proxy sigmah
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -20,7 +20,7 @@ start() {
|
||||
}
|
||||
|
||||
start_post() {
|
||||
/usr/local/bin/spotter-appmgr update-hosts ushahidi
|
||||
/usr/local/bin/spotter-appmgr update-proxy ushahidi
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
Loading…
Reference in New Issue
Block a user