forked from saltastro/tacprocess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flightplan.js
57 lines (49 loc) · 1.51 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
/* eslint-disable */
var plan = require('flightplan');
var appName = 'tacweb'; // the folder app is deployed to
var username = 'tacweb';
var startFile = '/';
var hostname = 'hostname'
var tmpDir = appName+'-' + new Date().getTime();
// configuration
plan.target('staging', [
{
host: hostname,
username: username,
agent: process.env.SSH_AUTH_SOCK
}
]);
plan.target('production', [
{
host: hostname,
username: username,
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('gulp build');
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);
});
// 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.sudo('restart tacweb');
});