From f6dcaf5510d083321151f0800a8b3284b5221882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Mon, 19 Feb 2018 14:15:11 +0100 Subject: [PATCH] Update readme, makefile and settings. --- Makefile | 1 + README.md | 41 ++++++++++++++++++++++++++----------- openlobby/core/documents.py | 2 +- openlobby/settings.py | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 1004b1d..4d22aba 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ run: migrate: DEBUG=1 python manage.py migrate + DEBUG=1 python manage.py search_index --rebuild -f build: docker build -t openlobby/openlobby-server:latest . diff --git a/README.md b/README.md index cd0bddf..88d47a5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Configuration is done by environment variables: - `DATABASE_DSN` - DSN of PostgreSQL database (default: `postgresql://db:db@localhost:5432/openlobby`) - `ELASTICSEARCH_DSN` - DSN of Elasticsearch cluster (default: `http://localhost:9200`) - `SITE_NAME` - site name for OpenID authentication (default: `Open Lobby`) - - `ES_INDEX` - Elasticsearch index (default: `openlobby`) + - `ES_INDEX` - Elasticsearch indices prefix (default: `openlobby`) ## Docker @@ -41,12 +41,27 @@ Demo of Open Lobby with instructions is in repository ## Local run and development -You need to have Python 3 installed. Clone this repository and run: +### Prrequisites + +You need to have Python 3 installed. + +Run PostgreSQL database on `localhost:5432` with user `db`, password `db` and +database `openlobby`. You can provide different address in environment variable +`DATABASE_DSN`. + +Run Elasticsearch server +[openlobby/openlobby-es-czech](https://github.com/openlobby/openlobby-es-czech) +on `http://localhost:9200`. You can provide different address in environment +variable `ELASTICSEARCH_DSN`. + +### Local run + +Clone this repository and run: 1. `make init-env` - prepares Python virtualenv in dir `.env` 2. `source .env/bin/activate` - activates virtualenv 3. `make install` - installs requirements and server in development mode -4. `make migrate` - runs database migrations +4. `make migrate` - runs database migrations and rebuilds Elasticsearch index 5. `make run` - runs development server on port `8010` Now you can use GraphQL API endpoint and GraphiQL web interface at @@ -54,16 +69,18 @@ Now you can use GraphQL API endpoint and GraphiQL web interface at Next time you can just do steps 2 and 5. -Development server assumes that you have -[openlobby/openlobby-es-czech](https://github.com/openlobby/openlobby-es-czech). -running on `http://localhost:9200`. You can override this address in environment -variable `ELASTICSEARCH_DSN`. E.g. -`ELASTICSEARCH_DSN=http://my-server:9200 make run` - ### Testing Run: `pytest` -Expects Elasticsearch for tests running on `localhost:9200` (can be override by -environment variable `ELASTICSEARCH_DSN`). Tests creates random indices with -prefix `test_` and deletes all indices matching `test_*` on teardown. +For full test suite run you have to provide OpenID Provider issuer URL which +allows client registration. For example you can run Keycloak sever locally: +`docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=pass -p 8080:8080 --rm jboss/keycloak` + +Login into Keycloak admin console `http://localhost:8080/auth/admin/` +(as admin/pass) and go to Realm Settings -> Client Registration -> Client +Registration Policies -> Trusted Hosts. There add `localhost` to "Trusted +Hosts", turn off "Host Sending Client Registration Request Must Match" and save +it. + +Now run: `pytest --issuer=http://localhost:8080/auth/realms/master` diff --git a/openlobby/core/documents.py b/openlobby/core/documents.py index c4574a7..4d4b339 100644 --- a/openlobby/core/documents.py +++ b/openlobby/core/documents.py @@ -5,7 +5,7 @@ import json from .models import Report -report = Index('report') +report = Index('{}-reports'.format(settings.ES_INDEX)) @report.doc_type diff --git a/openlobby/settings.py b/openlobby/settings.py index dad0d61..07cc939 100644 --- a/openlobby/settings.py +++ b/openlobby/settings.py @@ -141,7 +141,7 @@ GRAPHENE = { ############################################################################### # Custom settings -# Elasticsearch index +# Elasticsearch index with reports ES_INDEX = os.environ.get('ES_INDEX', 'openlobby') # default analyzer for text fields -- GitLab