This repo is a production ready seed project. The app shows a list of users.
This fork differs from its parent by:
- Re-adding Dockerfiles
- The
client
service is a build of theclient
directory. It contain an Angular app, built with Angular-Cli, ngrx to handle state, Angular Material as a design library, have service worker, andAOT
compiled. The app shows the users from the Django api. - The
server
service is a build of theserver
directory. It contain a simple Django app that expose anapi
of Djangousers
with Django REST framework. The Python serve through a gunicorn server installed in the container. - There is a
postgres
service for the Django database. Thedatabase
directory contains the automatic backup script. - There is an
nginx
service to serve static files (the client app). - There is an
haproxy
service 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
server
and theclient
logs sent to logstash, and saved in elasticsearch. There is also a kibana instance to check and analyze all the logs. - There is a
visualizer
container 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
win
ormac
please comment the lines of thedatabase -> volumes
indocker-compose.yml
, this share volume withlinux
system only. - In
client
directory rundocker build -t client .
to build the Docker image. - In
server
directory rundocker 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
- 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.sh
script that runs in theserver
container. It'll migrate the database and create a new super user with a usernameadmin
and 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 (;