Séparation du fichier de configuration à l'aide de django-split-settings
This commit is contained in:
parent
96de9e859c
commit
ae1a3edd99
@ -9,9 +9,11 @@ COPY requirements.txt $APPS_DIR/
|
||||
WORKDIR $APPS_DIR
|
||||
|
||||
# uWSGI requires linux-headers
|
||||
# django-split-settings needs ca-certificates as they changed on PyPi
|
||||
RUN set -ex \
|
||||
&& buildDeps=' \
|
||||
build-base \
|
||||
ca-certificates \
|
||||
linux-headers \
|
||||
python3-dev \
|
||||
' \
|
||||
|
1
TODO
1
TODO
@ -1,6 +1,5 @@
|
||||
# À faire
|
||||
|
||||
* tester django-split-settings pour voir ce que ça donne
|
||||
* étudier la possibilité à l'utilisateur, via des variables d'environnement, de configurer un email, une autre BDD, etc.
|
||||
|
||||
## Dépôt / code
|
||||
|
0
collection/collection/components/__init__.py
Normal file
0
collection/collection/components/__init__.py
Normal file
89
collection/collection/components/common.py
Normal file
89
collection/collection/components/common.py
Normal file
@ -0,0 +1,89 @@
|
||||
"""
|
||||
Django settings for collection project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 1.11.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.11/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.11/ref/settings/
|
||||
"""
|
||||
import os
|
||||
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
DEBUG = False
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'core',
|
||||
'games.apps.GamesConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'collection.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'collection.wsgi.application'
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(os.path.abspath(os.path.curdir), 'static')
|
||||
if os.getenv('STATIC_ROOT', None):
|
||||
STATIC_ROOT = os.path.abspath(os.getenv('STATIC_ROOT'))
|
||||
|
15
collection/collection/components/database.py
Normal file
15
collection/collection/components/database.py
Normal file
@ -0,0 +1,15 @@
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||
|
||||
DB_DIR = os.getenv('DB_DIR', os.path.join(BASE_DIR, 'db'))
|
||||
|
||||
if not os.path.exists(DB_DIR):
|
||||
os.makedirs(DB_DIR)
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db', 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
25
collection/collection/components/i18n.py
Normal file
25
collection/collection/components/i18n.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
LANGUAGE_CODE = 'fr'
|
||||
|
||||
LANGUAGES = (
|
||||
('fr', _('French')),
|
||||
('en', _('English')),
|
||||
)
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = False
|
||||
|
||||
USE_TZ = False
|
||||
|
||||
# Translation directories
|
||||
LOCALE_PATHS = [
|
||||
os.path.join(BASE_DIR, 'conf/locale'),
|
||||
os.path.join(BASE_DIR, 'collection/locale')
|
||||
]
|
||||
|
0
collection/collection/environments/__init__.py
Normal file
0
collection/collection/environments/__init__.py
Normal file
11
collection/collection/environments/development.py
Normal file
11
collection/collection/environments/development.py
Normal file
@ -0,0 +1,11 @@
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'tqma23#v!#ecse_gz_u(1oa6+x%1uyi718an9%nefqhi$0q_eg'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
@ -1,8 +1,6 @@
|
||||
"""
|
||||
Django production settings
|
||||
"""
|
||||
import os
|
||||
from collection.settings import * # NOQA
|
||||
|
||||
DEBUG = os.getenv('DEBUG', False)
|
||||
|
@ -1,139 +1,29 @@
|
||||
"""
|
||||
Django settings for collection project.
|
||||
This is a django-split-settings main file.
|
||||
For more information read this:
|
||||
https://github.com/sobolevn/django-split-settings
|
||||
|
||||
Generated by 'django-admin startproject' using Django 1.11.
|
||||
Default environment is `developement`.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.11/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.11/ref/settings/
|
||||
To change settings file:
|
||||
`DJANGO_ENV=production python manage.py runserver`
|
||||
"""
|
||||
|
||||
import os
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from split_settings.tools import optional, include
|
||||
from os import environ
|
||||
|
||||
ENV = environ.get('DJANGO_ENV') or 'development'
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
base_settings = [
|
||||
'components/common.py', # standard django settings
|
||||
'components/database.py', # SQLite 3
|
||||
'components/i18n.py', # Internationalisation and localization
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'tqma23#v!#ecse_gz_u(1oa6+x%1uyi718an9%nefqhi$0q_eg'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'core',
|
||||
'games.apps.GamesConfig',
|
||||
# Select the right env:
|
||||
'environments/%s.py' % ENV,
|
||||
# Optionally override some settings:
|
||||
optional('environments/local_settings.py'),
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'collection.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'collection.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db', 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'fr'
|
||||
|
||||
LANGUAGES = (
|
||||
('fr', _('French')),
|
||||
('en', _('English')),
|
||||
)
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = False
|
||||
|
||||
USE_TZ = False
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(os.path.abspath(os.path.curdir), 'static')
|
||||
if os.getenv('STATIC_ROOT', None):
|
||||
STATIC_ROOT = os.path.abspath(os.getenv('STATIC_ROOT'))
|
||||
|
||||
# Translation directories
|
||||
LOCALE_PATHS = [
|
||||
os.path.join(BASE_DIR, 'conf/locale'),
|
||||
os.path.join(BASE_DIR, 'collection/locale')
|
||||
]
|
||||
# Include settings:
|
||||
include(*base_settings)
|
||||
|
@ -5,10 +5,10 @@ set -e
|
||||
chown -R guest "$DB_DIR"
|
||||
|
||||
if [ "$1" = 'dev' ]; then
|
||||
export DJANGO_SETTINGS_MODULE=collection.settings
|
||||
export DJANGO_ENV='development'
|
||||
exec python3 manage.py runserver 0.0.0.0:8000
|
||||
elif [ "$1" = 'prod' ]; then
|
||||
export DJANGO_SETTINGS_MODULE=collection.production
|
||||
export DJANGO_ENV='production'
|
||||
# Collect static files
|
||||
python3 manage.py collectstatic --noinput --clear -v 0
|
||||
exec uwsgi --ini uwsgi.ini --pythonpath "$APPS_DIR" --static-map=/static/="$STATIC_ROOT"
|
||||
|
@ -1,3 +1,4 @@
|
||||
Django==1.11.4
|
||||
django-split-settings==0.2.5
|
||||
PyYAML==3.12
|
||||
uWSGI==2.0.15
|
||||
|
Loading…
Reference in New Issue
Block a user