From 3d601b3aead5a2939a65d3814af4aae6854d2429 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 7 Jan 2025 15:31:52 +0100 Subject: [PATCH] :whale: [#4993] Add docker-compose file and fixtures for Referentielijsten to be used for unittests with VCR and local development --- docker/docker-compose.referentielijsten.yml | 57 +++++++++++++++++++ docker/referentielijsten/README.md | 41 +++++++++++++ .../0001-docker-init-referentielijsten-db.sql | 5 ++ .../fixtures/referentielijsten_fixtures.json | 57 +++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 docker/docker-compose.referentielijsten.yml create mode 100644 docker/referentielijsten/README.md create mode 100644 docker/referentielijsten/docker-init-referentielijsten-db/0001-docker-init-referentielijsten-db.sql create mode 100644 docker/referentielijsten/fixtures/referentielijsten_fixtures.json diff --git a/docker/docker-compose.referentielijsten.yml b/docker/docker-compose.referentielijsten.yml new file mode 100644 index 0000000000..f95e1912ff --- /dev/null +++ b/docker/docker-compose.referentielijsten.yml @@ -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 diff --git a/docker/referentielijsten/README.md b/docker/referentielijsten/README.md new file mode 100644 index 0000000000..a4f6a9bb62 --- /dev/null +++ b/docker/referentielijsten/README.md @@ -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 +``` diff --git a/docker/referentielijsten/docker-init-referentielijsten-db/0001-docker-init-referentielijsten-db.sql b/docker/referentielijsten/docker-init-referentielijsten-db/0001-docker-init-referentielijsten-db.sql new file mode 100644 index 0000000000..b55486a20f --- /dev/null +++ b/docker/referentielijsten/docker-init-referentielijsten-db/0001-docker-init-referentielijsten-db.sql @@ -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; diff --git a/docker/referentielijsten/fixtures/referentielijsten_fixtures.json b/docker/referentielijsten/fixtures/referentielijsten_fixtures.json new file mode 100644 index 0000000000..a3a5a74f50 --- /dev/null +++ b/docker/referentielijsten/fixtures/referentielijsten_fixtures.json @@ -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": "john@doe.nl", + "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 + } +} +]