Add proxy registration/unregistration
This commit is contained in:
parent
be054ed17b
commit
571e641787
@ -8,7 +8,7 @@ NGINX = '''server {{
|
|||||||
error_log /var/log/nginx/{app}.error.log;
|
error_log /var/log/nginx/{app}.error.log;
|
||||||
|
|
||||||
location / {{
|
location / {{
|
||||||
proxy_pass http://{app}:8080;
|
proxy_pass http://{ip}:8080;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
error_page 502 /502.html;
|
error_page 502 /502.html;
|
||||||
|
@ -6,7 +6,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import urllib
|
import urllib
|
||||||
from spoc import config as spoc_config, repo_local, repo_online
|
from spoc import config as spoc_config, net as spoc_net, repo_local, repo_online
|
||||||
from spoc.app import App
|
from spoc.app import App
|
||||||
from spoc.container import Container, ContainerState
|
from spoc.container import Container, ContainerState
|
||||||
from spoc.depsolver import DepSolver
|
from spoc.depsolver import DepSolver
|
||||||
@ -23,16 +23,20 @@ def register_app(app, host, login, password):
|
|||||||
'password': password if password else 'N/A',
|
'password': password if password else 'N/A',
|
||||||
'visible': False,
|
'visible': False,
|
||||||
})
|
})
|
||||||
|
register_proxy(app)
|
||||||
|
|
||||||
def unregister_app(app):
|
def unregister_app(app):
|
||||||
|
unregister_proxy(app)
|
||||||
config.unregister_app(app)
|
config.unregister_app(app)
|
||||||
|
|
||||||
def register_proxy(app):
|
def register_proxy(app):
|
||||||
# Setup proxy configuration and reload nginx
|
# Setup proxy configuration and reload nginx
|
||||||
app_host = config.get_apps()[app]['host']
|
app_host = config.get_apps()[app]['host']
|
||||||
host = config.get_host()
|
host = config.get_host()
|
||||||
|
# Assume that the main container has always the same name as the app
|
||||||
|
app_ip = spoc_net.get_ip(app)
|
||||||
with open(os.path.join(NGINX_DIR, f'{app}.conf'), 'w') as f:
|
with open(os.path.join(NGINX_DIR, f'{app}.conf'), 'w') as f:
|
||||||
f.write(templates.NGINX.format(app=app, host=app_host, domain=host['domain'], port=host['port']))
|
f.write(templates.NGINX.format(app=app, host=app_host, ip=app_ip, domain=host['domain'], port=host['port']))
|
||||||
reload_nginx()
|
reload_nginx()
|
||||||
|
|
||||||
def unregister_proxy(app):
|
def unregister_proxy(app):
|
||||||
@ -146,7 +150,7 @@ def update_app_autostart(app_name, enabled):
|
|||||||
App(app_name, False).set_autostart(enabled)
|
App(app_name, False).set_autostart(enabled)
|
||||||
|
|
||||||
def is_app_started(app_name):
|
def is_app_started(app_name):
|
||||||
# Assume that the main container has always the same name as app
|
# Assume that the main container has always the same name as the app
|
||||||
return Container(app_name).get_state() == ContainerState.RUNNING
|
return Container(app_name).get_state() == ContainerState.RUNNING
|
||||||
|
|
||||||
def is_app_autostarted(app_name):
|
def is_app_autostarted(app_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user