Merge pull request #563 from foarsitter/docker_postgresql

Postgresql docker container for local development
This commit is contained in:
Jelmer 2024-03-25 19:06:28 +01:00 committed by GitHub
commit 8bef73cd99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 16 deletions

View file

@ -3,6 +3,9 @@ name: Test
on: [push, pull_request]
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
FORCE_COLOR: 1
jobs:
@ -16,11 +19,11 @@ jobs:
services:
postgres:
image: postgres:12
image: postgres:13-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
ports:
- 5432:5432
options: >-
@ -60,11 +63,9 @@ jobs:
run: |
tox -v -- --cov --cov-append --cov-report term-missing --cov-report xml
env:
DB_NAME: postgres
DB_USER: postgres
DB_PASSWORD: postgres
DB_HOST: localhost
DB_PORT: 5432
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
- name: Upload coverage
uses: codecov/codecov-action@v3

View file

@ -74,6 +74,18 @@ To run tox and generate a coverage report (in ``htmlcov`` directory)::
make test
A database is required to run the tests. For convince there is a ``docker-compose.yml`` file for spinning up a
database container. To start the database container run:
docker-compose up -d
Another way to run the tests with a sqlite database is to export the `SQLITE` variable::
export SQLITE=1
make test
# or
SQLITE=1 python setup.py test
**Please note**: Before a pull request can be merged, all tests must pass and
code/branch coverage in tests must be 100%.

9
docker-compose.yml Normal file
View file

@ -0,0 +1,9 @@
services:
postgres:
image: postgres:13-alpine
environment:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: modelutils
POSTGRES_USER: postgres
ports:
- 5432:5432

View file

@ -15,14 +15,13 @@ else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DB_NAME", "modelutils"),
"USER": os.environ.get("DB_USER", 'postgres'),
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
"HOST": os.environ.get("DB_HOST", "localhost"),
"PORT": os.environ.get("DB_PORT", 5432)
"NAME": os.environ.get("POSTGRES_DB", "modelutils"),
"USER": os.environ.get("POSTGRES_USER", 'postgres'),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", ""),
"HOST": os.environ.get("POSTGRES_HOST", "localhost"),
"PORT": os.environ.get("POSTGRES_PORT", 5432)
},
}
SECRET_KEY = 'dummy'
CACHES = {

View file

@ -36,7 +36,7 @@ passenv =
CI
FORCE_COLOR
GITHUB_*
DB_*
POSTGRES_*
usedevelop = True
commands =
python -m pytest {posargs}