core: revert to cherrypy for main webserver and use daphne only for app_gw
This commit is contained in:
parent
4d0148193f
commit
ed25801e6e
0
passbook/app_gw/management/__init__.py
Normal file
0
passbook/app_gw/management/__init__.py
Normal file
0
passbook/app_gw/management/commands/__init__.py
Normal file
0
passbook/app_gw/management/commands/__init__.py
Normal file
30
passbook/app_gw/management/commands/app_gw_web.py
Normal file
30
passbook/app_gw/management/commands/app_gw_web.py
Normal file
|
@ -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'
|
||||||
|
])
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
from logging import getLogger
|
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.core.management.base import BaseCommand
|
||||||
from django.utils import autoreload
|
|
||||||
|
|
||||||
from passbook.lib.config import CONFIG
|
from passbook.lib.config import CONFIG
|
||||||
|
from passbook.root.wsgi import application
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getLogger(__name__)
|
||||||
|
|
||||||
|
@ -15,16 +16,21 @@ class Command(BaseCommand):
|
||||||
"""Run CherryPy webserver"""
|
"""Run CherryPy webserver"""
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
"""passbook daphne server"""
|
"""passbook cherrypy server"""
|
||||||
autoreload.run_with_reloader(self.daphne_server)
|
cherrypy.config.update(CONFIG.get('web'))
|
||||||
|
cherrypy.tree.graft(application, '/')
|
||||||
def daphne_server(self):
|
# Mount NullObject to serve static files
|
||||||
"""Run daphne server within autoreload"""
|
cherrypy.tree.mount(None, settings.STATIC_URL, config={
|
||||||
autoreload.raise_last_exception()
|
'/': {
|
||||||
CommandLineInterface().run([
|
'tools.staticdir.on': True,
|
||||||
'-p', str(CONFIG.y('web.port', 8000)),
|
'tools.staticdir.dir': settings.STATIC_ROOT,
|
||||||
'-b', CONFIG.y('web.listen', '0.0.0.0'), # nosec
|
'tools.expires.on': True,
|
||||||
'--access-log', '/dev/null',
|
'tools.expires.secs': 86400,
|
||||||
'--application-close-timeout', '500',
|
'tools.gzip.on': True,
|
||||||
'passbook.root.asgi:application'
|
}
|
||||||
])
|
})
|
||||||
|
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()
|
||||||
|
|
|
@ -23,9 +23,13 @@ email:
|
||||||
use_ssl: false
|
use_ssl: false
|
||||||
from: passbook <passbook@domain.tld>
|
from: passbook <passbook@domain.tld>
|
||||||
web:
|
web:
|
||||||
listen: 0.0.0.0
|
server.socket_host: 0.0.0.0
|
||||||
port: 8000
|
server.socket_port: 8000
|
||||||
threads: 30
|
server.thread_pool: 20
|
||||||
|
log.screen: false
|
||||||
|
log.access_file: ''
|
||||||
|
log.error_file: ''
|
||||||
|
|
||||||
debug: false
|
debug: false
|
||||||
secure_proxy_header:
|
secure_proxy_header:
|
||||||
HTTP_X_FORWARDED_PROTO: https
|
HTTP_X_FORWARDED_PROTO: https
|
||||||
|
@ -96,3 +100,6 @@ saml_idp:
|
||||||
types:
|
types:
|
||||||
- passbook.saml_idp.processors.generic
|
- passbook.saml_idp.processors.generic
|
||||||
- passbook.saml_idp.processors.salesforce
|
- passbook.saml_idp.processors.salesforce
|
||||||
|
app_gw:
|
||||||
|
listen: 0.0.0.0
|
||||||
|
port: 8000
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
celery
|
celery
|
||||||
colorlog
|
colorlog
|
||||||
|
cherrypy
|
||||||
django-ipware
|
django-ipware
|
||||||
django-model-utils
|
django-model-utils
|
||||||
django-redis
|
django-redis
|
||||||
|
@ -11,5 +12,4 @@ psycopg2
|
||||||
PyYAML
|
PyYAML
|
||||||
sentry-sdk
|
sentry-sdk
|
||||||
pip
|
pip
|
||||||
whitenoise
|
|
||||||
urllib3<1.25,>=1.21.1
|
urllib3<1.25,>=1.21.1
|
||||||
|
|
|
@ -122,7 +122,6 @@ CACHES = {
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'passbook.app_gw.middleware.ApplicationGatewayMiddleware',
|
'passbook.app_gw.middleware.ApplicationGatewayMiddleware',
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
@ -239,7 +238,6 @@ if not DEBUG:
|
||||||
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
||||||
|
|
||||||
with CONFIG.cd('log'):
|
with CONFIG.cd('log'):
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
|
|
Reference in a new issue