-
Notifications
You must be signed in to change notification settings - Fork 2
/
flightplan.js
72 lines (63 loc) · 1.82 KB
/
flightplan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var plan = require('flightplan');
var appName = 'market';
var username = 'vagrant';
var password = 'vagrant';
var startFile = 'server/server.js';
var tmpDir = appName+'-' + new Date().getTime();
// configuration
plan.target('staging', [
{
host: '55.55.55.2',
username: username,
password: password,
agent: process.env.SSH_AUTH_SOCK
}
]);
plan.target('production', [
{
host: '55.55.55.2',
username: username,
password: password,
agent: process.env.SSH_AUTH_SOCK
},
{
host: '55.55.55.3',
username: username,
password: password,
agent: process.env.SSH_AUTH_SOCK
},
{
host: '55.55.55.4',
username: username,
password: password,
agent: process.env.SSH_AUTH_SOCK
}
//add in another server if you have more than one
// {
// host: '104.131.93.216',
// username: username,
// agent: process.env.SSH_AUTH_SOCK
// }
]);
// run commands on localhost
plan.local(function(local) {
// uncomment these if you need to run a build on your machine first
// local.log('Run build');
local.exec('git add -f bower_components');
local.log('Copy files to remote hosts');
var filesToCopy = local.exec('git ls-files', {silent: true});
// rsync files to all the destination's hosts
local.transfer(filesToCopy, '/tmp/' + tmpDir);
local.exec('git rm -rf --cached bower_components');
});
// run commands on remote hosts (destinations)
plan.remote(function(remote) {
remote.log('Move folder to root');
remote.sudo('cp -R /tmp/' + tmpDir + ' ~', {user: username});
remote.rm('-rf /tmp/' + tmpDir);
remote.log('Install dependencies');
remote.sudo('npm --production --prefix ~/' + tmpDir + ' install ~/' + tmpDir, {user: username});
remote.log('Reload application');
remote.sudo('ln -snf ~/' + tmpDir + ' ~/'+appName, {user: username});
remote.exec('sudo restart market');
});