- name: Run unit tests (via tox)
run: tox
env:
- PW_TEST_DB_TYPE: "${{ matrix.db }}"
- PW_TEST_DB_USER: "patchwork"
- PW_TEST_DB_PASS: "patchwork"
- PW_TEST_DB_HOST: "127.0.0.1"
+ DATABASE_TYPE: "${{ matrix.db }}"
+ DATABASE_USER: "patchwork"
+ DATABASE_PASSWORD: "patchwork"
+ DATABASE_HOST: "127.0.0.1"
docs:
name: Build docs
runs-on: ubuntu-latest
environment:
- UID
- GID
- - PW_TEST_DB_HOST=db
- - PW_TEST_DB_PORT=5432
- - PW_TEST_DB_TYPE=postgres
- - PW_TEST_DB_USER=postgres
- - PW_TEST_DB_PASS=password
- - PGPASSWORD=password
+ - DATABASE_TYPE=postgres
+ - DATABASE_HOST=db
+ - DATABASE_PORT=5432
+ - DATABASE_NAME=patchwork
+ - DATABASE_USER=patchwork
+ - DATABASE_PASSWORD=password
volumes:
- ./tools/docker/db/data:/var/lib/mysql
environment:
- - MYSQL_ROOT_PASSWORD=password
+ - MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=patchwork
- MYSQL_PASSWORD=password
environment:
- UID
- GID
- - PW_TEST_DB_HOST=db
- - PW_TEST_DB_PORT=3306
+ # skip DATABASE_TYPE explicitly as mysql should be the default type.
+ - DATABASE_HOST=db
+ - DATABASE_PORT=3306
+ - DATABASE_USER=patchwork
+ - DATABASE_PASSWORD=password
+ - MYSQL_ROOT_PASSWORD=root
Username that the Patchwork web application will access the database with. We
will use ``www-data``, for reasons described later in this guide.
-``DATABASE_PASS=``
+``DATABASE_PASSWORD=``
Password that the Patchwork web application will access the database with. As
we're going to use *peer* authentication (more on this later), this will be
unset.
$ sudo -u www-data \
--preserve-env=DATABASE_NAME \
--preserve-env=DATABASE_USER \
- --preserve-env=DATABASE_PASS \
+ --preserve-env=DATABASE_PASSWORD \
--preserve-env=DATABASE_HOST \
--preserve-env=DATABASE_PORT \
--preserve-env=STATIC_ROOT \
The ``patchwork`` username and ``password`` password are the defaults
expected by the provided ``dev`` settings files. If using something
- different, export the ``PW_TEST_DB_USER`` and ``PW_TEST_DB_PASS`` variables
+ different, export the ``DATABASE_USER`` and ``DATABASE_PASSWORD`` variables
described in the :ref:`Environment Variables <dev-envvar>` section below.
Alternatively, you can create your own settings file with these variables
hardcoded and change the value of ``DJANGO_SETTINGS_MODULE`` as described
Environment Variables
---------------------
-The following environment variables are available to configure settings when
-using the provided ``dev`` settings file.
+The following environment variables are available to configure settings.
-``PW_TEST_DB_NAME=patchwork``
+``DATABASE_NAME=patchwork``
Name of the database
-``PW_TEST_DB_USER=patchwork``
+``DATABASE_USER=patchwork``
Username to access the database with
-``PW_TEST_DB_PASS=password``
+``DATABASE_PASSWORD=password``
Password to access the database with<
-``PW_TEST_DB_TYPE=mysql``
+``DATABASE_TYPE=mysql``
Type of database to use. Options: ``mysql``, ``postgres``
# env = DJANGO_SECRET_KEY=
# env = DATABASE_NAME=
# env = DATABASE_USER=
-# env = DATABASE_PASS=
+# env = DATABASE_PASSWORD=
# env = DATABASE_HOST=
# env = DATABASE_PORT=
# env = STATIC_ROOT=
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
- 'HOST': os.getenv('PW_TEST_DB_HOST', 'localhost'),
- 'PORT': os.getenv('PW_TEST_DB_PORT', ''),
- 'USER': os.getenv('PW_TEST_DB_USER', 'patchwork'),
- 'PASSWORD': os.getenv('PW_TEST_DB_PASS', 'password'),
- 'NAME': os.getenv('PW_TEST_DB_NAME', 'patchwork'),
+ 'HOST': os.getenv('DATABASE_HOST', 'localhost'),
+ 'PORT': os.getenv('DATABASE_PORT', ''),
+ 'USER': os.getenv('DATABASE_USER', 'patchwork'),
+ 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'),
+ 'NAME': os.getenv('DATABASE_NAME', 'patchwork'),
'TEST': {
'CHARSET': 'utf8',
},
},
}
-if os.getenv('PW_TEST_DB_TYPE', None) == 'postgres':
+if os.getenv('DATABASE_TYPE', None) == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
- DATABASES['default']['HOST'] = os.getenv('PW_TEST_DB_HOST', '')
-elif os.getenv('PW_TEST_DB_TYPE', None) == 'sqlite':
+ DATABASES['default']['HOST'] = os.getenv('DATABASE_HOST', '')
+elif os.getenv('DATABASE_TYPE', None) == 'sqlite':
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
DATABASES['default']['NAME'] = '/dev/shm/patchwork.test.db.sqlite3'
del DATABASES['default']['HOST']
--- /dev/null
+---
+upgrade:
+ - |
+ Database configuration variables ``PW_TEST_DB_*`` are renamed to their
+ corresponding ``DATABASE_*`` names to sync development & production
+ environments setup. Some mistaken references to ``DATABASE_PASS`` are
+ also replaced with ``DATABASE_PASSWORD`` to follow the convention.
#!/bin/bash
set -euo pipefail
-PW_TEST_DB_TYPE=${PW_TEST_DB_TYPE:-mysql}
+DATABASE_TYPE=${DATABASE_TYPE:-mysql}
# functions
test_db_connection() {
- if [ ${PW_TEST_DB_TYPE} = "postgres" ]; then
- echo ';' | psql -h $PW_TEST_DB_HOST -U postgres 2> /dev/null > /dev/null
+ if [ ${DATABASE_TYPE} = "postgres" ]; then
+ echo ';' | psql -h $DATABASE_HOST -U postgres 2> /dev/null > /dev/null
else
- mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null
+ mysqladmin -h $DATABASE_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null
fi
}
test_database() {
- if [ ${PW_TEST_DB_TYPE} = "postgres" ]; then
- echo ';' | psql -h $PW_TEST_DB_HOST -U postgres patchwork 2> /dev/null
+ if [ ${DATABASE_TYPE} = "postgres" ]; then
+ echo ';' | psql -h $DATABASE_HOST -U postgres patchwork 2> /dev/null
else
- echo ';' | mysql -h $PW_TEST_DB_HOST -u patchwork -ppassword patchwork 2> /dev/null
+ echo ';' | mysql -h $DATABASE_HOST -u patchwork -ppassword patchwork 2> /dev/null
fi
}
reset_data_mysql() {
- mysql -uroot -ppassword -h $PW_TEST_DB_HOST << EOF
+ mysql -uroot -ppassword -h $DATABASE_HOST << EOF
DROP DATABASE IF EXISTS patchwork;
CREATE DATABASE patchwork CHARACTER SET utf8;
GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY 'password';
}
reset_data_postgres() {
- psql -h $PW_TEST_DB_HOST -U postgres <<EOF
+ psql -h $DATABASE_HOST -U postgres <<EOF
DROP DATABASE IF EXISTS patchwork;
CREATE DATABASE patchwork WITH ENCODING = 'UTF8';
EOF
}
reset_data() {
- if [ x${PW_TEST_DB_TYPE} = x"postgres" ]; then
+ if [ x${DATABASE_TYPE} = x"postgres" ]; then
reset_data_postgres
else
reset_data_mysql
py{37,38,39}: PYTHONWARNINGS = once
passenv =
http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
- PW_TEST_DB_TYPE PW_TEST_DB_USER PW_TEST_DB_PASS PW_TEST_DB_HOST
- PW_TEST_DB_PORT PW_TEST_DB_NAME DJANGO_TEST_PROCESSES
+ DATABASE_TYPE DATABASE_USER DATABASE_PASSWORD DATABASE_HOST
+ DATABASE_PORT DATABASE_NAME DJANGO_TEST_PROCESSES
commands =
python {toxinidir}/manage.py test --noinput --parallel -- {posargs:patchwork}