From 90eae21bc7ced291e20d94ba65828043cf16e718 Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Sat, 17 Mar 2018 13:59:04 +0100 Subject: [PATCH] Add sentry and fabfile --- bbssite/settings.py | 51 +++++++++++++++++++++++++++++++++++++++++---- bbssite/wsgi.py | 4 +++- fabfile.py | 49 +++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 ++- 4 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 fabfile.py diff --git a/bbssite/settings.py b/bbssite/settings.py index be4f0ad..1db6c41 100755 --- a/bbssite/settings.py +++ b/bbssite/settings.py @@ -73,7 +73,7 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'bbssite.urls' -INSTALLED_APPS = ( +INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', @@ -87,10 +87,11 @@ INSTALLED_APPS = ( 'django_extensions', 'rest_framework', 'easy_thumbnails', -) -LOCAL_APPS = ( + 'raven.contrib.django.raven_compat', +] +LOCAL_APPS = [ 'main', -) +] INSTALLED_APPS += LOCAL_APPS LOGIN_REDIRECT_URL = '/' @@ -108,6 +109,48 @@ THUMBNAIL_ALIASES = { }, } +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'root': { + 'level': 'INFO', + 'handlers': ['console', 'sentry'], + }, + 'formatters': { + 'verbose': { + 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' + }, + }, + 'handlers': { + 'sentry': { + 'level': 'WARNING', + 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', + }, + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'verbose' + } + }, + 'loggers': { + 'django.db.backends': { + 'level': 'ERROR', + 'handlers': ['console'], + 'propagate': False, + }, + 'raven': { + 'level': 'WARNING', + 'handlers': ['console'], + 'propagate': False, + }, + 'sentry.errors': { + 'level': 'WARNING', + 'handlers': ['console'], + 'propagate': False, + }, + }, +} + try: from .local_settings import * except ImportError: diff --git a/bbssite/wsgi.py b/bbssite/wsgi.py index fce2b90..6a29147 100644 --- a/bbssite/wsgi.py +++ b/bbssite/wsgi.py @@ -1,6 +1,8 @@ import os +from django.core.wsgi import get_wsgi_application +from raven.contrib.django.middleware.wsgi import Sentry os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bbssite.settings') -from django.core.wsgi import get_wsgi_application application = get_wsgi_application() +application = Sentry(application) diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 0000000..441a4f0 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,49 @@ +import os +from contextlib import contextmanager as _contextmanager +from fabric.api import run, sudo, env, cd, prefix + +env.use_ssh_config = True +env.hosts = ['dreamcast.neuf.no'] +env.user = 'gitdeploy' + + +BASE_PATH = '/var/www/neuf.no/' + +PROJECTS = { + 'bbs': { + 'path': os.path.join(BASE_PATH, 'bbs'), + 'process_name': 'bbs.neuf.no' + }, + 'fantastene': { + 'path': os.path.join(BASE_PATH, 'bbs_fantastene'), + 'process_name': 'fantastene-bbs.neuf.no' + }, + 'arrut': { + 'path': os.path.join(BASE_PATH, 'bbs_arrut'), + 'process_name': 'arrut-bbs.neuf.no' + } +} + + +@_contextmanager +def virtualenv(project): + activate = 'source {}/venv/bin/activate'.format(project['path']) + with cd(project['path']), prefix(activate): + yield + + +def deploy(project_name='bbs'): + if project_name not in PROJECTS: + print("'{}' not in valid projects({})".format(project_name, ', '.join(sorted(PROJECTS.keys())))) + exit(1) + + project = PROJECTS[project_name] + with virtualenv(project): + run('git pull') # Get source + run('pip install -r requirements.txt') # install deps in virtualenv + run('umask 022; python manage.py collectstatic --noinput') # Collect static + run('python manage.py migrate') # Run DB migrations + + # Reload + sudo('/usr/bin/supervisorctl pid {process_name} | xargs kill -HUP'.format(process_name=project['process_name']), + shell=False) diff --git a/requirements.txt b/requirements.txt index 833e69e..dbf3ad8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ facebook-sdk==2.0.0 gunicorn==19.7.1 mysqlclient==1.3.12 djangorestframework==3.6.4 -Pillow==5.0.0 \ No newline at end of file +Pillow==5.0.0 +raven==6.6.0 \ No newline at end of file