GithubHelp home page GithubHelp logo

shahar84 / angular-django-seed-project Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nirgn975/angular-sanic-seed-project

0.0 2.0 0.0 331 KB

:gem: An opinionated Angular - Django RESTful seed

License: Other

TypeScript 41.07% JavaScript 3.20% Nginx 1.64% HTML 1.70% CSS 2.48% Shell 31.77% Python 18.14%

angular-django-seed-project's Introduction

license GitHub release Build Status codecov Dependency Status Codacy Badge Maintenance Donate

This repo is a production ready seed project. The app shows a list of users.

Structure

  • The client service is a build of the client directory. It contain an Angular app, built with Angular-Cli, ngrx to handle state, Angular Material as a design library, have service worker, and AOT compiled. The app shows the users from the Django api.
  • The server service is a build of the server directory. It contain a simple Django app that expose an api of Django users with Django REST framework. The Python serve through a gunicorn server installed in the container.
  • There is a postgres service for the Django database. The database 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 the client 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.

Pre Requirements

  1. install docker.

Installation

Automatic installation of the project with docker.

  1. In client directory run docker build -t client . to build the Docker image.
  2. In server directory run docker build -t server . to build the Docker image.
  3. To create a swarm docker swarm init.
  4. 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
  5. Run docker stack deploy --compose-file=docker-compose.yml prod
  6. Open the browser at http://localhost to see your Angular (client) app.
  7. Open the browser at http://localhost:8000 to see your Django (server) app.
  8. Open the browser at http://localhost:8080 to see the visualizer.
  9. 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.

Our Stack

Tools we use

Django Admin

  • When install the project with docker, there is an entrypoint.sh script that runs in the server container. It'll migrate the database and create a new super user with a username admin and a password pass.
  • 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.

Tests

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

Load Tests

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.

Rolling Updates

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

Database Backups

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.

Contribute

Just fork and do a pull request (;

angular-django-seed-project's People

Contributors

pyup-bot avatar

Watchers

James Cloos avatar Shahar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.