From 54a090712985e21cb31252dec6b8821380520706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastiaan=20Versteeg?= Date: Tue, 24 Jul 2018 23:18:02 +0200 Subject: [PATCH] Replace Slack reporting by Sentry reporting --- .gitlab-ci.yml | 2 +- Dockerfile | 2 + requirements.txt | 1 + website/thaliawebsite/settings/production.py | 71 +++++++++++++++----- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b23e8e2a..2a556937 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,7 +78,7 @@ build docker image: - echo $GITLAB_REGISTRY_PASSWORD | docker login --username thaliawww --password-stdin registry.gitlab.com script: - docker-compose config -q - - docker-compose build --build-arg install_dev_requirements=0 web + - docker-compose build --build-arg install_dev_requirements=0 --build-arg source_commit=$(git rev-parse HEAD) web - docker-compose run --rm web test - docker tag $DOCKER_LATEST $DOCKER_TAG - docker push $DOCKER_TAG diff --git a/Dockerfile b/Dockerfile index c9ebe149..f8ff92b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ LABEL description="Contains the Thaliawebsite Django application" # Arguments ARG install_dev_requirements=1 +ARG source_commit="unknown" # Try to keep static operation on top to maximise Docker cache utilisation @@ -11,6 +12,7 @@ ARG install_dev_requirements=1 ENV DJANGO_PRODUCTION 1 ENV PYTHONUNBUFFERED 1 ENV DEBIAN_FRONTEND=noninteractive +ENV SOURCE_COMMIT=${source_commit} # Set up entrypoint and command ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/requirements.txt b/requirements.txt index 83da67b1..bfea39a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ pyfcm>=1.4.2,<1.5 celery>=4.0<4.2 redis>=2.10<2.11 django-celery-results>=1.0.1<1.1 +raven>=6.4.0,<6.5.0 diff --git a/website/thaliawebsite/settings/production.py b/website/thaliawebsite/settings/production.py index 46f499f5..762c3b52 100644 --- a/website/thaliawebsite/settings/production.py +++ b/website/thaliawebsite/settings/production.py @@ -10,14 +10,11 @@ See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ """ import os -from copy import deepcopy - -from django.utils.log import DEFAULT_LOGGING from . import settings INSTALLED_APPS = settings.INSTALLED_APPS -INSTALLED_APPS.append('django_slack') +INSTALLED_APPS.append('raven.contrib.django.raven_compat') # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.abspath(os.path.join( @@ -135,17 +132,57 @@ X_FRAME_OPTIONS = 'DENY' SECURE_CONTENT_TYPE_NOSNIFF = True SECURE_BROWSER_XSS_FILTER = True -# Slack configuration -SLACK_TOKEN = os.environ.get('DJANGO_SLACK_TOKEN') -SLACK_CHANNEL = '#django-errors' -SLACK_USERNAME = 'Concrexit' -SLACK_ICON_EMOJI = ':pingu:' -SLACK_FAIL_SILENTLY = True - -LOGGING = deepcopy(DEFAULT_LOGGING) -LOGGING['handlers']['slack-error'] = { - 'level': 'ERROR', - 'class': 'django_slack.log.SlackExceptionHandler', +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse', + }, + }, + 'root': { + 'level': 'WARNING', + 'handlers': ['sentry'], + }, + 'formatters': { + 'verbose': { + 'format': '%(levelname)s %(asctime)s %(module)s ' + '%(process)d %(thread)d %(message)s' + }, + }, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'verbose' + }, + 'sentry': { + 'level': 'ERROR', + 'filters': ['require_debug_false'], + 'class': 'raven.contrib.django.raven_compat.' + 'handlers.SentryHandler', + }, + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'level': 'INFO', + }, + 'raven': { + 'level': 'DEBUG', + 'handlers': ['console'], + 'propagate': False, + }, + 'sentry.errors': { + 'level': 'DEBUG', + 'handlers': ['console'], + 'propagate': False, + }, + }, +} + + +RAVEN_CONFIG = { + 'dsn': os.environ.get('SENTRY_DSN'), + 'release': os.environ.get('SOURCE_COMMIT'), } -LOGGING['loggers']['django']['handlers'].append('slack-error') -LOGGING['loggers']['django']['handlers'].remove('mail_admins') -- GitLab