Skip to content

Commit 8bef73c

Browse files
authored
Merge pull request jazzband#563 from foarsitter/docker_postgresql
Postgresql docker container for local development
2 parents 87a9466 + caac9a4 commit 8bef73c

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Test
33
on: [push, pull_request]
44

55
env:
6+
POSTGRES_USER: postgres
7+
POSTGRES_PASSWORD: postgres
8+
POSTGRES_DB: postgres
69
FORCE_COLOR: 1
710

811
jobs:
@@ -16,11 +19,11 @@ jobs:
1619

1720
services:
1821
postgres:
19-
image: postgres:12
22+
image: postgres:13-alpine
2023
env:
21-
POSTGRES_USER: postgres
22-
POSTGRES_PASSWORD: postgres
23-
POSTGRES_DB: postgres
24+
POSTGRES_USER: ${{ env.POSTGRES_USER }}
25+
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
26+
POSTGRES_DB: ${{ env.POSTGRES_DB }}
2427
ports:
2528
- 5432:5432
2629
options: >-
@@ -60,11 +63,9 @@ jobs:
6063
run: |
6164
tox -v -- --cov --cov-append --cov-report term-missing --cov-report xml
6265
env:
63-
DB_NAME: postgres
64-
DB_USER: postgres
65-
DB_PASSWORD: postgres
66-
DB_HOST: localhost
67-
DB_PORT: 5432
66+
POSTGRES_DB: ${{ env.POSTGRES_DB }}
67+
POSTGRES_USER: ${{ env.POSTGRES_USER }}
68+
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
6869

6970
- name: Upload coverage
7071
uses: codecov/codecov-action@v3

CONTRIBUTING.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ To run tox and generate a coverage report (in ``htmlcov`` directory)::
7474

7575
make test
7676

77+
A database is required to run the tests. For convince there is a ``docker-compose.yml`` file for spinning up a
78+
database container. To start the database container run:
79+
80+
docker-compose up -d
81+
82+
Another way to run the tests with a sqlite database is to export the `SQLITE` variable::
83+
84+
export SQLITE=1
85+
make test
86+
# or
87+
SQLITE=1 python setup.py test
88+
7789
**Please note**: Before a pull request can be merged, all tests must pass and
7890
code/branch coverage in tests must be 100%.
7991

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
postgres:
3+
image: postgres:13-alpine
4+
environment:
5+
POSTGRES_HOST_AUTH_METHOD: trust
6+
POSTGRES_DB: modelutils
7+
POSTGRES_USER: postgres
8+
ports:
9+
- 5432:5432

tests/settings.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
DATABASES = {
1616
"default": {
1717
"ENGINE": "django.db.backends.postgresql",
18-
"NAME": os.environ.get("DB_NAME", "modelutils"),
19-
"USER": os.environ.get("DB_USER", 'postgres'),
20-
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
21-
"HOST": os.environ.get("DB_HOST", "localhost"),
22-
"PORT": os.environ.get("DB_PORT", 5432)
18+
"NAME": os.environ.get("POSTGRES_DB", "modelutils"),
19+
"USER": os.environ.get("POSTGRES_USER", 'postgres'),
20+
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", ""),
21+
"HOST": os.environ.get("POSTGRES_HOST", "localhost"),
22+
"PORT": os.environ.get("POSTGRES_PORT", 5432)
2323
},
2424
}
25-
2625
SECRET_KEY = 'dummy'
2726

2827
CACHES = {

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ passenv =
3636
CI
3737
FORCE_COLOR
3838
GITHUB_*
39-
DB_*
39+
POSTGRES_*
4040
usedevelop = True
4141
commands =
4242
python -m pytest {posargs}

0 commit comments

Comments
 (0)