Skip to content

Commit

Permalink
🐳 [#4993] Add docker-compose file and fixtures for Referentielijsten
Browse files Browse the repository at this point in the history
to be used for unittests with VCR and local development
  • Loading branch information
stevenbal committed Jan 14, 2025
1 parent dd00dea commit 14a1f5e
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
57 changes: 57 additions & 0 deletions docker/docker-compose.referentielijsten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.8'

name: referentielijsten

services:
referentielijsten-redis:
image: redis:7
command: ["redis-server", "--appendonly", "yes"]
networks:
- open-forms-dev

referentielijsten-db:
image: postgres:${PG_VERSION:-14}
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- ./referentielijsten/docker-init-referentielijsten-db/:/docker-entrypoint-initdb.d
- referentielijsten-db:/var/lib/postgresql/data
networks:
- open-forms-dev

referentielijsten-web.local:
image: maykinmedia/referentielijsten-api:${REFERENTIELIJSTEN_VERSION:-0.2.0}
environment: &referentielijsten_web_env
- DJANGO_SETTINGS_MODULE=referentielijsten.conf.docker
- SECRET_KEY=${SECRET_KEY:-7&3f^bo1(-5($bre4iv-!nt%1xr!b54b&y7+97j5f&ndm_e=lz}
- ALLOWED_HOSTS=referentielijsten-web.local,localhost
- DB_NAME=referentielijsten
- DB_USER=referentielijsten
- DB_HOST=referentielijsten-db
- DISABLE_2FA=true
- IS_HTTPS=no
- CACHE_DEFAULT=referentielijsten-redis:6379/0
- CACHE_AXES=referentielijsten-redis:6379/0
- SUBPATH=${SUBPATH:-/}
- DJANGO_SUPERUSER_PASSWORD=admin
ports:
- 8004:8000
volumes: &referentielijsten_web_volumes
# mount fixtures dir to automatically populate the DB
- ./referentielijsten/fixtures/:/app/fixtures
- media:/app/media # Shared media volume to get access to saved OAS files
- private-media:/app/private-media
depends_on:
- referentielijsten-db
- referentielijsten-redis
networks:
- open-forms-dev

volumes:
referentielijsten-db:
media:
private-media:

networks:
open-forms-dev:
name: open-forms-dev
41 changes: 41 additions & 0 deletions docker/referentielijsten/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Referentielijsten API

The `docker-compose.referentielijsten.yml` compose file is available to run an instance of Referentielijsten API.

## docker compose

Start an instance in your local environment from the parent directory:

```bash
docker compose -f docker-compose.referentielijsten.yml up -d
```

This brings up the admin at http://localhost:8004/admin/. You can log in with the `admin` / `admin`
credentials.

## Load fixtures

The fixtures in `referentielijsten/fixtures` are automatically loaded when the Referentielijsten container starts.

## Dump fixtures

Whenever you make changes in the admin for the tests, you need to dump the fixtures again so that
bringing up the containers the next time (or in other developers' environments) will still have the
same data.

Dump the fixtures with (in the `docker` directory):

```bash
docker compose -f docker-compose.referentielijsten.yml run referentielijsten-web.local \
python src/manage.py dumpdata \
--indent=4 \
--output /app/fixtures/referentielijsten_fixtures.json \
accounts \
api
```

Depending on your OS, you may need to grant extra write permissions:

```bash
chmod o+rwx ./referentielijsten/fixtures
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE USER referentielijsten;
CREATE DATABASE referentielijsten;
GRANT ALL PRIVILEGES ON DATABASE referentielijsten TO referentielijsten;
-- On Postgres 15+, connect to the database and grant schema permissions.
-- GRANT USAGE, CREATE ON SCHEMA public TO referentielijsten;
57 changes: 57 additions & 0 deletions docker/referentielijsten/fixtures/referentielijsten_fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"model": "accounts.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$600000$DCgCQRA6R57PicaatiWGHU$S65r6Yedgkfv/exr8gFZogpyuCgortmrloq7+LBdnyY=",
"last_login": "2025-01-07T14:17:06.242Z",
"is_superuser": true,
"username": "admin",
"first_name": "",
"last_name": "",
"email": "",
"is_staff": true,
"is_active": true,
"date_joined": "2025-01-07T14:10:46.508Z",
"groups": [],
"user_permissions": []
}
},
{
"model": "api.tabel",
"pk": 1,
"fields": {
"code": "tabel1",
"naam": "Tabel1",
"einddatum_geldigheid": null,
"beheerder_naam": "John Doe",
"beheerder_email": "[email protected]",
"beheerder_afdeling": "",
"beheerder_organisatie": ""
}
},
{
"model": "api.item",
"pk": 1,
"fields": {
"tabel": 1,
"code": "option1",
"naam": "Option 1",
"begindatum_geldigheid": "2025-01-07T14:17:53Z",
"einddatum_geldigheid": null,
"aanvullende_gegevens": null
}
},
{
"model": "api.item",
"pk": 2,
"fields": {
"tabel": 1,
"code": "option2",
"naam": "Option 2",
"begindatum_geldigheid": "2025-01-07T14:17:59Z",
"einddatum_geldigheid": null,
"aanvullende_gegevens": null
}
}
]

0 comments on commit 14a1f5e

Please sign in to comment.