Drone Transportation Infrastructure API
Distributed under the terms of the MIT license.
This project was built using:
- Python
- Django
- Django Rest Framework
- Docker
- Poetry (not required)
(This step is not required if you use poetry)
python -m venv .venv
pip install .
or use poetry:
poetry install
source .venv/bin/activate
or use poetry:
poetry shell
Then run the development server
python manage.py runserver
This project creates for you an administration account with username admin
and password admin1
.
For providing initial data for models you can run these commands:
python manage.py loaddata drones # this create some drones
python manage.py loaddata medications # this create some medications
This will create a periodic task to check the Drone battery and create a Log every 8 hours
python manage.py check_battery
or you can specify the hours:
python manage.py check_battery --hour 5
This project uses Docker for deployment
You must create .env file with the next variables:
DJANGO_SETTINGS_MODULE
: project settings. (setconfig.settings.develop
).SECRET_KEY
: used to provide cryptographic signing.DB_HOST
: postgres database host.DB_PORT
: postgres database port.DB_USER
: postgres database user.POSTGRES_PASSWORD
: postgres database password.POSTGRES_DB
: postgres database name.ALLOWED_HOSTS
: A list of strings representing the host/domain names that this Django site can serve.
Here you have an example
You must have installed Docker and Docker Compose to run the application:
docker-compose up -d
Here set an example for a nginx configuration and with the certbot to manage the ssl. This project is set to only run in secure protocol (https)
server {
server_name drones-api.ragnarok22.dev;
location / {
proxy_pass http://localhost:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/drones-api.ragnarok22.dev/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/drones-api.ragnarok22.dev/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = drones-api.ragnarok22.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name drones-api.ragnarok22.dev;
return 404; # managed by Certbot
}
docker-compose run api python manage.py check_battery
For running test
coverage run manage.py test apps
coverage report
This API documentation is in Postman