= Portal Backend Kontr portal backend image:https://gitlab.fi.muni.cz/grp-kontr2/portal/badges/master/pipeline.svg[link="https://gitlab.fi.muni.cz/grp-kontr2/portal/commits/master",title="pipeline status"] == Documentation More complex documentation you can find link:https://gitlab.fi.muni.cz/grp-kontr2/kontr-documentation[here] == Getting Started These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See documentation for notes on how to deploy the project on a live system. == Installation Here are simple instructions how to download and run the server. You need Python 3.6. ==== Checkout the portal project Checkout the portal. [source, shell] ---- $ git clone https://gitlab.fi.muni.cz/grp-kontr2/portal ---- ==== Install dependencies You need to install link:https://www.python-ldap.org/en/latest/installing.html[python-ldap], postgres development and python dev dependencies. ===== Alpine linux: [source, shell] ---- $ apk add --update --no-cache g++ gcc libxslt-dev postgresql-dev postgresql-libs openldap-dev python3-dev ---- ===== Debian: [source, shell] ---- $ apt install ldap-utils ldapscripts libldap2-dev libsasl2-dev ---- ==== Install Python dependencies If you need to run the tests, you need to call `pipenv install` with `--dev` option. [source, shell] ---- $ pipenv install --dev ---- == Running the tests To run the test you need to run: [source, bash] ---- $ pipenv run coverage run -m pytest ---- == Development Deployment === Deploy postgres For manual deployment you need to have deployed database - for example `postgres`. **Docker instance:** [source, shell] ---- $ docker run -d --name pgdb -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres:latest ---- === Deploy redis You need redis as message broker for the celery. [source, shell] ---- $ docker run --rm --name some-redis -p 6379:6379 -d redis redis-server ---- === Configure the Portal You can use the `ENV` variables or configure it using the `portal.local.cfg` or `portal/config.py`. Here are some important variables: - `SQLALCHEMY_DATABASE_URI` - Database uri for SQLAlchemy (example: `postgresql://postgres:postgres@localhost:5432/postgres`) - `JWT_SECRET_KEY` - Key to be used to encrypt the `access_code` for authentication - `PORTAL_STORAGE_BASE_DIR` - Storage base dir - where to store all the files (examle: `/tmp/portal/storage`) - `GITLAB_URL` - Url to Gitlab instance - `GITLAB_CLIENT_ID` - Gitlab client id - `GITLAB_CLIENT_SECRET` - Client secret - `FRONTEND_URL` - Where to redirect after gitlab login was successfull - `EMAIL_HOST` - Where is running the mail server - `EMAIL_PORT` - Port on which the mail server is running - `EMAIL_DEFAULT_FROM` - From who the emails are - `PORTAL_DATA_WORKER_DOMAIN` - Domain where default worker will be running (default: `localhost`) This one is mostly for the template - `LDAP_URL` - LDAP url, required only if you need LDAP support For more take a look at the config files. Logging specific: ``` LOG_LEVEL_GLOBAL = 'INFO' LOG_LEVEL_FILE = LOG_LEVEL_GLOBAL LOG_LEVEL_CONSOLE = LOG_LEVEL_GLOBAL ``` ==== Init the portal Initialize the portal database and data [source, shell] ---- $ flask db upgrde $ flask data init 'dev' $ flask users create admin --password '' ---- ==== Run the celery worker Run the async worker [source, shell] ---- $ celery -A app.celery worker ---- ==== Run the flask server - API Run the flask API server. [source, shell] ---- $ flask run -p 8000 ---- == Contributing Please read `CONTRIBUTING.adoc` for details on our code of conduct, and the process for submitting pull requests to us. == Authors * *Matej Dujava* * *Barbora Kompišová* - https://gitlab.fi.muni.cz/xkompis[xkompis] * *Kristýna Pekarková* * *Peter Stanko* - https://gitlab.fi.muni.cz/xstanko2[xstanko2] == Acknowledgments * Hat tip to anyone who's code was used * Inspiration * etc