diff --git a/.gitignore b/.gitignore index 5d8adc55..6e5803f3 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ coverage .idea # Local data -settings_local.py +secrets.py *.log # Virtualenv diff --git a/note_kfet/settings/__init__.py b/note_kfet/settings/__init__.py new file mode 100644 index 00000000..28c4d5d8 --- /dev/null +++ b/note_kfet/settings/__init__.py @@ -0,0 +1,11 @@ +import os + +from .base import * + +app_stage = os.environ.get('DJANGO_APP_STAGE', 'dev') +if app_stage == 'prod': + from .production import * +else: + from .development import * + +from .secrets import * diff --git a/note_kfet/settings.py b/note_kfet/settings/base.py similarity index 92% rename from note_kfet/settings.py rename to note_kfet/settings/base.py index 0abdd37d..ba6726ad 100644 --- a/note_kfet/settings.py +++ b/note_kfet/settings/base.py @@ -8,8 +8,8 @@ import sys from django.utils.translation import gettext_lazy as _ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) APPS_DIR = os.path.realpath(os.path.join(BASE_DIR, "apps")) sys.path.append(APPS_DIR) @@ -91,16 +91,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'note_kfet.wsgi.application' -# Database -# https://docs.djangoproject.com/en/2.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators diff --git a/note_kfet/settings/development.py b/note_kfet/settings/development.py new file mode 100644 index 00000000..de46e355 --- /dev/null +++ b/note_kfet/settings/development.py @@ -0,0 +1,47 @@ +######################## +# Development Settings # +######################## +# For local dev on your machine: +# - Enabled by default +# - use sqlite as a db engine , Debug is True. +# - standalone mail server +# - and more ... + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases +from . import * +import os + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +# Break it, fix it! +DEBUG = True + +# Mandatory ! +ALLOWED_HOSTS = ['127.0.0.1','note.comby.xyz'] + +# Emails +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +# EMAIL_USE_SSL = False +# EMAIL_HOST = 'smtp.example.org' +# EMAIL_PORT = 25 +# EMAIL_HOST_USER = 'change_me' +# EMAIL_HOST_PASSWORD = 'change_me' + +SERVER_EMAIL = 'no-reply@example.org' + +# Security settings +SECURE_CONTENT_TYPE_NOSNIFF = False +SECURE_BROWSER_XSS_FILTER = False +SESSION_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = False +CSRF_COOKIE_HTTPONLY = False +X_FRAME_OPTIONS = 'DENY' +SESSION_COOKIE_AGE = 60 * 60 * 3 diff --git a/note_kfet/settings/production.py b/note_kfet/settings/production.py new file mode 100644 index 00000000..834c9633 --- /dev/null +++ b/note_kfet/settings/production.py @@ -0,0 +1,46 @@ +######################## +# Production Settings # +######################## +# For local dev on your machine: +# - Enabled by setting env variable DJANGO_APP_STAGE = 'prod' +# - use Postgresql as db engine +# - Debug should be false. +# - should have a dedicated mail server +# - and more ... + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'mydatabase', + 'USER': 'mydatabaseuser', + 'PASSWORD': 'mypassword', + 'HOST': '127.0.0.1', + 'PORT': '5432', + } +} + +# Break it, fix it! +DEBUG = True + +# Mandatory ! +ALLOWED_HOSTS = ['127.0.0.1','note.comby.xyz'] + +# Emails +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +# EMAIL_USE_SSL = False +# EMAIL_HOST = 'smtp.example.org' +# EMAIL_PORT = 25 +# EMAIL_HOST_USER = 'change_me' +# EMAIL_HOST_PASSWORD = 'change_me' + +SERVER_EMAIL = 'no-reply@example.org' + +# Security settings +SECURE_CONTENT_TYPE_NOSNIFF = False +SECURE_BROWSER_XSS_FILTER = False +SESSION_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = False +CSRF_COOKIE_HTTPONLY = False +X_FRAME_OPTIONS = 'DENY' +SESSION_COOKIE_AGE = 60 * 60 * 3 diff --git a/note_kfet/settings/secrets.py_example b/note_kfet/settings/secrets.py_example new file mode 100644 index 00000000..0f1394f4 --- /dev/null +++ b/note_kfet/settings/secrets.py_example @@ -0,0 +1,2 @@ + +SECRET_KEY = 'CHANGE_ME_IN_LOCAL_SETTINGS!' diff --git a/note_kfet/settings_local.example.py b/note_kfet/settings_local.example.py deleted file mode 100644 index b539cd18..00000000 --- a/note_kfet/settings_local.example.py +++ /dev/null @@ -1,22 +0,0 @@ -# Obligatoire, liste des host autorisés -ALLOWED_HOSTS = ['127.0.0.1'] - -# Emails -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' -# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -# EMAIL_USE_SSL = False -# EMAIL_HOST = 'smtp.example.org' -# EMAIL_PORT = 25 -# EMAIL_HOST_USER = 'change_me' -# EMAIL_HOST_PASSWORD = 'change_me' - -SERVER_EMAIL = 'no-reply@example.org' - -# Security settings -SECURE_CONTENT_TYPE_NOSNIFF = False -SECURE_BROWSER_XSS_FILTER = False -SESSION_COOKIE_SECURE = False -CSRF_COOKIE_SECURE = False -CSRF_COOKIE_HTTPONLY = False -X_FRAME_OPTIONS = 'DENY' -SESSION_COOKIE_AGE = 60 * 60 * 3 diff --git a/uwsgi_note.ini b/uwsgi_note.ini index 465430cb..83c52e50 100644 --- a/uwsgi_note.ini +++ b/uwsgi_note.ini @@ -23,5 +23,4 @@ chmod-socket = 664 # clear environment on exit vacuum = true #Touch reload -touch-reload = /var/www/note_kfet/note_kfet/settings.py - +touch-reload = /var/www/note_kfet/note_kfet/settings/__init__.py