- 1 Authentication microservice written in Flask (custom token-based authentication)
- 1 Redis service (where temp auth tokens are stored)
- 1 Nginx Load Balancer (serving the 2 parent services below)
- 2 Parent server apps written in Django (Where most of the backend logic happens - pulls data from various API's into one place)
- 1 Postgres service
- 1 Messaging microservice written in Flask
- 1 User/Profile microservice written in Flask
When this project was live, the path to production looked like the following:
- Each service has it's own Github Repository
- When a pull request is initiated against any one of the repositories, a new build is triggered in CircleCI
- If all tests pass, the pull request is merged into master
- Github service hooks notify Docker Hub to build a new Docker image.
- Web hooks running on EC2 detect when a new image is available on Docker Hub.
- If a new image is recognized, it is pulled down from Docker Hub and automatically deployed to the correct AWS instance via Docker.
Since this project is no longer live, I made some changes to the above steps outlined below:
- The entire project (consisting of all the microservices and build/deploy infrastructure) is now contained within a single repository.
- All the services above are mapped out in a docker-compose.yml with some small tweaks that enable a single-click production deploy.
- Included is the Dockerrun.aws.json used to single-click deploy to AWS Elastic Beanstalk
- Extensive use of environment variables and automation scripting to handle deployment from scratch (ie: deploying/configuring postgres with postGIS, populating database with location data, setting permissions, linking services, etc.)
- Using Ansible in place of pip to install application dependencies
- Static assetts were moved from an S3 bucket to the repository itself
cannablr uses a number of open source projects to work properly
- Flask - a Python microframework!
- Django - a high level Python web framework
- jQuery - duh
- Userena - a Django library for custom user profiles/permissions
- Twitter Bootstrap - great UI boilerplate for modern web apps
- masonry.js - a js library for vertically positioning UI elements
- Docker - containers for deploying applications
cannablr requires Docker to run.
Clone the repo and it's as simple as docker-compose up.
$ git clone https://github.com/donnaloia/cannablr.git
$ cd cannablr
$ docker-compose build
$ docker-compose up
For production environments...
$ git clone https://github.com/donnaloia/cannablr.git
$ cd cannablr
$ docker-compose build
$ docker-compose up
Now What?
$ docker-compose ps
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' nginx
Curl or visit this ip address in your browser (port 8000) - the web app should be running and fully functional!
$ docker-compose scale parentserver=2
or...
$ docker-compose scale parentserver=10
The nginx.conf has been edited to automatically detect when a new instance of parentserver has been added upstream. We can now add multiple instances of parentserver on the fly, and nginx will automatically load balance between them. Pretty cool!
- Write MOAR Tests
- The Flask Auth service is currently running using Flask's built in http server - This is obviously not production friendly
- Add readme's for each microservice with a map of API endpoints
Free Software, Hell Yeah!