File tree Expand file tree Collapse file tree
compose/production/django Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828 "features" : {
2929 "ghcr.io/devcontainers/features/docker-outside-of-docker:1" : {}
3030 },
31- "remoteEnv" : {
32- "DATABASE_URL" : " postgres://${containerEnv:POSTGRES_USER}:${containerEnv:POSTGRES_PASSWORD}@${containerEnv:POSTGRES_HOST}:${containerEnv:POSTGRES_PORT}/${containerEnv:POSTGRES_DB}"
33- },
3431 // Set *default* container specific settings.json values on container create.
3532 "customizations" : {
3633 "vscode" : {
Original file line number Diff line number Diff line change @@ -156,7 +156,8 @@ Running Tests Locally
156156The easiest way to run tests is by running ``just test ``. This will run the tests from
157157the ``django `` Docker service so they have access to Postgres. To run the tests in the
158158local environment, for example using the VSCode test runner, you must have PostgreSQL _
159- installed on your computer. Django should automatically create a test database for you
160- when you run the tests.
159+ installed on your computer, and you must set the environment variable
160+ ``DATABASE_URL=postgres:///democrasite ``. Django should automatically create a test
161+ database for you when you run the tests.
161162
162163.. _PostgreSQL : https://www.postgresql.org/download/
Original file line number Diff line number Diff line change @@ -88,9 +88,7 @@ RUN chown -R django:django ${APP_HOME}
8888
8989USER django
9090
91- RUN DATABASE_URL="" \
92- REDIS_URL="" \
93- DJANGO_SETTINGS_MODULE="config.settings.test" \
91+ RUN DJANGO_SETTINGS_MODULE="config.settings.test" \
9492 python manage.py compilemessages
9593
9694ENTRYPOINT ["/entrypoint" ]
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ if [ -z "${POSTGRES_USER}" ]; then
1010 base_postgres_image_default_user=' postgres'
1111 export POSTGRES_USER=" ${base_postgres_image_default_user} "
1212fi
13- export DATABASE_URL=" postgres://${POSTGRES_USER} :${POSTGRES_PASSWORD} @${POSTGRES_HOST} :${POSTGRES_PORT} /${POSTGRES_DB} "
1413
1514python << END
1615import sys
Original file line number Diff line number Diff line change 3737# DATABASES
3838# ------------------------------------------------------------------------------
3939# https://docs.djangoproject.com/en/dev/ref/settings/#databases
40- DATABASES = {"default" : env .db ("DATABASE_URL" , default = "postgres:///democrasite" )}
40+ if db_url := env .db ("DATABASE_URL" , default = None ):
41+ DATABASES = {"default" : db_url }
42+ else :
43+ DATABASES = {
44+ "default" : {
45+ "ENGINE" : "django.db.backends.postgresql" ,
46+ "NAME" : env .str ("POSTGRES_DB" ),
47+ "USER" : env .str ("POSTGRES_USER" ),
48+ "PASSWORD" : env .str ("POSTGRES_PASSWORD" ),
49+ "HOST" : env .str ("POSTGRES_HOST" , default = "postgres" ),
50+ "PORT" : env .str ("POSTGRES_PORT" , default = "5432" ),
51+ },
52+ }
4153DATABASES ["default" ]["ATOMIC_REQUESTS" ] = True
4254# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
4355DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
You can’t perform that action at this time.
0 commit comments