This repo is a production ready seed project. The app shows a list of users.
clientservice is a build of the
clientdirectory. It contain an Angular app, built with Angular-Cli, ngrx to handle state, Angular Material as a design library, have service worker, and
AOTcompiled. The app shows the users from the Django api.
serverservice is a build of the
serverdirectory. It contain a simple Django app that expose an
userswith Django REST framework. The Python serve through a gunicorn server installed in the container.
- There is a
postgresservice for the Django database. The
databasedirectory 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
clientlogs 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).
- install docker.
Automatic installation of the project with docker.
- If you work on
macplease comment the lines of the
database -> volumesin
docker-compose.yml, this share volume with
docker build -t client .to build the Docker image.
docker build -t server .to build the Docker image.
- To create a swarm
docker swarm init.
- Download all docker images:
docker pull dockercloud/haproxy
docker pull postgres
docker pull dockersamples/visualizer:stable
docker pull elasticsearch:5.4.3
docker pull kibana:5.4.3
docker pull logstash:5.4.3
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
/server directories and read the
Tools we use
- When install the project with docker, there is an
entrypoint.shscript that runs in the
servercontainer. It'll migrate the database and create a new super user with a username
adminand a password
- 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
- 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
npm run lint npm run test
To run the
server tests and lint run the commands below in the
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
To do a load test just install locust (it's in the
requirements.txt file) go to
server directory and run
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
volumes section of the
Just fork and do a pull request (;