This project is part of Sento's backend.
Async API for exposing results of Sento's analytics
For this type of installation you will need:
- Docker Engine 17.12.0 or higher.
- Docker Compose 1.18.0 or higher.
These are the software requirements of each component if you want to run it locally:
-
Database
- PostgreSQL 9.6 or higher (older versions have not been tested).
- PostGIS 2.3.0 or higher.
pg_trgm
extension activated.
-
API
- Python 3.7 or higher.
- Pipenv (package manager).
In order to set up an instance you need a PostgreSQL database initialised using the instructions available here.
The best way to set up the database is with Docker container provided in this repository, but you can also use an existing DBMS. You need to do the following:
-
Configure variables for the database:
- Using the Docker Container:
- Create a
db.env
file from a copy ofdb.example.env
. - Configure the different values in
db.env
according to your needs. Keep in mind that most of those values will be needed by other Sento's components in order to connect to the database.
- Create a
- Using an existing PostgreSQL instance: If you have an existing PostgreSQL database
that matches the requirements, you can create a database for sento using the SQL script
located at
sento_api/database/init.sql
. Substitute the different variables at the start of that script with the values that best suit you.
- Using the Docker Container:
-
Configure Sento API database connection:
- Create a
config.ini
file from a copy ofconfig.example.ini
- Adjust the configuration in
config.ini
according to your needs. Keep track of the variables set in yourdb.env
file or in your customizedinit.sql
script. You should leave the default value ofsento-db
in thehost
key inside the[postgres]
section if you plan to use the PostgreSQL container, this is a name that can be used by the container to reach to the database in the container network.
- Create a
-
Create a database and a user for Sento:
- With the Docker Container:
- Run
docker volume create sento-data
, this will create a Docker volume where all database data will be stored, useful for making backups and avoiding data loss caused by the removal of the database container. - Run
docker-compose up -d sento-db
, this will create a PostgreSQL + PostGIS container without any kind of structure. - Run
docker-compose exec sento-db psql -U postgres -f /src/init.sql
, this will create a user and a database for Sento, this step uses the configuration values written indb.env
file.
- Run
- Using an available instance: run your customized
init.sql
script with a tool likepsql
orpgAdmin
.
- With the Docker Container:
-
Create the tables from the models:
- With Docker:
- Build the API container's image with
docker-compose build
. - Run
docker-compose run --rm --use-aliases sento-api pipenv run alembic upgrade head
. This will create the necessary tables in the database using Alembic.
- Build the API container's image with
- Locally using pipenv:
- Create a Python virtual environment with the necessary dependencies with
pipenv sync
. - Run
pipenv run alembic upgrade head
.
- Create a Python virtual environment with the necessary dependencies with
- With Docker:
After that you will be all set!
Check the values set in your config.ini
file (made from a copy of
config.example.ini
), specifically the values set in the [api]
section.
- With Docker:
- Remember that the values set in the
config.ini
file are relative to the container. Normally you will not need to change the listening IP and port present in theconfig.example.ini
, but, if you make any changes you will need to keep them in mind for the next step. - Create a
docker-compose.override.yml
file fromdocker-compose.override.exammple.yml
file, then you can configure the IP and port mapping between your host and the container. You can also override other container configurations if you need. - If you built the image for the API container previously, you can run
docker-compose up -d sento-api
.
- Remember that the values set in the
- Running locally:
- Create a Python virtual environment with the necessary dependencies with
pipenv sync
, if you have not created it previously. - Run the following command
pipenv run sento_api/main.py
.
- Create a Python virtual environment with the necessary dependencies with
If you have followed the previous steps you should have an instance of the API waiting for requests.
The source code of this project is licensed under the GNU Affero General Public License v3.0.