Skip to content

Commit

Permalink
Merge pull request #563 from foarsitter/docker_postgresql
Browse files Browse the repository at this point in the history
Postgresql docker container for local development
  • Loading branch information
foarsitter authored Mar 25, 2024
2 parents 87a9466 + caac9a4 commit 8bef73c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Test
on: [push, pull_request]

env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
FORCE_COLOR: 1

jobs:
Expand All @@ -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: >-
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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%.

Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 5 additions & 6 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
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 = {
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ passenv =
CI
FORCE_COLOR
GITHUB_*
DB_*
POSTGRES_*
usedevelop = True
commands =
python -m pytest {posargs}
Expand Down

0 comments on commit 8bef73c

Please sign in to comment.