Backend for brewmaster project.
- Python 3.7
- Pipenv
- PostgreSQL (recommended version 11.5)
- Git
The Git installation example below will download the codebase project and run the pipenv install. Pipenv will create a virtual environment in which will install all project dependencies.
git clone https://github.com/brewmajsters/brewmaster-backend.git
cd brewmaster-backend
pipenv install
- In project root is located file
.env.example
. - Rename this file to
.env
. - Configure variables in
.env
file according to your needs.
(Pay attention to variable: RUN_ENVIRONMENT
. If you set that variable to value development
,
this configuration setting will create software emulated modules for testing purposes.
This setting should be activated only if you can't communicate with real devices and HW components.
For production purposes you should set this variable to value production
.)
- Download PostgreSQL (Our tested and working Postgresql server with timescale extension is version 11.5).
- Install Postgresql according to manual on official web page.
- Download TimeScaleDB extension for Postgresql.
- Install TimeScaleDB according to manual on official web page.
- Add TimeScale extension to installed Postgresql server.
- Connect to Postgresql server via CMD:
psql -U postgres -h host -p port
- Create new database:
CREATE database tutorial;
- Connect to created database:
\c tutorial
- Create TimescaleDB extension to specified database:
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
- Connect to Postgresql server via CMD:
WARNING: During installation on Windows platform creating database extension raised error:
ERROR: could not load library "C:/Program Files/PostgreSQL/11/lib/timescaledb-1.5.0.dll": The specified module could not be found.
Issue was resolved on Github.
- Activate environment
pipenv shell
. - Run download dependencies from pipfile
pipenv update
.
- If you only wish to create empty DB with no testing data skip this step.
- Run server from project root path with command:
python wsgi.py
(only for DB table recreating purposes) - After the server start-up is finished, you need to look if DB tables are created successfully.
- Stop the server.
- Run command for populating DB tables with testing data:
flask seed run
- Run command in project root
python wsgi.py
.
DEPENDENCY: Running TimescaleDB instance (docker, ansible)
- Build from the Dockerfile:
docker build -t backend:latest .
- Run the container from newly created image:
- available environment variables are identical to those in .env file
- (in case fo docker TimeScaleDB) retrieve the timescaldb docker instance ip address:
docker inspect <TIMESCALEDB-DOCKER-ID> | jq -r '.[0].NetworkSettings.Networks.bridge.IPAddress'
- e.g.
docker run -d --name backend -p 5000:5000 -e DATABASE_HOST=<IP> -e DATABASE_PASSWORD=<PASSWD> backend
-
Project is developed in python with flask web micro-framework.
-
Backend communicates with 4 ways:
- Communication through REST.
- Communication with PostgreSQL DB.
- Communication through MQTT.
- Communication through Web Sockets.
-
We use strict code-style according to PEP8 and we are using for maintaining codebase technique git-flow.
- master branch always contains stable version of source code.
- develop branch containing changes implemented in specific sprint.
- feature/ branches containing implementations of specific issues/features.
- fix/ branches containing error corrections.
Implemented tests are located in path core/tests/*
. To run test file, its needed to name it with prefix test_*.py
.
Tests are implemented with pytest library. Pytest settings are located in project root file pytest.ini
.
- To run tests it's needed to type command
pytest
.
Database seed is made with library flask-seeder. All seeders are located in
path seeds/*
- To seed database with fake data for test purposes, its necessary to run command
flask seed run
.
Cheers! 🍻, by team Brewmasters.