Skip to content

Commit 196d5f3

Browse files
committed
container: use DJANGO_SETTINGS_MODULE=ynr.settings
This reverts all changes to ynr.settings.testing, and defaults the containerised YNR app to use the base ynr.settings module throughout the build process and the compose invocation. The pytest wrapper script is allowed to use pytest's default settings already configured via pyproject.toml. This change is generally implemented by removing the explicit use of ynr.settings.testing across various scenarios, and opting in to manage.py's default of ynr.settings (which inherits ynr.settings.base). Also: small tweaks to docs. Signed-off-by: Jonathan Matthews <github@hello.jonathanmatthews.com>
1 parent 79dfd40 commit 196d5f3

File tree

10 files changed

+31
-19
lines changed

10 files changed

+31
-19
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,11 @@ jobs:
177177
net="$(docker network inspect $(docker network ls -q -f "label=task-network") --format '{{.Name}}')"
178178
docker run -it --rm \
179179
--net="$net" \
180-
-e RUN_ENV=test \
181180
-e PGHOST=dbpsql \
182181
-e CIRCLECI=true \
183182
\
184183
ynr:test \
185-
pytest --ds=ynr.settings.testing -x
184+
pytest -x
186185
187186
workflows:
188187
test_build_deploy:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ynr/assets/*
2020
.pytest_cache
2121
*.css.map
2222
test-results
23-
env/
23+
/env/*.env
2424
node_modules/
2525
.vscode/
2626
/test-env

container/build/Containerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ WORKDIR $APP_CODE
8888
# Invoke a lightweight, post-build test that proves the container reaches a
8989
# baseline level of correctness, whilst also generating .pyc files for faster
9090
# app startup.
91-
RUN python manage.py check --settings=ynr.settings.testing
91+
RUN DJANGO_SECRET_KEY=insecure python manage.py check
9292

9393
###########
9494
## Assets #
9595
###########
9696
RUN date \
9797
&& npm run build \
98-
&& python manage.py collectstatic --no-input --settings=ynr.settings.testing \
98+
&& DJANGO_SECRET_KEY=insecure python manage.py collectstatic --no-input \
9999
&& date
100100

101101
###########################################################################

docs/DEVELOPMENT.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ Run a Django management command:
119119
`podman compose up -d`
120120
1. Use the `container.manage-py.bash` script to invoke the command:
121121
```
122-
./scripts/container.manage-py.bash command-to-invoke --command-args command params
122+
# ./scripts/container.manage-py.bash command-to-invoke --command-args command params
123+
# e.g.
124+
./scripts/container.manage-py.bash check
123125
```
124126
1. Stop the compose stack:
125127
`podman compose down`
@@ -190,8 +192,6 @@ GitHub-rendered view so that command strings don't line-wrap. -->
190192

191193
These executable scripts are available from the [`scripts`](../scripts) directory.
192194

193-
<!-- The &nbsp; HTML entities force the Script column to be wide enough in the
194-
GitHub-rendered view so that command strings don't line-wrap. -->
195195
| Script | Purpose | Parameters
196196
| :--- | :--- | :---
197197
| `container.image.build.bash` | Builds the YNR container image | $1 -- The named stage from [`container/build/Containerfile`](../container/build/Containerfile) to build and tag (*required*)<br>$2, $3, ... -- Any parameters to pass to the underlying builder process (*optional*)

docs/INSTALL.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ and to get closer to the intended future state of the application's
3838
`podman compose build`
3939
1. Pull any 3rd-party container images used by the compose stack:
4040
`podman compose pull`
41-
1. Set up your local/development envvars as needed, by placing keys and values
42-
`env/frontend.env`, like this:
41+
1. Set up your development envvars as needed, by placing keys and values in
42+
`env/frontend.env`, using `env/frontend.env.example` as a template.
43+
In general, the only envar you should need is this:
4344
```
44-
DJANGO_SETTINGS_MODULE=ynr.settings.testing
45+
DJANGO_SETTINGS_MODULE=ynr.settings
4546
```
47+
1. Copy `ynr/settings/local.py.container.example` to `ynr/settings/local.py`.
48+
If you already have a `ynr/settings/local.py` file, incorporate the example
49+
file's settings. **If you don't use most of the example file's settings, you
50+
*will* experience problems interacting with the app, later**.
4651
1. Test that the compose stack can be stood up:
4752
```bash
4853
podman compose up -d # NB Space between "podman" and "compose"!

env/.gitkeep

Whitespace-only changes.

env/frontend.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DJANGO_SETTINGS_MODULE=ynr.settings

scripts/container.pytest.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# container.test.bash invokes a `pytest` command in a "frontend" container.
4+
# container.pytest.bash invokes a `pytest` command in a "frontend" container.
55
# The container and a database server must be running before running this
66
# script (see README.md).
77
#
88
# Usage:
9-
# scripts/container.test.bash # run all tests; continue after failures
10-
# scripts/container.test.bash -x # stop after first failure
9+
# scripts/container.pytest.bash # run all tests; continue after failures
10+
# scripts/container.pytest.bash -x # stop after first failure
1111

1212
# The command being invoked does not need to be quoted, unless it contains
1313
# shell meta-characters or similar. Multiple words are fine, without quotes.

ynr/settings/local.py.container.example

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
DEBUG = True
33

44
# These Postgres settings should match docker-compose.yml.
5-
DATABASES["default"]["NAME"] = "ynr" # noqa
6-
DATABASES["default"]["USER"] = "ynr" # noqa
5+
# Credentials are not required.
6+
DATABASES = {"default": {
7+
"ENGINE": "django.db.backends.postgresql",
8+
"HOST": "dbpsql", "NAME": 'ynr', "USER": "ynr",
9+
}}
10+
11+
# The containerised setup does not include the same memcache service that
12+
# production currently uses for its cache, so we explicitly set up a dummy
13+
# cache when running locally.
14+
CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
715

816
# This short, known value is insecure.
9-
SECRET_KEY = "development"
17+
SECRET_KEY = "insecure"
1018

1119
# Certain errors are very noisy (obscuring the real problem) if this list is
1220
# empty.

ynr/settings/testing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def __contains__(self, item):
1717
def __getitem__(self, item):
1818
return None
1919

20-
ADMINS = [("dummy", "dummy@dummy.example")]
2120

2221
MIGRATION_MODULES = DisableMigrations()
2322

@@ -30,7 +29,7 @@ def __getitem__(self, item):
3029
RUNNING_TESTS = True
3130

3231
SECRET_KEY = "just here for testing"
33-
ALLOWED_HOSTS = ["candidates.democracyclub.org.uk","*"]
32+
ALLOWED_HOSTS = ["candidates.democracyclub.org.uk"]
3433

3534
SHOW_SOPN_TRACKER = False
3635
SHOW_RESULTS_PROGRESS = False

0 commit comments

Comments
 (0)