diff --git a/passbook/root/asgi.py b/passbook/app_gw/asgi.py similarity index 100% rename from passbook/root/asgi.py rename to passbook/app_gw/asgi.py diff --git a/passbook/app_gw/management/__init__.py b/passbook/app_gw/management/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/app_gw/management/commands/__init__.py b/passbook/app_gw/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/app_gw/management/commands/app_gw_web.py b/passbook/app_gw/management/commands/app_gw_web.py new file mode 100644 index 000000000..5b6945ce1 --- /dev/null +++ b/passbook/app_gw/management/commands/app_gw_web.py @@ -0,0 +1,30 @@ +"""passbook app_gw webserver management command""" + +from logging import getLogger + +from daphne.cli import CommandLineInterface +from django.core.management.base import BaseCommand +from django.utils import autoreload + +from passbook.lib.config import CONFIG + +LOGGER = getLogger(__name__) + + +class Command(BaseCommand): + """Run Daphne Webserver for app_gw""" + + def handle(self, *args, **options): + """passbook daphne server""" + autoreload.run_with_reloader(self.daphne_server) + + def daphne_server(self): + """Run daphne server within autoreload""" + autoreload.raise_last_exception() + CommandLineInterface().run([ + '-p', str(CONFIG.y('app_gw.port', 8000)), + '-b', CONFIG.y('app_gw.listen', '0.0.0.0'), # nosec + '--access-log', '/dev/null', + '--application-close-timeout', '500', + 'passbook.app_gw.asgi:application' + ]) diff --git a/passbook/core/management/commands/web.py b/passbook/core/management/commands/web.py index de424093e..3fdbf097c 100644 --- a/passbook/core/management/commands/web.py +++ b/passbook/core/management/commands/web.py @@ -2,11 +2,12 @@ from logging import getLogger -from daphne.cli import CommandLineInterface +import cherrypy +from django.conf import settings from django.core.management.base import BaseCommand -from django.utils import autoreload from passbook.lib.config import CONFIG +from passbook.root.wsgi import application LOGGER = getLogger(__name__) @@ -15,16 +16,21 @@ class Command(BaseCommand): """Run CherryPy webserver""" def handle(self, *args, **options): - """passbook daphne server""" - autoreload.run_with_reloader(self.daphne_server) - - def daphne_server(self): - """Run daphne server within autoreload""" - autoreload.raise_last_exception() - CommandLineInterface().run([ - '-p', str(CONFIG.y('web.port', 8000)), - '-b', CONFIG.y('web.listen', '0.0.0.0'), # nosec - '--access-log', '/dev/null', - '--application-close-timeout', '500', - 'passbook.root.asgi:application' - ]) + """passbook cherrypy server""" + cherrypy.config.update(CONFIG.get('web')) + cherrypy.tree.graft(application, '/') + # Mount NullObject to serve static files + cherrypy.tree.mount(None, settings.STATIC_URL, config={ + '/': { + 'tools.staticdir.on': True, + 'tools.staticdir.dir': settings.STATIC_ROOT, + 'tools.expires.on': True, + 'tools.expires.secs': 86400, + 'tools.gzip.on': True, + } + }) + cherrypy.engine.start() + for file in CONFIG.loaded_file: + cherrypy.engine.autoreload.files.add(file) + LOGGER.info("Added '%s' to autoreload triggers", file) + cherrypy.engine.block() diff --git a/passbook/lib/default.yml b/passbook/lib/default.yml index 10562100c..b14c25110 100644 --- a/passbook/lib/default.yml +++ b/passbook/lib/default.yml @@ -23,9 +23,13 @@ email: use_ssl: false from: passbook web: - listen: 0.0.0.0 - port: 8000 - threads: 30 + server.socket_host: 0.0.0.0 + server.socket_port: 8000 + server.thread_pool: 20 + log.screen: false + log.access_file: '' + log.error_file: '' + debug: false secure_proxy_header: HTTP_X_FORWARDED_PROTO: https @@ -96,3 +100,6 @@ saml_idp: types: - passbook.saml_idp.processors.generic - passbook.saml_idp.processors.salesforce +app_gw: + listen: 0.0.0.0 + port: 8000 diff --git a/passbook/root/requirements.txt b/passbook/root/requirements.txt index b3ddc9a87..32f120342 100644 --- a/passbook/root/requirements.txt +++ b/passbook/root/requirements.txt @@ -1,5 +1,6 @@ celery colorlog +cherrypy django-ipware django-model-utils django-redis @@ -11,5 +12,4 @@ psycopg2 PyYAML sentry-sdk pip -whitenoise urllib3<1.25,>=1.21.1 diff --git a/passbook/root/settings.py b/passbook/root/settings.py index 512f64262..9115b31e5 100644 --- a/passbook/root/settings.py +++ b/passbook/root/settings.py @@ -122,7 +122,6 @@ CACHES = { MIDDLEWARE = [ 'django.contrib.sessions.middleware.SessionMiddleware', - 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'passbook.app_gw.middleware.ApplicationGatewayMiddleware', 'django.middleware.security.SecurityMiddleware', @@ -239,7 +238,6 @@ if not DEBUG: # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' with CONFIG.cd('log'): LOGGING = {