Switch settings to use "the one true way" approach
The advantage of this approach is that the production and dev configurations are in version control, so there's less opportunity for surprises. As advocated by Jacob Kaplan-Moss (OSCON 2011) and Two Scoops of Django book.
This commit is contained in:
parent
fe4112c879
commit
3826b6fb66
10 changed files with 65 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ conservancy/static/docs/SFC_response_to_summary_judgement.pdf
|
||||||
conservancy/static/docs/Vizio_summary_judgement_reply_brief.pdf
|
conservancy/static/docs/Vizio_summary_judgement_reply_brief.pdf
|
||||||
conservancy/static/docs/2023-4-28 VIZIOs Motion for Summary Judgment with Reservation.pdf
|
conservancy/static/docs/2023-4-28 VIZIOs Motion for Summary Judgment with Reservation.pdf
|
||||||
|
|
||||||
|
/conservancy/secrets.json
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
# To build the Docker image with the necessary dependencies:
|
# To build the Docker image with the necessary dependencies:
|
||||||
# docker build --tag sfconservancy.org-bookworm --file Dockerfile-debian-bookworm .
|
# docker build --tag sfconservancy.org-bookworm --file Dockerfile-debian-bookworm .
|
||||||
#
|
#
|
||||||
# To run the website, first ensure you have a
|
|
||||||
# "conservancy/djangocommonsettings.py" file, with an appropriate database path.
|
|
||||||
#
|
|
||||||
# [FIRST RUN ONLY] If you don't have an existing copy of the database, run:
|
# [FIRST RUN ONLY] If you don't have an existing copy of the database, run:
|
||||||
# touch conservancy-website.sqlite3
|
# touch conservancy-website.sqlite3
|
||||||
#
|
#
|
||||||
|
|
|
@ -38,10 +38,6 @@ Debian:
|
||||||
|
|
||||||
python3 -m pip install -r requirements.txt
|
python3 -m pip install -r requirements.txt
|
||||||
|
|
||||||
You'll need a copy of `conservancy/djangocommonsettings.py`, a file that not
|
|
||||||
committed to the repository that has database settings and other
|
|
||||||
environment-specific config.
|
|
||||||
|
|
||||||
To run the tests, install `pytest-django` and run pytest:
|
To run the tests, install `pytest-django` and run pytest:
|
||||||
|
|
||||||
python3 -m pip install pytest-django
|
python3 -m pip install pytest-django
|
||||||
|
|
4
TODO.md
4
TODO.md
|
@ -5,12 +5,12 @@
|
||||||
* use `<detail>` elements for supporter page hidden sections, rather than complex jQuery - or consider Alpine.js
|
* use `<detail>` elements for supporter page hidden sections, rather than complex jQuery - or consider Alpine.js
|
||||||
* replace `internalNavigate` with inline flexbox layout
|
* replace `internalNavigate` with inline flexbox layout
|
||||||
* add tests for main pages returning 200
|
* add tests for main pages returning 200
|
||||||
* standardise settings to replace `settings.py` and `djangocommonsettings.py`
|
|
||||||
with `settings/prod.py` and move `SECRET_KEY` to an environment variable
|
|
||||||
|
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
|
|
||||||
|
* standardise settings to replace `settings.py` and `djangocommonsettings.py`
|
||||||
|
with `settings/prod.py` and move `SECRET_KEY` to an environment variable
|
||||||
* migrate to Django 4.2 LTS
|
* migrate to Django 4.2 LTS
|
||||||
* review `apache2` directory - may be unused
|
* review `apache2` directory - may be unused
|
||||||
* add deployment script that runs migrations and collects static files
|
* add deployment script that runs migrations and collects static files
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from datetime import datetime as DateTime
|
from datetime import datetime as DateTime
|
||||||
|
|
||||||
from . import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from .fundgoal.models import FundraisingGoal
|
from .fundgoal.models import FundraisingGoal
|
||||||
|
|
||||||
SITE_FUNDGOAL = 'cy2023-end-year-match'
|
SITE_FUNDGOAL = 'cy2023-end-year-match'
|
||||||
|
|
0
conservancy/settings/__init__.py
Normal file
0
conservancy/settings/__init__.py
Normal file
|
@ -19,13 +19,9 @@
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .djangocommonsettings import *
|
|
||||||
|
|
||||||
SITE_ID = 2
|
SITE_ID = 2
|
||||||
ROOT_URLCONF = 'conservancy.urls'
|
ROOT_URLCONF = 'conservancy.urls'
|
||||||
|
|
||||||
FORCE_CANONICAL_HOSTNAME = False if DEBUG else 'sfconservancy.org'
|
|
||||||
|
|
||||||
REDIRECT_TABLE = {
|
REDIRECT_TABLE = {
|
||||||
'www.sf-conservancy.org': 'sfconservancy.org',
|
'www.sf-conservancy.org': 'sfconservancy.org',
|
||||||
}
|
}
|
||||||
|
@ -101,7 +97,7 @@ INSTALLED_APPS = [
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
17
conservancy/settings/dev.py
Normal file
17
conservancy/settings/dev.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
from .base import *
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
|
FORCE_CANONICAL_HOSTNAME = False
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'NAME': 'conservancy-website.sqlite3',
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
||||||
|
|
||||||
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
41
conservancy/settings/prod.py
Normal file
41
conservancy/settings/prod.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
|
from .base import *
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
|
ALLOWED_HOSTS = ['www.sfconservancy.org', 'sfconservancy.org']
|
||||||
|
|
||||||
|
FORCE_CANONICAL_HOSTNAME = 'sfconservancy.org'
|
||||||
|
|
||||||
|
ADMINS = [
|
||||||
|
('Bradley M. Kuhn', 'sysadmin@sfconservancy.org'),
|
||||||
|
('Ben Sturmfels', 'sysadmin+conservancy@sturm.com.au'),
|
||||||
|
]
|
||||||
|
|
||||||
|
MANAGERS = [
|
||||||
|
('Bradley M. Kuhn', 'sysadmin@sfconservancy.org'),
|
||||||
|
]
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'NAME': '/var/lib/www/database/conservancy-website.sqlite3',
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Apache/mod_wsgi doesn't make it straightforward to pass environment variables
|
||||||
|
# to Django (can't use the Apache config).
|
||||||
|
with open(BASE_DIR / 'secrets.json') as f:
|
||||||
|
secrets = json.load(f)
|
||||||
|
|
||||||
|
def get_secret(secrets, setting):
|
||||||
|
try:
|
||||||
|
return secrets[setting]
|
||||||
|
except KeyError:
|
||||||
|
raise ImproperlyConfigured(f'Missing secret \'{setting}\'')
|
||||||
|
|
||||||
|
SECRET_KEY = get_secret(secrets, 'SECRET_KEY')
|
||||||
|
|
||||||
|
SESSION_COOKIE_SECURE = True
|
|
@ -7,7 +7,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'conservancy.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'conservancy.settings.dev')
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
|
Loading…
Reference in a new issue