Skip to content

Commit 65b2438

Browse files
committed
Fixed #1817 -- Added tracdb container
Added 'tracdb' container to compose file. Simplified docker settings to remove duplication. Added support for 'secrets.json' in the docker dev stage. Added the 'DJANGOPROJECT_DATA_DIR' env var to tox.
1 parent d689893 commit 65b2438

File tree

4 files changed

+48
-77
lines changed

4 files changed

+48
-77
lines changed

README.rst

+33-3
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,47 @@ Running Locally with Docker
372372

373373
docker compose build
374374

375-
2. Spin up the containers::
375+
2. Create the file ``data/conf/secrets.json`` with the required configuration::
376+
377+
{
378+
"secret_key": "insecure-local-key",
379+
"db_user": "djangoproject",
380+
"db_host": "db",
381+
"db_password": "secret",
382+
"trac_db_user": "code.djangoproject",
383+
"trac_db_host": "tracdb",
384+
"trac_db_password": "secret",
385+
"allowed_hosts": [".localhost", "127.0.0.1", "www.127.0.0.1"],
386+
"internal_ips": ["127.0.0.1"]
387+
}
388+
389+
3. Spin up the containers::
376390

377391
docker compose up
378392

379-
3. View the site at http://localhost:8000/
393+
4. View the site at http://localhost:8000/
380394

381-
4. Run the tests::
395+
5. Run the tests::
382396

383397
docker compose exec web tox
384398
docker compose exec web python -m manage test
385399

400+
``secrets.json`` file
401+
---------------------
402+
403+
The secrets file may contain the following fields:
404+
405+
* ``secret_key``: Django's ``SECRET_KEY`` setting.
406+
* ``db_user``: must match the value of ``POSTGRES_USER`` for the ``db`` service.
407+
* ``db_host``: must match the name of the ``db`` service.
408+
* ``db_password``: must match the value of ``POSTGRES_PASSWORD`` for the ``db`` service.
409+
* ``trac_db_user``: must match the value of ``POSTGRES_USER`` for the ``tracdb`` service.
410+
* ``trac_db_host``: must match the name of the ``tracdb`` service.
411+
* ``trac_db_password``: must match the value of ``POSTGRES_PASSWORD`` for the ``tracdb`` service.
412+
* ``allowed_hosts``: an array that will be appended to Django's ``ALLOWED_HOSTS`` setting.
413+
* ``internal_ips``: an array of IPs assigned to the ``INTERNAL_IPS`` Django Debug Toolbar setting. Defaults to ``["127.0.0.1"]``.
414+
* ``parent_host``: the django-hosts ``PARENT_HOST`` setting. Useful if you run docker on a machine other than ``localhost``, but setting it breaks some tests. Defaults to ``djangoproject.localhost:8000``.
415+
386416
Pre-commit checks
387417
-----------------
388418

djangoproject/settings/docker.py

+5-73
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,8 @@
1-
from .common import * # noqa
2-
3-
DATABASES = {
4-
"default": {
5-
"ENGINE": os.environ.get("SQL_ENGINE"),
6-
"NAME": os.environ.get("SQL_DATABASE"),
7-
"USER": os.environ.get("SQL_USER"),
8-
"PASSWORD": os.environ.get("SQL_PASSWORD"),
9-
"HOST": os.environ.get("SQL_HOST"),
10-
"PORT": os.environ.get("SQL_PORT"),
11-
}
12-
}
13-
14-
SECRET_KEY = os.environ.get("SECRET_KEY")
15-
16-
SILENCED_SYSTEM_CHECKS = SILENCED_SYSTEM_CHECKS + [
17-
"django_recaptcha.recaptcha_test_key_error" # Default test keys for development.
18-
]
19-
20-
ALLOWED_HOSTS = [".localhost", "127.0.0.1", "www.127.0.0.1"]
21-
22-
LOCALE_MIDDLEWARE_EXCLUDED_HOSTS = ["docs.djangoproject.localhost"]
23-
24-
DEBUG = True
25-
THUMBNAIL_DEBUG = DEBUG
26-
27-
CACHES = {
28-
"default": {
29-
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
30-
"LOCATION": "trololololol",
31-
},
32-
"docs-pages": {
33-
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
34-
"LOCATION": "docs-pages",
35-
},
36-
}
37-
38-
CSRF_COOKIE_SECURE = False
39-
40-
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
41-
42-
MEDIA_ROOT = str(DATA_DIR.joinpath("media_root"))
43-
44-
SESSION_COOKIE_SECURE = False
45-
46-
STATIC_ROOT = str(DATA_DIR.joinpath("static_root"))
47-
48-
# Docs settings
49-
DOCS_BUILD_ROOT = DATA_DIR.joinpath("djangodocs")
1+
from .dev import * # noqa
502

513
# django-hosts settings
4+
if parent_host := SECRETS.get("parent_host"):
5+
PARENT_HOST = parent_host
526

53-
PARENT_HOST = "localhost:8000"
54-
55-
# django-push settings
56-
57-
PUSH_SSL_CALLBACK = False
58-
59-
# Enable optional components
60-
61-
if DEBUG:
62-
try:
63-
import debug_toolbar # NOQA
64-
except ImportError:
65-
pass
66-
else:
67-
INSTALLED_APPS.append("debug_toolbar")
68-
INTERNAL_IPS = ["127.0.0.1"]
69-
MIDDLEWARE.insert(
70-
MIDDLEWARE.index("django.middleware.common.CommonMiddleware") + 1,
71-
"debug_toolbar.middleware.DebugToolbarMiddleware",
72-
)
73-
MIDDLEWARE.insert(
74-
MIDDLEWARE.index("debug_toolbar.middleware.DebugToolbarMiddleware") + 1,
75-
"djangoproject.middleware.CORSMiddleware",
76-
)
7+
# debug-toolbar settings
8+
INTERNAL_IPS = SECRETS.get("internal_ips", ["127.0.0.1"])

docker-compose.yml

+9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ services:
2424
- SQL_PORT=5432
2525
depends_on:
2626
- db
27+
- tracdb
2728
db:
2829
image: postgres:14-alpine
2930
environment:
3031
- POSTGRES_USER=djangoproject
3132
- POSTGRES_PASSWORD=secret
3233
- POSTGRES_DB=djangoproject
34+
tracdb:
35+
image: postgres:14-alpine
36+
environment:
37+
- POSTGRES_USER=code.djangoproject
38+
- POSTGRES_PASSWORD=secret
39+
- POSTGRES_DB=code.djangoproject
40+
volumes:
41+
- ./tracdb/trac.sql:/docker-entrypoint-initdb.d/trac.sql

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ python =
88

99
[testenv]
1010
allowlist_externals = make
11-
passenv = DJANGO_SETTINGS_MODULE
11+
passenv = DJANGO_SETTINGS_MODULE, DJANGOPROJECT_DATA_DIR
1212
deps =
1313
tests: -r{toxinidir}/requirements/tests.txt
1414
flake8: flake8

0 commit comments

Comments
 (0)