From 19cd1624c161d09958299f54c4bcf675c2c72bce Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 11 Apr 2019 13:43:49 +0200 Subject: [PATCH] replace cherrypy with daphne --- .../templates/passbook-web-deployment.yaml | 2 +- passbook/core/management/commands/web.py | 34 ++++++++----------- passbook/core/requirements.txt | 1 - passbook/core/settings.py | 17 +++------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/helm/passbook/templates/passbook-web-deployment.yaml b/helm/passbook/templates/passbook-web-deployment.yaml index df98947a2..2308300ca 100644 --- a/helm/passbook/templates/passbook-web-deployment.yaml +++ b/helm/passbook/templates/passbook-web-deployment.yaml @@ -29,7 +29,7 @@ spec: image: "docker.pkg.beryju.org/passbook:{{ .Values.image.tag }}" imagePullPolicy: IfNotPresent command: ["/bin/sh","-c"] - args: ["./manage.py migrate && daphne -p 8000 passbook.core.asgi:application"] + args: ["./manage.py migrate && ./manage.py web"] ports: - name: http containerPort: 8000 diff --git a/passbook/core/management/commands/web.py b/passbook/core/management/commands/web.py index da8c66879..329e070e6 100644 --- a/passbook/core/management/commands/web.py +++ b/passbook/core/management/commands/web.py @@ -2,11 +2,11 @@ from logging import getLogger -import cherrypy -from django.conf import settings +from daphne.cli import CommandLineInterface from django.core.management.base import BaseCommand +from django.utils import autoreload -from passbook.core.wsgi import application +from passbook.lib.config import CONFIG LOGGER = getLogger(__name__) @@ -16,19 +16,15 @@ class Command(BaseCommand): def handle(self, *args, **options): """passbook cherrypy server""" - config = settings.CHERRYPY_SERVER - config.update(**options) - cherrypy.config.update(config) - cherrypy.tree.graft(application, '/') - # Mount NullObject to serve static files - cherrypy.tree.mount(None, '/static', 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() - cherrypy.engine.block() + autoreload.run_with_reloader(self.daphne_server) + + def daphne_server(self): + """Run daphne server within autoreload""" + autoreload.raise_last_exception() + with CONFIG.cd('web'): + CommandLineInterface().run([ + '-p', str(CONFIG.get('port', 8000)), + '-b', CONFIG.get('listen', '0.0.0.0'), # nosec + '--access-log', '/dev/null', + 'passbook.core.asgi:application' + ]) diff --git a/passbook/core/requirements.txt b/passbook/core/requirements.txt index 5d7793425..78e07757a 100644 --- a/passbook/core/requirements.txt +++ b/passbook/core/requirements.txt @@ -1,5 +1,4 @@ celery -cherrypy colorlog django-ipware django-model-utils diff --git a/passbook/core/settings.py b/passbook/core/settings.py index 47dda43c3..144dbd516 100644 --- a/passbook/core/settings.py +++ b/passbook/core/settings.py @@ -231,18 +231,6 @@ sentry_init( send_default_pii=True ) - -# CherryPY settings -with CONFIG.cd('web'): - CHERRYPY_SERVER = { - 'server.socket_host': CONFIG.get('listen', '0.0.0.0'), # nosec - 'server.socket_port': CONFIG.get('port', 8000), - 'server.thread_pool': CONFIG.get('threads', 30), - 'log.screen': False, - 'log.access_file': '', - 'log.error_file': '', - } - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ @@ -325,6 +313,11 @@ with CONFIG.cd('log'): 'level': 'DEBUG', 'propagate': True, }, + 'daphne': { + 'handlers': LOG_HANDLERS, + 'level': 'DEBUG', + 'propagate': True, + } } }