Add proxy registration/unregistration

This commit is contained in:
Disassembler 2020-04-04 13:38:03 +02:00
parent be054ed17b
commit 571e641787
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
2 changed files with 8 additions and 4 deletions

View File

@ -8,7 +8,7 @@ NGINX = '''server {{
error_log /var/log/nginx/{app}.error.log;
location / {{
proxy_pass http://{app}:8080;
proxy_pass http://{ip}:8080;
}}
error_page 502 /502.html;

View File

@ -6,7 +6,7 @@ import os
import shutil
import subprocess
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.container import Container, ContainerState
from spoc.depsolver import DepSolver
@ -23,16 +23,20 @@ def register_app(app, host, login, password):
'password': password if password else 'N/A',
'visible': False,
})
register_proxy(app)
def unregister_app(app):
unregister_proxy(app)
config.unregister_app(app)
def register_proxy(app):
# Setup proxy configuration and reload nginx
app_host = config.get_apps()[app]['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:
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()
def unregister_proxy(app):
@ -146,7 +150,7 @@ def update_app_autostart(app_name, enabled):
App(app_name, False).set_autostart(enabled)
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
def is_app_autostarted(app_name):