From 9283638ba806e008026f796548137bcac07c9b61 Mon Sep 17 00:00:00 2001 From: Gregory Trullemans Date: Thu, 20 Jun 2024 07:23:56 +0200 Subject: [PATCH] Add Procfile and Docker file --- Procfile | 2 ++ comptabilite/settings.py | 35 +++++++++++++++++++++++++++++------ docker-compose.yaml | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 Procfile create mode 100644 docker-compose.yaml diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..f77ba1d --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: python manage.py migrate +web: gunicorn config.wsgi diff --git a/comptabilite/settings.py b/comptabilite/settings.py index 48a19bc..ee5c24e 100644 --- a/comptabilite/settings.py +++ b/comptabilite/settings.py @@ -12,6 +12,26 @@ https://docs.djangoproject.com/en/1.8/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +import environ +from pathlib import Path + +# Initialise environment variables +env = environ.Env() +environ.Env.read_env() + +# Sentry +SENTRY_DSN = env("SENTRY_DSN", default=None) +if SENTRY_DSN is not None: + import sentry_sdk + from sentry_sdk.integrations.django import DjangoIntegration + + sentry_sdk.init( + dsn=SENTRY_DSN, + integrations=[DjangoIntegration()], + traces_sample_rate=env("SENTRY_TRACES_SAMPLE_RATE", default=1.0), + send_default_pii=True, + debug=env("SENTRY_DEBUG", default=True), + ) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -20,12 +40,12 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'mvu)=%+ocv3n9dljxq0===$v!01@rw2j$++i&h6#65cu1#0ff@' +SECRET_KEY = env("SECRET_KEY", default="Super Little Poney 2000") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = env("ALLOWED_HOSTS", default="localhost").split() # Application definition @@ -75,11 +95,14 @@ WSGI_APPLICATION = 'comptabilite.wsgi.application' # Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +# } DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } + "default": env.db_url("DATABASE_URL", default=os.path.join(BASE_DIR, 'db.sqlite3')) } diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f928e6f --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,14 @@ +version: "3" +services: + db: + image: "postgres:14" + restart: always + container_name: "compta_inde_db_container" + environment: + POSTGRES_DB: "compta_inde_db" + POSTGRES_USER: "Greg&Arnaud" + POSTGRES_PASSWORD: "K&kP4t4t0r1!" + ports: + - "5432:5432" + volumes: + - ./data:/var/lib/postgresql/data \ No newline at end of file