This repo is a production ready seed project. The app shows a list of users.
- The
clientservice is a build of theclientdirectory. It contain an Angular app, built with Angular-Cli, ngrx to handle state, Angular Material as a design library, have service worker, andAOTcompiled. The app shows the users from the Django api. - The
serverservice is a build of theserverdirectory. It contain a simple Django app that expose anapiof Djangouserswith Django REST framework. The Python serve through a gunicorn server installed in the container. - There is a
postgresservice for the Django database. Thedatabasedirectory contains the automatic backup script. - There is an
nginxservice to serve static files (the client app). - There is an
haproxyservice to get all the HTTP requests and do load balancing between the containers in the services. - There are a separate containers for the ELK Stack for logging. The
serverand theclientlogs sent to logstash, and saved in elasticsearch. There is also a kibana instance to check and analyze all the logs. - There is a
visualizercontainer to visualize where is each container is located at (on which server).
All the parts are in a separate Docker containers and we use Docker Swarm to manage them.
- install docker.
Automatic installation of the project with docker.
- If you work on
winormacplease comment the lines of thedatabase -> volumesindocker-compose.yml, this share volume withlinuxsystem only. - In
clientdirectory rundocker build -t client .to build the Docker image. - In
serverdirectory rundocker build -t server .to build the Docker image. - To create a swarm
docker swarm init. - Download all docker images:
docker pull dockercloud/haproxydocker pull postgresdocker pull dockersamples/visualizer:stabledocker pull elasticsearch:5.4.3docker pull kibana:5.4.3docker pull logstash:5.4.3
- Run
docker stack deploy --compose-file=docker-compose.yml prod - Open the browser at http://localhost to see your Angular (client) app.
- Open the browser at http://localhost:8000 to see your Django (server) app.
- Open the browser at http://localhost:8080 to see the visualizer.
- Open the browser at http://localhost:5601 to see Kibana and check your logs.
If you want to install the project manually, go to the /client or /server directories and read the README file.
Tools we use
- When install the project with docker, there is an
entrypoint.shscript that runs in theservercontainer. It'll migrate the database and create a new super user with a usernameadminand a passwordpass. - We use django-admin-honeypot to fake the default Django admin login screen to log and notify admins of attempted unauthorized access. So the real Django admin login screen will be under
/secret-admin. - We also use django-flat-responsive to make the Django admin screens responsive to mobile.
There is already tests for the server and the client, we currently at +90 percent coverage.
To run the client tests and lint run the commands below in the client directory.
npm run lint
npm run test
To run the server tests and lint run the commands below in the server directory.
pycodestyle --show-source --max-line-length=120 --show-pep8 .
python manage.py test
We also write some tests for doing load test with locust, you can find it under server/locustfile.py.
To do a load test just install locust (it's in the requirements.txt file) go to server directory and run
locust --host=http://localhost
Then open up Locust’s web interface http://localhost:8089.
To update any of the containers that are in a service with a new image just create a new image, for example
docker build -t server:v2 .
And then update the service with the new image
docker service update --image server:v2 prod_server
Each day a backup of the PostgreSQL database will be created. The daily backups are rotated weekly, so maximum 7 backup files will be at the daily directory at once.
Each Saturday morning a weekly backup will be created at the weekly directory. The weekly backups are rotated on a 5 week cycle.
Each month at the 1st of the month a monthly backup will be created at the monthly directory. Monthly backups are NOT rotated
The backups are saved at /var/backups/postgres at the host machine via a shared volume. It can be configured in the docker-compose.yml at volumes section of the database service.
Just fork and do a pull request (;
