Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 8849889

Browse files
authored
Backup PostgreSQL automatically (#69)
* Lower postgres restart policy * Add a backup script to postgres db to run in cron.daily * Add an option to login to api view * Fix server test * Add Database Backups section to README * Edit README file * Edit README file take 2 * Try different indentation * Fix tests take 1 * Fix tests teke 2
1 parent 19a6101 commit 8849889

File tree

11 files changed

+549
-26
lines changed

11 files changed

+549
-26
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ script:
3939
# Client
4040
- cd ../client && npm run lint
4141
- npm run test
42-
- ng build --prod --aot
42+
- npm run build -- --prod
4343
- cd dist && ws --port 4200&
4444
- npm run e2e
4545

README.md

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
# An opinionated Angular - Django RESTful cluster
1+
# An Angular - Django Project Seed
22

33
[![license][license-image]][license-url] [![Build Status][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url] [![Dependency Status][dependencyci-image]][dependencyci-url] [![Donate][donate-image]][donate-url]
44

5-
The `server` directory 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 `client` directory contain an [Angular](https://angular.io/) simple 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 ready to `AOT` compilation. The simple Angular app show the users from the Django api.
5+
This repo is a production ready seed project. The app shows a list of users.
66

7-
The repo is a production ready app, that uses `nginx` to serve static files (the client app and static files from the server), and `gunicorn` for the server (python) stuff. 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.
7+
## Structure
88

9-
We use [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.
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.
1018

1119
## Pre Requirements
1220

@@ -19,10 +27,18 @@ Automatic installation of the project with docker, for development.
1927
1. In `client` directory run `docker build -t client .` to build the Docker image.
2028
2. In `server` directory run `docker build -t server .` to build the Docker image.
2129
3. To create a swarm `docker swarm init`.
22-
4. Run `docker stack deploy --compose-file=docker-compose.yml prod`
23-
5. Open the browser at [http://localhost](http://localhost) to see your Angular (client) app.
24-
6. Open the browser at [http://localhost:8000](http://localhost:8000) to see your Django (server) app.
25-
7. Open the browser at [http://localhost:5601](http://localhost:5601) to see Kibana and check your logs.
30+
4. Download all docker images:
31+
* `docker pull dockercloud/haproxy`
32+
* `docker pull postgres`
33+
* `docker pull dockersamples/visualizer:stable`
34+
* `docker pull elasticsearch:5.4.3`
35+
* `docker pull kibana:5.4.3`
36+
* `docker pull logstash:5.4.3`
37+
5. Run `docker stack deploy --compose-file=docker-compose.yml prod`
38+
6. Open the browser at [http://localhost](http://localhost) to see your Angular (client) app.
39+
7. Open the browser at [http://localhost:8000](http://localhost:8000) to see your Django (server) app.
40+
8. Open the browser at [http://localhost:8080](http://localhost:8080) to see the visualizer.
41+
9. Open the browser at [http://localhost:5601](http://localhost:5601) to see Kibana and check your logs.
2642

2743
**If you want to install the project manually, go to the `/client` or `/server` directories and read the `README` file.**
2844

@@ -52,7 +68,25 @@ Automatic installation of the project with docker, for development.
5268

5369
There is already tests for the `server` and the `client`, we currently at **+90** percent coverage.
5470

55-
We also write some tests for doing load test with [locust](http://locust.io/), 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
71+
To run the `client` tests and lint run the commands below in the `client` directory.
72+
73+
```
74+
npm run lint
75+
npm run test
76+
```
77+
78+
To run the `server` tests and lint run the commands below in the `server` directory.
79+
80+
```
81+
pycodestyle --show-source --max-line-length=120 --show-pep8 .;
82+
python manage.py test
83+
```
84+
85+
## Load Tests
86+
87+
We also write some tests for doing load test with [locust](http://locust.io/), you can find it under `server/locustfile.py`.
88+
89+
To do a load test just install locust (it's in the `requirements.txt` file) go to `server` directory and run
5690

5791
```
5892
locust --host=http://localhost
@@ -74,6 +108,16 @@ And then update the service with the new image
74108
docker service update --image server:v2 prod_server
75109
```
76110

111+
## Database Backups
112+
113+
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.
114+
115+
Each Saturday morning a weekly backup will be created at the weekly directory. The weekly backups are rotated on a 5 week cycle.
116+
117+
Each month at the 1st of the month a monthly backup will be created at the monthly directory. Monthly backups are **NOT** rotated
118+
119+
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.
120+
77121
## Contribute
78122

79123
Just fork and do a pull request (;

client/.angular-cli.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@
3636
},
3737
"lint": [
3838
{
39-
"project": "src/tsconfig.app.json"
39+
"project": "src/tsconfig.app.json",
40+
"exclude": "**/node_modules/**"
4041
},
4142
{
42-
"project": "src/tsconfig.spec.json"
43+
"project": "src/tsconfig.spec.json",
44+
"exclude": "**/node_modules/**"
4345
},
4446
{
45-
"project": "e2e/tsconfig.e2e.json"
47+
"project": "e2e/tsconfig.e2e.json",
48+
"exclude": "**/node_modules/**"
4649
}
4750
],
4851
"test": {

client/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8.1.2
1+
FROM node:8.2.1
22
MAINTAINER Nir Galon <[email protected]>
33

44
# Install nginx

client/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"private": false,
1515
"dependencies": {
16-
"@angular/animations": "^4.3.0",
16+
"@angular/animations": "^4.0.0",
1717
"@angular/common": "^4.0.0",
1818
"@angular/compiler": "^4.0.0",
1919
"@angular/core": "^4.0.0",
@@ -29,12 +29,12 @@
2929
"core-js": "^2.4.1",
3030
"hammerjs": "^2.0.8",
3131
"reselect": "^3.0.1",
32-
"rxjs": "^5.1.0",
33-
"zone.js": "^0.8.4"
32+
"rxjs": "^5.4.1",
33+
"zone.js": "^0.8.14"
3434
},
3535
"devDependencies": {
3636
"@angular/cdk": "^2.0.0-beta.8",
37-
"@angular/cli": "1.2.1",
37+
"@angular/cli": "1.2.6",
3838
"@angular/compiler-cli": "^4.0.0",
3939
"@angular/language-service": "^4.0.0",
4040
"@ngrx/store-devtools": "^3.2.4",

client/src/app/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'hammerjs';
22

33
import { BrowserModule } from '@angular/platform-browser';
44
import { NgModule } from '@angular/core';
5-
import { FormsModule } from '@angular/forms';
65
import { HttpModule } from '@angular/http';
76
import { StoreModule } from '@ngrx/store';
87
import { EffectsModule } from '@ngrx/effects';
@@ -27,7 +26,6 @@ import { UserService } from './services/user.service';
2726
],
2827
imports: [
2928
BrowserModule,
30-
FormsModule,
3129
HttpModule,
3230
AppRoutingModule,
3331
MaterialModule,

0 commit comments

Comments
 (0)