From 106f1ed7ca74c2eb4d64b67bb1d9079c0cb9e389 Mon Sep 17 00:00:00 2001 From: Nico Vermaas <vermaas@astron.nl> Date: Tue, 26 Jul 2022 14:00:41 +0200 Subject: [PATCH] add instructions to use local Docker container for Postgres --- README.md | 57 +++++++++++++++++++ .../docker/docker-compose-postgres-dev.yml | 22 +++++++ .../lofardata/templates/lofardata/index.html | 2 +- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 ldvspec/docker/docker-compose-postgres-dev.yml diff --git a/README.md b/README.md index 0ec67fed..722039d1 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,63 @@ After a collegue has made changes, then locally * pip install -r requirements\dev.txt * python manage.py migrate --settings=ldvspec.settings.dev + +## Local Development Environment + +### Postgres Database in Docker + +Run `docker-compose up -d` with the following compose file to spin up a new Postgres container. +See the `docker-compose-postgres-dev.yml` file in the `docker` directory. +(not that port 5433 is used. You can change that at will, but then also change it in `dev.py`) +```yaml + +version: "3.7" +services: + + ldv-spec-db: + image: postgres:14 + container_name: ldv-spec-postgres + expose: + - 5433 + ports: + - 5433:5432 + environment: + POSTGRES_PASSWORD: "secret" + POSTGRES_USER: "postgres" + POSTGRES_DB: "ldv-spec-db" + volumes: + - ldv-spec-db:/var/lib/postgresql/data + restart: always + +volumes: + ldv-spec-db: +``` + +### Django Application + * clone the repo + * open the project in Pycharm + * create a venv (File -> Settings -> Project -> Project Interpreter -> (click cog) -> add) + * pip install -r requirements\dev.txt + + * check and/or change the database connection in settings/dev/py. In this example it connects to a database server on 'raspiastro', + you have to change that to the server where you run your Postgres Docker container (localhost?) + +```python +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'USER': 'postgres', + 'PASSWORD': 'secret', + 'NAME': 'ldv-spec-db', + 'HOST': 'raspiastro', + 'PORT': '5433', + }, +} +``` + + * python manage.py migrate --settings=ldvspec.settings.dev + * python manage.py runserver --settings=ldvspec.settings.dev + ## Test Environment * https://sdc-dev.astron.nl/ldvspec/ diff --git a/ldvspec/docker/docker-compose-postgres-dev.yml b/ldvspec/docker/docker-compose-postgres-dev.yml new file mode 100644 index 00000000..c8a3fa54 --- /dev/null +++ b/ldvspec/docker/docker-compose-postgres-dev.yml @@ -0,0 +1,22 @@ +version: "3.7" +services: + + ldv-spec-db: + image: postgres:14 + container_name: ldv-spec-postgres + expose: + - 5433 + ports: + - 5433:5432 + env_file: + - $HOME/shared/ldvspec.env + environment: + POSTGRES_PASSWORD: "secret" + POSTGRES_USER: "postgres" + POSTGRES_DB: "ldv-spec-db" + volumes: + - ldv-spec-db:/var/lib/postgresql/data + restart: always + +volumes: + ldv-spec-db: \ No newline at end of file diff --git a/ldvspec/lofardata/templates/lofardata/index.html b/ldvspec/lofardata/templates/lofardata/index.html index 534bfbc0..8e7e2bd2 100644 --- a/ldvspec/lofardata/templates/lofardata/index.html +++ b/ldvspec/lofardata/templates/lofardata/index.html @@ -16,7 +16,7 @@ </tbody> </table> - <p class="footer"> Version 1.0.0 (25 jul 2022 - 8:00) + <p class="footer"> Version 1.0.0 (26 jul 2022 - 13:00) </div> -- GitLab