Skip to content

Commit 44ca0e5

Browse files
authored
Merge pull request #151 from Xpirix/local_settings_override
Local settings override
2 parents c9fb2f0 + f922844 commit 44ca0e5

File tree

8 files changed

+67
-1
lines changed

8 files changed

+67
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ package-lock.json
122122
webpack-stats.json
123123
qgisfeedproject/static/bundles
124124
!qgisfeedproject/qgisfeedproject/settings_local.py.templ
125+
qgisfeedproject/qgisfeedproject/settings_local_override.py
125126

126127
# Sustaining members template
127128
qgisfeedproject/templates/layouts/sustaining_members.html
128129

129130
.vscode
130-
.vscode-extensions
131+
.vscode-extensions

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ TODO: Install all dependecies when running nix-shell.
7171
$ make dev-build
7272
```
7373

74+
#### Environment setup
7475
- Create `settings_local.py` int the `qgisfeedproject` directory, configure the media folder as in the example below:
7576

7677
```python
@@ -105,6 +106,21 @@ See https://docs.djangoproject.com/en/2.2/topics/email/#module-django.core.mail
105106
QGISFEED_MAX_RECORDS=40 # default value is 20
106107
```
107108
109+
**IMPORTANT NOTE**: For new Django variables, please use the `settings_local_override.py` as the `.env` file is not supported by the new production infrastructure.
110+
111+
#### Django Local Settings Override (`settings_local_override.py`)
112+
113+
- Create settings_local_override.py file
114+
```bash
115+
$ cp settings_local_override.py.templ settings_local_override.py
116+
```
117+
118+
- Edit settings_local_override.py file and set your environment variables
119+
120+
**IMPORTANT NOTE**: As we are migrating to a declarative based infrastructure, it is preferable to use the `settings_local_override.py` file for all new Django variables. This file is ignored when commiting so please make sure you define your new variables with an example value (**NOT THE REAL ONE FOR SECRETS AND PASSWORDS**) inside the `settings_local_override.py.templ` file.
121+
122+
#### Spin up the development environment
123+
108124
- Start the docker the container
109125
```bash
110126
$ make dev-start

docker-compose-production-ssl.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ services:
5757
QGISFEED_DOCKER_DBUSER: ${QGISFEED_DOCKER_DBUSER}
5858
QGISFEED_DOCKER_DBPASSWORD: ${QGISFEED_DOCKER_DBPASSWORD}
5959
QGIS_FEED_PROD_URL: ${QGIS_FEED_PROD_URL}
60+
DJANGO_LOCAL_SETTINGS: ${DJANGO_LOCAL_SETTINGS:-settings_local_override.py}
6061
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL:-automation}
6162
EMAIL_BACKEND: ${EMAIL_BACKEND}
6263
EMAIL_HOST: ${EMAIL_HOST}

docker-compose-production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ services:
5757
QGISFEED_DOCKER_DBUSER: ${QGISFEED_DOCKER_DBUSER}
5858
QGISFEED_DOCKER_DBPASSWORD: ${QGISFEED_DOCKER_DBPASSWORD}
5959
QGIS_FEED_PROD_URL: ${QGIS_FEED_PROD_URL}
60+
DJANGO_LOCAL_SETTINGS: ${DJANGO_LOCAL_SETTINGS:-settings_local_override.py}
6061
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL:-automation}
6162
EMAIL_BACKEND: ${EMAIL_BACKEND}
6263
EMAIL_HOST: ${EMAIL_HOST}

docker-compose.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
QGISFEED_DOCKER_DBUSER: ${QGISFEED_DOCKER_DBUSER}
2727
QGISFEED_DOCKER_DBPASSWORD: ${QGISFEED_DOCKER_DBPASSWORD}
2828
QGIS_FEED_PROD_URL: ${QGIS_FEED_PROD_URL}
29+
DJANGO_LOCAL_SETTINGS: ${DJANGO_LOCAL_SETTINGS:-settings_local_override.py}
2930
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL:-automation}
3031
EMAIL_BACKEND: ${EMAIL_BACKEND}
3132
EMAIL_HOST: ${EMAIL_HOST}

env.template

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ QGISFEED_DOCKER_DBUSER=docker
2222
# Database password
2323
QGISFEED_DOCKER_DBPASSWORD=docker
2424

25+
# (Optional) Full path of the Django local settings override.
26+
# Any values defined in this file will override values
27+
# from the existing settings. New variables can also be
28+
# defined. We can't use settings_local.py because it will be
29+
# automaticaly replaced by settings_docker_production.py in
30+
# Production.
31+
# This variable is mainly usefull for the new infrastructure
32+
DJANGO_LOCAL_SETTINGS='/path/to/settings_local_override.py'
33+
2534
# Email variables
2635
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
2736
EMAIL_HOST='smtp.resend.com'

qgisfeedproject/qgisfeedproject/settings.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,31 @@
221221
# Telegram
222222
TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN", "")
223223
TELEGRAM_CHAT_ID = os.environ.get("TELEGRAM_CHAT_ID", "")
224+
225+
# Local settings overrides
226+
# Must be the last!
227+
DJANGO_LOCAL_SETTINGS = os.environ.get(
228+
"DJANGO_LOCAL_SETTINGS", "settings_local_override.py"
229+
)
230+
231+
try:
232+
from pathlib import Path
233+
234+
local_settings_path = Path(__file__).parent / DJANGO_LOCAL_SETTINGS
235+
if local_settings_path.exists():
236+
import importlib.util
237+
238+
spec = importlib.util.spec_from_file_location(
239+
"settings_local_override", local_settings_path
240+
)
241+
settings_local_override = importlib.util.module_from_spec(spec)
242+
spec.loader.exec_module(settings_local_override)
243+
for setting in dir(settings_local_override):
244+
if setting.isupper():
245+
globals()[setting] = getattr(settings_local_override, setting)
246+
else:
247+
raise ImportError(
248+
f"Local settings file {DJANGO_LOCAL_SETTINGS} does not exist."
249+
)
250+
except ImportError:
251+
pass
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Host for sending e-mail.
2+
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
3+
EMAIL_HOST = 'smtp.resend.com'
4+
EMAIL_PORT = 587
5+
EMAIL_USE_TLS = True
6+
EMAIL_HOST_USER = "resend"
7+
EMAIL_HOST_PASSWORD = ""
8+
EMAIL_SUBJECT_PREFIX = '[QGIS Feed] '
9+
DEFAULT_FROM_EMAIL = 'no-reply-feed@qgis.org'

0 commit comments

Comments
 (0)