Awesome Open Source
Awesome Open Source

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 contain an Angular app, built with Angular-Cli, and ngrx to handle state, Angular Material as a design library, and have service worker, and AOT compiled. The app shows the users from the Sanic api.
  • The server contain a simple Sanic app that expose an api of users. The Python serve through a gunicorn server installed in the container.
  • There is a postgres service for the database. The database directory contains the automatic backup script.
  • All the logs are going to stdout and can be collected through any service.
  • There are built in test that configured to run on travis-ci, and a code coverage analysis via codecov.

The client app is built via the cloud build CI on GCP and deployed to the GCP storage. The server app is built via the cloud build CI as a docker image and deployed to a GKE cluster on GCP (managed by Kubernetes). The PostgreSQL database is built via the cloud build CI as a docker image and deployed to a GKE cluster on GCP (managed by Kubernetes).

Production Installation

Deploy the client app:

  1. Create a storage bucket with the name of the Domain you have.
  2. Create a cloud build trigger with the parameters in the screenshot (change the _REGION_NAME to the location of the bucket you created in the previous step).
  3. Now you can deploy your client app by creating a new tag in the v0.0.1/prod/prod format and push it to github (git push --tags).

Deploy the server app:

  1. Create a GKE cluster on GCP.
  2. Create a cloud build trigger with the parameters in the screenshot (change the _REGION_NAME to the location of the GKE cluster you created in step 1).
  3. Connect to the GKE cluster using gcloud container clusters get-credentials prod and then create a tiler using the commands:
  4. kubectl create serviceaccount --namespace kube-system tiller
  5. kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
  6. kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
  7. helm init --service-account tiller --upgrade
  8. Then change the helm permissions by navigate to server/kubernetes in the command line and then write kubectl apply -f helm-permissions.yaml.
  9. Now you can deploy your server app by create a new tag in the v0.0.1/prod/prod format and push it to github (git push --tags).

Create a Cloud DNS record:

  1. Create a Cloud DNS record on GCP. In this record you should add an A record to the kubernetes cluster (the server) and place there your load balancer ip address you get in the "Deploy the server app", and a CNAME record to our Storage bucket (client app) screenshot.

Our Stack

Tools we use

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 Locusts 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 (;


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (1,120,145
Docker (33,824
Angular (12,589
Django (12,536
Postgresql (7,684
Containers (3,167
Test (2,681
Restful Api (2,518
Angular Cli (1,184
Best Practices (882
Docker Swarm (541
Seed (514
Ngrx (497
Project Template (314
Elk Stack (223
Related Projects