From 92d254da20b944a23e4d25caa3340aa94e9848c8 Mon Sep 17 00:00:00 2001 From: Arthur Vuillard Date: Tue, 30 May 2023 14:30:38 +0200 Subject: [PATCH] prepare some things for preproduction --- la_chariotte/settings.py | 46 ++++++++++++++++++++++++++++++++++------ pyproject.toml | 1 + requirements.txt | 14 ++++++++---- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/la_chariotte/settings.py b/la_chariotte/settings.py index 991a686..12956be 100644 --- a/la_chariotte/settings.py +++ b/la_chariotte/settings.py @@ -12,24 +12,26 @@ https://docs.djangoproject.com/en/4.1/ref/settings/ import os from pathlib import Path +import sentry_sdk +from sentry_sdk.integrations.django import DjangoIntegration + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -BASE_URL = "http://127.0.0.1:8000" # to be moved to settings/dev.py - -BASE_URL = os.getenv("BASE_URL") +BASE_URL = os.getenv("BASE_URL", "http://127.0.0.1:8000") # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-f66vu+dj79c(5u(w2i0indkrlf$qtt!b$dmotnm%5!0a*9+=my" +SECRET_KEY = os.geteng("SECRET_KEY", "django-insecure-f66vu+dj79c(5u(w2i0indkrlf$qtt!b$dmotnm%5!0a*9+=my") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] +DEBUG = os.getenv(DEBUG, "True") == "True" +ALLOWED_HOSTS = ["localhost", "127.0.0.1"] +if os.getenv("ALLOWED_HOSTS"): + ALLOWED_HOSTS += os.getenv("ALLOWED_HOSTS").split(",") # Application definition @@ -145,3 +147,33 @@ MEDIA_ROOT = os.getenv("MEDIA_ROOT", BASE_DIR / "media") # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +# SENTRY settings +# For production logs +SENTRY_DSN = os.getenv("SENTRY_DSN") + +if SENTRY_DSN: + sentry_sdk.init( + dsn=SENTRY_DSN, + integrations=[DjangoIntegration()], + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + # We recommend adjusting this value in production, + traces_sample_rate=1.0, + # If you wish to associate users to errors (assuming you are using + # django.contrib.auth) you may enable sending PII data. + send_default_pii=True, + environment=os.getenv("SENTRY_ENV", "production"), + ) + +# Email settings +EMAIL_BACKEND = os.getenv( + "EMAIL_BACKEND", "django.core.mail.backends.console.EmailBackend" +) +EMAIL_HOST = os.getenv("EMAIL_HOST") +EMAIL_PORT = int(os.getenv("EMAIL_PORT", "587")) +DEFAULT_FROM_EMAIL = os.getenv("DJANGO_DEFAULT_FROM_EMAIL") +DEFAULT_FROM_EMAIL_NAME = os.getenv("DJANGO_DEFAULT_FROM_EMAIL_NAME") +EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER") +EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") +EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS", "True") == "True" diff --git a/pyproject.toml b/pyproject.toml index 7b20b4b..243d912 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ classifiers = ["License :: OSI Approved :: GNU General Public License v3 or late dependencies = [ "django>=4,<5", "psycopg2-binary>=2,<3", + "sentry-sdk<1", ] [build-system] diff --git a/requirements.txt b/requirements.txt index f8b1225..649a9d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,20 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile # -asgiref==3.6.0 +asgiref==3.7.2 # via django -django==4.2 +certifi==2023.5.7 + # via sentry-sdk +django==4.2.1 # via la-chariotte (pyproject.toml) psycopg2-binary==2.9.6 # via la-chariotte (pyproject.toml) -sqlparse==0.4.3 +sentry-sdk==0.20.3 + # via la-chariotte (pyproject.toml) +sqlparse==0.4.4 # via django +urllib3==2.0.2 + # via sentry-sdk