mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-12 17:12:25 +03:00
Merge 958c39011e
into 285e86bf71
This commit is contained in:
commit
4e1602c2a5
|
@ -54,7 +54,9 @@ First things first.
|
||||||
|
|
||||||
#. Set the environment variables for your database(s): ::
|
#. Set the environment variables for your database(s): ::
|
||||||
|
|
||||||
$ export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/<DB name given to createdb>
|
$ export POSTGRES_USER=postgres
|
||||||
|
$ export POSTGRES_PASSWORD=
|
||||||
|
$ export POSTGRES_DB=<DB name given to createdb>
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ steps:
|
||||||
pull: if-not-exists
|
pull: if-not-exists
|
||||||
{%- if cookiecutter.use_docker == 'y' %}
|
{%- if cookiecutter.use_docker == 'y' %}
|
||||||
image: docker:25.0
|
image: docker:25.0
|
||||||
environment:
|
|
||||||
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
|
|
||||||
commands:
|
commands:
|
||||||
- docker-compose -f docker-compose.local.yml build
|
- docker-compose -f docker-compose.local.yml build
|
||||||
- docker-compose -f docker-compose.docs.yml build
|
- docker-compose -f docker-compose.docs.yml build
|
||||||
|
|
|
@ -59,8 +59,11 @@ jobs:
|
||||||
{%- if cookiecutter.use_celery == 'y' %}
|
{%- if cookiecutter.use_celery == 'y' %}
|
||||||
REDIS_URL: 'redis://localhost:6379/0'
|
REDIS_URL: 'redis://localhost:6379/0'
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
# postgres://user:password@host:port/database
|
POSTGRES_USER: 'postgres'
|
||||||
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/postgres'
|
POSTGRES_PASSWORD: 'postgres'
|
||||||
|
POSTGRES_DB: 'postgres'
|
||||||
|
POSTGRES_HOST: 'postgres'
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -5,6 +5,7 @@ stages:
|
||||||
variables:
|
variables:
|
||||||
POSTGRES_USER: '{{ cookiecutter.project_slug }}'
|
POSTGRES_USER: '{{ cookiecutter.project_slug }}'
|
||||||
POSTGRES_PASSWORD: ''
|
POSTGRES_PASSWORD: ''
|
||||||
|
POSTGRES_HOST: postgres
|
||||||
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
|
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
|
||||||
POSTGRES_HOST_AUTH_METHOD: trust
|
POSTGRES_HOST_AUTH_METHOD: trust
|
||||||
{%- if cookiecutter.use_celery == 'y' %}
|
{%- if cookiecutter.use_celery == 'y' %}
|
||||||
|
@ -42,8 +43,6 @@ pytest:
|
||||||
image: python:3.12
|
image: python:3.12
|
||||||
services:
|
services:
|
||||||
- postgres:{{ cookiecutter.postgresql_version }}
|
- postgres:{{ cookiecutter.postgresql_version }}
|
||||||
variables:
|
|
||||||
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
|
|
||||||
before_script:
|
before_script:
|
||||||
- pip install -r requirements/local.txt
|
- pip install -r requirements/local.txt
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -124,8 +124,7 @@ RUN chown -R django:django ${APP_HOME}
|
||||||
|
|
||||||
USER django
|
USER django
|
||||||
|
|
||||||
RUN DATABASE_URL="" \
|
RUN DJANGO_SETTINGS_MODULE="config.settings.test" \
|
||||||
DJANGO_SETTINGS_MODULE="config.settings.test" \
|
|
||||||
python manage.py compilemessages
|
python manage.py compilemessages
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint"]
|
ENTRYPOINT ["/entrypoint"]
|
||||||
|
|
|
@ -8,7 +8,6 @@ if [ -z "${POSTGRES_USER}" ]; then
|
||||||
base_postgres_image_default_user='postgres'
|
base_postgres_image_default_user='postgres'
|
||||||
export POSTGRES_USER="${base_postgres_image_default_user}"
|
export POSTGRES_USER="${base_postgres_image_default_user}"
|
||||||
fi
|
fi
|
||||||
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
|
|
||||||
|
|
||||||
wait-for-it "${POSTGRES_HOST}:${POSTGRES_PORT}" -t 30
|
wait-for-it "${POSTGRES_HOST}:${POSTGRES_PORT}" -t 30
|
||||||
|
|
||||||
|
|
|
@ -48,16 +48,21 @@ LOCALE_PATHS = [str(BASE_DIR / "locale")]
|
||||||
# DATABASES
|
# DATABASES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||||
{% if cookiecutter.use_docker == "y" -%}
|
|
||||||
DATABASES = {"default": env.db("DATABASE_URL")}
|
if db_url := env.db("DATABASE_URL", default=None):
|
||||||
{%- else %}
|
DATABASES = {"default": db_url}
|
||||||
DATABASES = {
|
else:
|
||||||
"default": env.db(
|
DATABASES = {
|
||||||
"DATABASE_URL",
|
"default": {
|
||||||
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
),
|
"NAME": env.str("POSTGRES_DB"),
|
||||||
}
|
"USER": env.str("POSTGRES_USER"),
|
||||||
{%- endif %}
|
"PASSWORD": env.str("POSTGRES_PASSWORD"),
|
||||||
|
"HOST": env.str("POSTGRES_HOST", default="{% if cookiecutter.windows == 'y' and cookiecutter.use_docker == 'n' %}localhost{%else%}postgres{% endif %}"),
|
||||||
|
"PORT": env.str("POSTGRES_PORT", default="5432"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
DATABASES["default"]["ATOMIC_REQUESTS"] = True
|
DATABASES["default"]["ATOMIC_REQUESTS"] = True
|
||||||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user