sample1 is a vagrant box provisioned by ansible with:
- HAproxy acting as load-balancer
- web application written in Django(Python) running in Docker container to store/list events in DB
- PostgreSQL running in Docker container
Despite there are two instances of web application, PostgreSQL is obviously SPOF in this example.
- ansible=7.3.0
- vagrant=2.4.1
# Install ansible dependencies
ansible-galaxy install -p provisioning/roles/ -r requirements.yml
# Start and provision vagrant environment
vagrant up
Once vagrant environment is up, web application should be reachable at
http://localhost:8080
.
Followin URIs are available:
/events
GET
to list events in DBPOST
to push event into DB
/event/<id>/
to show one particular event stored in DB
Event is expected to be in JSON format with the following mandatory attributes:
timestamp
- seconds since 1970-01-01 00:00:00 UTC aka Unix timestampmessage
- text
# In order to push some event run the following command
curl -XPOST -H 'Content-Type: application/json' http://localhost:8080/events \
-d '{"timestamp": 1515948504, "message": "Printer is on fire"}'
# To list events stored in DB
curl http://localhost:8080/events
# And to get the detail of particular event
curl http://localhost:8080/event/1/
PostgreSQL configuration is being fetched from ENV variables. Therefore, sadly
these variables must be set in order to use manage.py
.
POSTGRES_HOST
POSTGRES_DB
POSTGRES_USER
POSTGRES_PASS