Skip to content

Commit

Permalink
Merge pull request #188 from vallettea/alpha
Browse files Browse the repository at this point in the history
removed docker 🐳 🔫
  • Loading branch information
SergeBredin committed Jan 19, 2016
2 parents 1392003 + 0531c01 commit 94dc4d6
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 219 deletions.
5 changes: 4 additions & 1 deletion PRIVATE.json.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"secret": "fake"
"secret": "fake",
"pg_user": "postgres",
"pg_pwd": "toto",
"db_name": "element"
}
33 changes: 9 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,35 @@
### Dependencies

Install:
* Docker
* Node.js
* Postgresql

the use `npm install` to install all the dependencies.
Create a `Tokens.json` following the [example](Tokens.example.json)
Create a `PRIVATE.json` following the [example](PRIVATE.example.json)



### Initialize the database

There are two way of loading the places in the db.

#### Load with files

Put your datafiles in `data`, then do:
You should init your db with:

```
npm run serve-dev
# then in another window
docker exec 6elementdev_api_1 tools/init-database.js
docker exec 6elementdev_api_1 tools/loadFiles.js
alter user postgres password 'toto';
CREATE DATABASE element;
```

in production you can use `npm run prod` and change the names of the containers in the exec commands.

#### Load from a backup

In dev, `./backups` is linked to `/backups` and in prod, `/data/6element/backups` is linked to `/backups` where automatic backups (at 3AM) are persisted.
At anytime you can backup the db using
and

```
docker exec 6elementdev_api_1 tools/backup.js > backups/test.sql
tools/init-database.js
```

to load it back **you must put it in your backups folder and give the path inside the container**:
you can always use `psql` separately to load and dump data:

```
docker exec 6elementdev_api_1 tools/restore.js /backups/test.sql
psql -p5432 -U postgres -d element < Desktop/latest.sql
```

you can also use a gziped file (comming from the automated backup for example).


### Running the app

#### Daily routine in dev
Expand Down
29 changes: 0 additions & 29 deletions compose-alpha.yml

This file was deleted.

28 changes: 0 additions & 28 deletions compose-dev.yml

This file was deleted.

27 changes: 0 additions & 27 deletions compose-prod.yml

This file was deleted.

15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
"lint": "eslint .",
"watch": "babel client/views/*.jsx --out-dir . --watch",
"build": "babel client/views/*.jsx --out-dir .",
"stop-dev": "docker-compose -p dev6element -f compose-dev.yml stop",
"stop-alpha": "docker-compose -p alpha6element -f compose-alpha.yml stop",
"stop-prod": "docker-compose -f compose-prod.yml stop",
"prod": "docker-compose -f compose-prod.yml up -d --force-recreate",
"prod": "node server/index.js",
"preprod": "npm run build",
"alpha": "docker-compose -p alpha6element -f compose-alpha.yml up -d --force-recreate",
"prealpha": "npm run build",
"serve-dev": "docker-compose -p dev6element -f compose-dev.yml up --force-recreate",
"dev": "npm-run-all --parallel serve-dev watch",
"monitor": "nodemon -L --watch server --watch client/*.js server/index.js",
"dev": "npm-run-all --parallel serve-dev watch monitor",
"validate": "npm ls"
},
"babel": {
Expand Down Expand Up @@ -48,15 +43,12 @@
"core-js": "^1.2.1",
"es6-shim": "^0.31.3",
"express": "^4.12.4",
"geolib": "^2.0.18",
"jsdom": "^7.0.2",
"moment": "^2.11.1",
"moment-timezone": "^0.5.0",
"node-schedule": "^0.6.0",
"opening_hours": "^3.3.0",
"pg": "^4.4.2",
"pg-hstore": "^2.3.2",
"proj4": "^2.3.10",
"query-string": "^3.0.0",
"react": "0.14.5",
"react-dom": "0.14.5",
Expand All @@ -72,6 +64,7 @@
"babel-preset-react": "^6.1.18",
"eslint": "^1.3.1",
"eslint-plugin-react": "^3.15.0",
"nodemon": "^1.8.1",
"npm-run-all": "^1.3.4",
"reactify": "^1.1.1",
"watchify": "^3.2.1"
Expand Down
16 changes: 6 additions & 10 deletions server/database/management/connectToDB.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
'use strict';

var pg = require('pg');
var PRIVATE = require('../../../PRIVATE.json');

var conString = [
'postgres://',
process.env.POSTGRES_USER,
':',
process.env.POSTGRES_PASSWORD,
'@db/postgres'
].join('');

console.log('conString', conString);
var conString = 'postgres://'+ PRIVATE.pg_user + ':' + PRIVATE.pg_pwd + '@localhost:5432/' + PRIVATE.db_name;

var MAX_ATTEMPTS = 10;
var INITIAL_TIMEOUT_TIME = 100;
Expand All @@ -27,11 +20,14 @@ module.exports = function(){

client.connect(function(err) {
if(err){
console.log("Couldn't connect to db");
if(attempts >= MAX_ATTEMPTS)
reject(err);
else
else {
// wait twice more to give time and not overwhelm the database with useless attempts to connect
console.log("Retrying in ", 2*time);
tryConnect(2*time);
}
}
else{
resolve(client);
Expand Down
24 changes: 0 additions & 24 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ var path = require('path');

var PRIVATE = require('../PRIVATE.json');

// Dumps
var spawn = require('child_process').spawn;
var zlib = require('zlib');
var schedule = require('node-schedule');

// Express
var express = require('express');
var bodyParser = require('body-parser');
Expand Down Expand Up @@ -41,25 +36,6 @@ app.use(bodyParser.urlencoded({extended: true}));
app.use(compression());


// ---------- BACKUPS ----------
// Backup database everyday at 3AM
if (process.env.NODE_ENV === "production") {
schedule.scheduleJob('0 3 * * *', function(){
console.log('Backup database');
var gzip = zlib.createGzip();
var today = new Date();
var wstream = fs.createWriteStream('/backups/' + today.getDay() + '.sql.gz');
var proc = spawn('pg_dump', ['-p', process.env.DB_PORT_5432_TCP_PORT, '-h', process.env.DB_PORT_5432_TCP_ADDR, '-U', process.env.POSTGRES_USER, '-w']);
proc.stdout
.pipe(gzip)
.pipe(wstream);
proc.stderr.on('data', function(buffer) {
console.log(buffer.toString().replace('\n', ''));
});
});
}


// ---------- SOCKETS ----------
// Frontside sockets to activate
//var io6element = require('socket.io')(server);
Expand Down
7 changes: 0 additions & 7 deletions tools/backup.js

This file was deleted.

58 changes: 0 additions & 58 deletions tools/restore.js

This file was deleted.

0 comments on commit 94dc4d6

Please sign in to comment.