From b9c6e8bc3e54f3265fc99b2025a6369546ab07cb Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Thu, 16 Nov 2023 12:48:55 +0100 Subject: [PATCH] postgresql support (#79) * postgresql support * docs --- docs/index.md | 12 ++++++------ docs/maintenance.md | 8 ++++---- group_vars/all.yml | 2 ++ roles/backend/defaults/main.yml | 4 ++++ roles/backend/tasks/deploy.yml | 6 +++++- yap_dev_vars.yml | 4 ++-- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/docs/index.md b/docs/index.md index 15f51a5..f66e3b1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -26,11 +26,11 @@ git clone --recurse-submodules https://github.com/yaptide/ui.git Note `--recurse-submodules`. This is needed as the converter package is included as a submodule in both repositories. -Local deployment allows only for job execution on Celery worker. To be able to submit jobs to the HPC cluster, one needs to have access to the +Local deployment allows only for job execution on Celery worker. To be able to submit jobs to the HPC cluster, one needs to have access to the ## Deploying backend -Lets start with deploying backend using docker compose. This should take couple of minutes to complete. +Lets start with deploying backend using docker compose. This should take couple of minutes to complete. First go to the directory where backend was cloned: ```bash @@ -51,7 +51,7 @@ The `yaptide_nginx` container serves as a proxy and is exposing the REST API on ## Deploying frontend -In a similar way as for backend, the frontend can be deployed using docker compose. This should take couple of minutes to complete. +In a similar way as for backend, the frontend can be deployed using docker compose. This should take couple of minutes to complete. First go to the directory where frontend was cloned: ```bash @@ -76,10 +76,10 @@ Frontend is configured to use the backend REST API exposed on port 5000, using p At this point there is no single user in the database, so we need to create one. This can be done using the following command: ```bash -docker exec yaptide_flask python3 yaptide/admin/db_manage.py add-user admin --password password +docker exec yaptide_flask ./yaptide/admin/db_manage.py add-user admin --password password ``` ## Running first simulation -Now we are ready to run our first simulation. First we need to login to the frontend. Open your browser and navigate to [http://localhost:80](http://localhost:80) or [https://localhost:443](https://localhost:443). -Login with the credentials created in the previous step. \ No newline at end of file +Now we are ready to run our first simulation. First we need to login to the frontend. Open your browser and navigate to [http://localhost:80](http://localhost:80) or [https://localhost:443](https://localhost:443). +Login with the credentials created in the previous step. diff --git a/docs/maintenance.md b/docs/maintenance.md index e41604c..883585a 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -32,7 +32,7 @@ Note the `--build` flag. It is needed to rebuild the containers, as the source c ## Storage volume -The yaptide backend uses the docker volume named `yaptide_data` to store the data. It hosts SQLite database with following information: +The yaptide backend uses the docker volume named `yaptide_data` to store the data. It hosts PostgreSQL data with following information: * user accounts * data related to simulations: @@ -55,11 +55,11 @@ The SSL certificates are used to secure the communication for two cases: * between the user client and the machine serving the UI * between the user client and the machine serving the backend -Frontend uses Nginx to serve statically generated HTML, CSS and JavaScript files. +Frontend uses Nginx to serve statically generated HTML, CSS and JavaScript files. Backend uses Nginx as a proxy to forward requests to the backend server. Both Nginx instances are configured to use SSL certificates. -By default the self-signed certificates are used (usually not trusted by the browser). +By default the self-signed certificates are used (usually not trusted by the browser). They are generated automatically when the containers are started for the first time. To replace self-signed certificates with your own, stop the containers and replace the files according to the following recipe. @@ -106,4 +106,4 @@ Restart the container: ```bash docker restart yaptide_nginx -``` \ No newline at end of file +``` diff --git a/group_vars/all.yml b/group_vars/all.yml index df098ce..4e617ae 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -1,3 +1,5 @@ mode: deploy backend_password: "{{ lookup('ansible.builtin.password', 'roles/backend/files/password length=25 chars=ascii_letters,digits') }}" +backend_postgres_user: "{{ lookup('ansible.builtin.password', 'roles/backend/files/postgres_user length=25 chars=ascii_letters,digits') }}" +backend_postgres_password: "{{ lookup('ansible.builtin.password', 'roles/backend/files/postgres_password length=25 chars=ascii_letters,digits') }}" diff --git a/roles/backend/defaults/main.yml b/roles/backend/defaults/main.yml index 7f5f9b6..74766e7 100644 --- a/roles/backend/defaults/main.yml +++ b/roles/backend/defaults/main.yml @@ -12,4 +12,8 @@ backend_keycloak_realm: "" backend_ssl_crt: "server.crt" backend_ssl_key: "server.key" +backend_postgres_db: "yaptide" +backend_postgres_user: "yaptide" +backend_postgres_password: "yaptide" + ansible_become: false diff --git a/roles/backend/tasks/deploy.yml b/roles/backend/tasks/deploy.yml index 5bf68a5..fa4f112 100644 --- a/roles/backend/tasks/deploy.yml +++ b/roles/backend/tasks/deploy.yml @@ -45,6 +45,9 @@ {% if lookup('file', './.env', errors='ignore') is defined %} {{ lookup('file', './.env', errors='ignore') }} {% endif %} + POSTGRES_DB = {{ backend_postgres_db }} + POSTGRES_USER = {{ backend_postgres_user }} + POSTGRES_PASSWORD = {{ backend_postgres_password }} # https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_module.html @@ -75,12 +78,13 @@ command: 'python3 yaptide/admin/db_manage.py add-user admin --password {{ backend_password }}' chdir: /usr/local/app/ register: backend_add_user_output + retries: 5 + delay: 5 - name: Print output of add-user command ansible.builtin.debug: msg: '{{ backend_add_user_output.stdout_lines }}' - - name: Insert first cluster into database community.docker.docker_container_exec: container: yaptide_flask diff --git a/yap_dev_vars.yml b/yap_dev_vars.yml index 231087f..10641d8 100644 --- a/yap_dev_vars.yml +++ b/yap_dev_vars.yml @@ -33,5 +33,5 @@ backend_keycloak_base_url: 'https://sso.pre.plgrid.pl' backend_keycloak_realm: 'PLGrid' # github repo settings -frontend_repo_version: 'dependabot/npm_and_yarn/mui/lab-5.0.0-alpha.150' -backend_repo_version: '682-better-handling-of-error-messages-on-slurm' +frontend_repo_version: 'master' +backend_repo_version: '710-choose-more-efficient-db-engine'