|
1 |
| -<img src="https://raw.githubusercontent.com/nirgn975/Angular-Django-Seed-Project/master/angular-django-seed-project.png" /> |
| 1 | +<img src="https://raw.githubusercontent.com/nirgn975/Angular-Django-Seed-Project/master/art/angular-django-seed-project.png" /> |
2 | 2 |
|
3 | 3 | [![license][license-image]][license-url] [![GitHub release][github-image]][github-url] [![Build Status][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url] [![Dependency Status][dependencyci-image]][dependencyci-url] [![Codacy Badge][codacy-image]][codacy-url] [![Maintenance][maintenance-image]][maintenance-url] [![Donate][donate-image]][donate-url]
|
4 | 4 |
|
5 | 5 | This repo is a production ready seed project. The app shows a list of users.
|
6 | 6 |
|
7 | 7 | ## Structure
|
8 | 8 |
|
9 |
| -* The `client` service is a build of the `client` directory. It contain an [Angular](https://angular.io/) app, built with [Angular-Cli](https://github.com/angular/angular-cli), [ngrx](https://github.com/ngrx) to handle state, [Angular Material](https://github.com/angular/material2) as a design library, have service worker, and `AOT` compiled. The app shows the users from the Django api. |
10 |
| -* The `server` service is a build of the `server` directory. It contain a simple [Django](https://www.djangoproject.com/) app that expose an `api` of Django `users` with [Django REST framework](http://www.django-rest-framework.org/). The Python serve through a [gunicorn](http://gunicorn.org/) server installed in the container. |
11 |
| -* There is a `postgres` service for the Django database. The `database` directory contains the automatic backup script. |
12 |
| -* There is an `nginx` service to serve static files (the client app). |
13 |
| -* There is an `haproxy` service to get all the HTTP requests and do load balancing between the containers in the services. |
14 |
| -* There are a separate containers for the [ELK Stack](https://www.elastic.co/products) 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. |
15 |
| -* There is a `visualizer` container to visualize where is each container is located at (on which server). |
16 |
| - |
17 |
| -All the parts are in a separate [Docker](https://www.docker.com/) containers and we use [Docker Swarm](https://docs.docker.com/engine/swarm/) to manage them. |
18 |
| - |
19 |
| -## Pre Requirements |
20 |
| - |
21 |
| -1. install [docker](https://www.docker.com/). |
22 |
| - |
23 |
| -## Installation |
24 |
| - |
25 |
| -Automatic installation of the project with docker. |
26 |
| - |
27 |
| -0. If you work on `win` or `mac` please comment the lines of the `database -> volumes` in `docker-compose.yml`, this share volume with `linux` system only. |
28 |
| -1. In `client` directory run `docker build -t client .` to build the Docker image. |
29 |
| -2. In `server` directory run `docker build -t server .` to build the Docker image. |
30 |
| -3. To create a swarm `docker swarm init`. |
31 |
| -4. Download all docker images: |
32 |
| - * `docker pull dockercloud/haproxy` |
33 |
| - * `docker pull postgres` |
34 |
| - * `docker pull dockersamples/visualizer:stable` |
35 |
| - * `docker pull elasticsearch:5.4.3` |
36 |
| - * `docker pull kibana:5.4.3` |
37 |
| - * `docker pull logstash:5.4.3` |
38 |
| -5. Run `docker stack deploy --compose-file=docker-compose.yml prod` |
39 |
| -6. Open the browser at [http://localhost](http://localhost) to see your Angular (client) app. |
40 |
| -7. Open the browser at [http://localhost:8000](http://localhost:8000) to see your Django (server) app. |
41 |
| -8. Open the browser at [http://localhost:8080](http://localhost:8080) to see the visualizer. |
42 |
| -9. Open the browser at [http://localhost:5601](http://localhost:5601) to see Kibana and check your logs. |
43 |
| - |
44 |
| -**If you want to install the project manually, go to the `/client` or `/server` directories and read the `README` file.** |
| 9 | +* The `client` contain an [Angular](https://angular.io/) app, built with [Angular-Cli](https://github.com/angular/angular-cli), and [ngrx](https://github.com/ngrx) to handle state, [Angular Material](https://github.com/angular/material2) as a design library, and have service worker, and `AOT` compiled. The app shows the users from the Sanic api. |
| 10 | +* The `server` contain a simple [Sanic](https://sanic.readthedocs.io) app that expose an `api` of `users`. The Python serve through a [gunicorn](http://gunicorn.org/) server installed in the container. |
| 11 | +* There is a `postgres` service for the database. The `database` directory contains the automatic backup script. |
| 12 | +* All the logs are going to `stdout` and can be collected through any service. |
| 13 | +* There are built in test that configured to run on `travis-ci`, and a code coverage analysis via `codecov`. |
| 14 | + |
| 15 | +The `client` app is built via the cloud build CI on GCP and deployed to the GCP `storage`. |
| 16 | +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). |
| 17 | +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). |
| 18 | + |
| 19 | +## Production Installation |
| 20 | + |
| 21 | +Deploy the `client` app: |
| 22 | +1. Create a storage bucket with the name of the Domain you have. |
| 23 | +2. Create a cloud build trigger with the parameters in the [screenshot](art/client-trigger.jpg) (change the `_REGION_NAME` to the location of the bucket you created in the previous step). |
| 24 | +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`). |
| 25 | + |
| 26 | +Deploy the `server` app: |
| 27 | +1. Create a `GKE` cluster on GCP. |
| 28 | +2. Create a cloud build trigger with the parameters in the [screenshot](art/servier-trigger.jpg) (change the `_REGION_NAME` to the location of the `GKE` cluster you created in step 1). |
| 29 | +3. Connect to the `GKE` cluster using `gcloud container clusters get-credentials prod` and then create a `tiler` using the commands: |
| 30 | + 1. `kubectl create serviceaccount --namespace kube-system tiller` |
| 31 | + 2. `kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller` |
| 32 | + 3. `kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'` |
| 33 | + 4. `helm init --service-account tiller --upgrade` |
| 34 | +4. Then change the `helm` permissions by navigate to `server/kubernetes` in the command line and then write `kubectl apply -f helm-permissions.yaml`. |
| 35 | +5. 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`). |
| 36 | + |
| 37 | +Create a Cloud DNS record: |
| 38 | +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](art/cloud_dns.jpg). |
45 | 39 |
|
46 | 40 | ## Our Stack
|
47 | 41 |
|
48 | 42 | * [Angular](https://angular.io/)
|
49 |
| -* [Django](https://www.djangoproject.com/) |
50 |
| -* [PostgreSQL](http://www.postgresql.org/) |
| 43 | +* [Sanic](https://www.djangoproject.com/) |
| 44 | +* [PostgreSQL](https://sanic.readthedocs.io) |
51 | 45 | * [Docker](https://www.docker.com/)
|
52 | 46 |
|
53 | 47 | **Tools we use**
|
54 | 48 |
|
55 |
| - * [Angular Material](https://material.angular.io/) |
| 49 | + * [Angular Material](https://material.angular.io) |
56 | 50 | * [ngrx](https://github.com/ngrx)
|
57 |
| - * [Django REST framework](http://www.django-rest-framework.org/) |
58 |
| - * [django-admin-honeypot](http://django-admin-honeypot.readthedocs.io/en/latest/) |
59 |
| - * [ELK Stack](https://www.elastic.co/products) |
60 |
| - * [Docker Swarm](https://docs.docker.com/engine/swarm/) |
61 |
| - |
62 |
| -## Django Admin |
63 |
| - |
64 |
| - * 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`. |
65 |
| - * We use [django-admin-honeypot](https://github.com/dmpayton/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`. |
66 |
| - * We also use [django-flat-responsive](https://github.com/elky/django-flat-responsive) to make the Django admin screens responsive to mobile. |
| 51 | + * [Peewee](http://docs.peewee-orm.com) |
| 52 | + * [Kubernetes](https://kubernetes.io) |
| 53 | + * [Travis-CI](https://travis-ci.org) |
| 54 | + * [Codecov](https://codecov.io) |
67 | 55 |
|
68 | 56 | ## Tests
|
69 | 57 |
|
@@ -135,7 +123,7 @@ Just fork and do a pull request (;
|
135 | 123 | [dependencyci-url]: https://dependencyci.com/github/nirgn975/Angular-Django-Seed-Project
|
136 | 124 | [codacy-image]: https://api.codacy.com/project/badge/Grade/cdf4939e98804872b377a4120a4f4571
|
137 | 125 | [codacy-url]: https://www.codacy.com/app/nirgn975/Angular-Django-Seed-Project?utm_source=github.com&utm_medium=referral&utm_content=nirgn975/Angular-Django-Seed-Project&utm_campaign=Badge_Grade
|
138 |
| -[maintenance-image]: https://img.shields.io/maintenance/yes/2017.svg |
| 126 | +[maintenance-image]: https://img.shields.io/maintenance/yes/2019.svg |
139 | 127 | [maintenance-url]: https://github.com/nirgn975
|
140 | 128 | [donate-image]: https://img.shields.io/badge/PayPal-Donate-lightgrey.svg
|
141 | 129 | [donate-url]: https://www.paypal.me/nirgn/2
|
0 commit comments