Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgresql docker container for local development #563

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
foarsitter marked this conversation as resolved.
Show resolved Hide resolved
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
Loading