https://github.com/zstyblik/sample1
https://github.com/zstyblik/sample1
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zstyblik/sample1
- Owner: zstyblik
- Created: 2018-01-15T06:52:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-05-24T08:37:34.000Z (about 1 year ago)
- Last Synced: 2025-05-24T09:31:36.068Z (about 1 year ago)
- Language: Python
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sample1
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.
## Dependencies
* ansible=7.3.0
* vagrant=2.4.1
## How-to run/setup
```
# Install ansible dependencies
ansible-galaxy install -p provisioning/roles/ -r requirements.yml
# Start and provision vagrant environment
vagrant up
```
## Web application
Once vagrant environment is up, web application should be reachable at
`http://localhost:8080`.
## URIs
Followin URIs are available:
* `/events`
* `GET` to list events in DB
* `POST` to push event into DB
* `/event//` to show one particular event stored in DB
## Structure of Event
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 timestamp
* `message` - text
## How-to test
```
# 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/
```
## Extra notes
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`
# References
* https://github.com/geerlingguy/ansible-vagrant-examples