diff --git a/README.rst b/README.rst index 7e579fc64..64a166467 100644 --- a/README.rst +++ b/README.rst @@ -372,17 +372,47 @@ Running Locally with Docker docker compose build -2. Spin up the containers:: +2. Create the file ``data/conf/secrets.json`` with the required configuration:: + + { + "secret_key": "insecure-local-key", + "db_user": "djangoproject", + "db_host": "db", + "db_password": "secret", + "trac_db_user": "code.djangoproject", + "trac_db_host": "tracdb", + "trac_db_password": "secret", + "allowed_hosts": [".localhost", "127.0.0.1", "www.127.0.0.1"], + "internal_ips": ["127.0.0.1"] + } + +3. Spin up the containers:: docker compose up -3. View the site at http://localhost:8000/ +4. View the site at http://localhost:8000/ -4. Run the tests:: +5. Run the tests:: docker compose exec web tox docker compose exec web python -m manage test +``secrets.json`` file +--------------------- + +The secrets file may contain the following fields: + +* ``secret_key``: Django's ``SECRET_KEY`` setting. +* ``db_user``: must match the value of ``POSTGRES_USER`` for the ``db`` service. +* ``db_host``: must match the name of the ``db`` service. +* ``db_password``: must match the value of ``POSTGRES_PASSWORD`` for the ``db`` service. +* ``trac_db_user``: must match the value of ``POSTGRES_USER`` for the ``tracdb`` service. +* ``trac_db_host``: must match the name of the ``tracdb`` service. +* ``trac_db_password``: must match the value of ``POSTGRES_PASSWORD`` for the ``tracdb`` service. +* ``allowed_hosts``: an array that will be appended to Django's ``ALLOWED_HOSTS`` setting. +* ``internal_ips``: an array of IPs assigned to the ``INTERNAL_IPS`` Django Debug Toolbar setting. Defaults to ``["127.0.0.1"]``. +* ``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``. + Pre-commit checks ----------------- diff --git a/djangoproject/settings/docker.py b/djangoproject/settings/docker.py index d97f054e7..dc9035fa2 100644 --- a/djangoproject/settings/docker.py +++ b/djangoproject/settings/docker.py @@ -1,76 +1,8 @@ -from .common import * # noqa - -DATABASES = { - "default": { - "ENGINE": os.environ.get("SQL_ENGINE"), - "NAME": os.environ.get("SQL_DATABASE"), - "USER": os.environ.get("SQL_USER"), - "PASSWORD": os.environ.get("SQL_PASSWORD"), - "HOST": os.environ.get("SQL_HOST"), - "PORT": os.environ.get("SQL_PORT"), - } -} - -SECRET_KEY = os.environ.get("SECRET_KEY") - -SILENCED_SYSTEM_CHECKS = SILENCED_SYSTEM_CHECKS + [ - "django_recaptcha.recaptcha_test_key_error" # Default test keys for development. -] - -ALLOWED_HOSTS = [".localhost", "127.0.0.1", "www.127.0.0.1"] - -LOCALE_MIDDLEWARE_EXCLUDED_HOSTS = ["docs.djangoproject.localhost"] - -DEBUG = True -THUMBNAIL_DEBUG = DEBUG - -CACHES = { - "default": { - "BACKEND": "django.core.cache.backends.locmem.LocMemCache", - "LOCATION": "trololololol", - }, - "docs-pages": { - "BACKEND": "django.core.cache.backends.locmem.LocMemCache", - "LOCATION": "docs-pages", - }, -} - -CSRF_COOKIE_SECURE = False - -EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" - -MEDIA_ROOT = str(DATA_DIR.joinpath("media_root")) - -SESSION_COOKIE_SECURE = False - -STATIC_ROOT = str(DATA_DIR.joinpath("static_root")) - -# Docs settings -DOCS_BUILD_ROOT = DATA_DIR.joinpath("djangodocs") +from .dev import * # noqa # django-hosts settings +if parent_host := SECRETS.get("parent_host"): + PARENT_HOST = parent_host -PARENT_HOST = "localhost:8000" - -# django-push settings - -PUSH_SSL_CALLBACK = False - -# Enable optional components - -if DEBUG: - try: - import debug_toolbar # NOQA - except ImportError: - pass - else: - INSTALLED_APPS.append("debug_toolbar") - INTERNAL_IPS = ["127.0.0.1"] - MIDDLEWARE.insert( - MIDDLEWARE.index("django.middleware.common.CommonMiddleware") + 1, - "debug_toolbar.middleware.DebugToolbarMiddleware", - ) - MIDDLEWARE.insert( - MIDDLEWARE.index("debug_toolbar.middleware.DebugToolbarMiddleware") + 1, - "djangoproject.middleware.CORSMiddleware", - ) +# debug-toolbar settings +INTERNAL_IPS = SECRETS.get("internal_ips", ["127.0.0.1"]) diff --git a/docker-compose.yml b/docker-compose.yml index 0730523cb..51dac2a35 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,9 +24,18 @@ services: - SQL_PORT=5432 depends_on: - db + - tracdb db: image: postgres:14-alpine environment: - POSTGRES_USER=djangoproject - POSTGRES_PASSWORD=secret - POSTGRES_DB=djangoproject + tracdb: + image: postgres:14-alpine + environment: + - POSTGRES_USER=code.djangoproject + - POSTGRES_PASSWORD=secret + - POSTGRES_DB=code.djangoproject + volumes: + - ./tracdb/trac.sql:/docker-entrypoint-initdb.d/trac.sql diff --git a/tox.ini b/tox.ini index d8f31f0b9..03b498806 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ python = [testenv] allowlist_externals = make -passenv = DJANGO_SETTINGS_MODULE +passenv = DJANGO_SETTINGS_MODULE, DJANGOPROJECT_DATA_DIR deps = tests: -r{toxinidir}/requirements/tests.txt flake8: flake8