Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

inLabFIB/toopath-api

Repository files navigation

TooPath v3

MIT licensed

TooPath v3 is an API that let you manage tracks and locations related to a device. This API is protected with JWT authentication and follows the GeoJSON RFC 7946.

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 deployment for notes on how to deploy the project on a live system.

Docker image

If you only want to run TooPath you can use the available Docker image, after setting up database (see Database section below) you can do:

docker build -t toopath/api .
docker run --name toopath --network toopathnetwork -p 8080:8080 toopath/api

And a working instance of TooPath will be available on port 8080.

Network flag is required to connect this container to database container.

Prerequisites

  • Install python 3.6.1.
  • Install OSGeo4W following the steps in GeoDjango Tutorial (make sure to install the same bit version of python and OSGeo4W.
  • Install PyCharm (optional, recommended for Windows users).

Windows

Linux

Environment setup

This environment setup can be done via console and also, via PyCharm console (if you have installed this IDE). First of all, create a virtual environment:

mkvirtualenv [virtual_environment_name]

If the virtual environment is not automatically activated, then use:

workon [virtual_environment_name]

Install all the python requirements:

pip install -r requirements.txt

As it is recommended on this settings tutorial, this project has production and local separate settings. To use the local settings setup your DJANGO_SETTINGS_MODULE environment variable to TooPath3.settings.local.

Database setup

There is a Vagrant file and a Docker file with PostgreSQL and PostGIS installed and configured with local settings.

For those who prefer to use Vagrant, follow this Getting started of Vagrant to create a virtual machine with.

Docker users should build image and run a container using (network flag is required to connect this container to TooPath container):

cd bootstrap
docker build -t toopath/postgres .
docker run --name postgres -p 5432:5432 --network toopathnetwork toopath/postgres

Of course, manual configuration is available, you can create the database with the PostgreSQL and PostGIS versions mentioned above.

Apply all the migrations with:

python manage.py migrate

PyCharm setup

  1. Go to File>Settings>Project:"name">Project interpreter>Add local
  2. Select python.exe from [virtual_environment_name] folder
  3. Mark Associate this virtual environment with current project
  4. Configure the settings INSTALLED_APPS and DATABASES following the steps in Configure settings.py

Running the API

Use python manage.py runserver x.x.x.x:aaaa where x.x.x.x is the address and aaaa is the port. For local example:

python manage.py runserver 127.0.0.1:8080 

Running the tests

Once you’ve written tests, run them using the test command of your project’s manage.py utility:

python manage.py test

If you wanna run a concrete test you can do it specifying the package. For example, to run the devices test:

python manage.py test TooPath3.devices.tests

If you wanna run test inside docker:

docker exec -it <api_container_name> python manage.py test

Deployment (production)

To apply the migrations on the production environment use:

python manage.py migrate --settings=TooPath3.settings.production

To start the API on the production enviroment use:

python manage.py runserver x.x.x.x:aaaa --settings=TooPath3.settings.production

You can also setup the DJANGO_SETTINGS_MODULE environment variable to TooPath3.settings.production.

Built With

Authors

  • Albert Díaz Benitez - First stable version - AlbertWayne

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments