Repository navigation
Expand file tree
/
Copy pathdeploy.js
More file actions
55 lines (50 loc) · 1.67 KB
/
Copy pathdeploy.js
File metadata and controls
55 lines (50 loc) · 1.67 KB
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
"use strict";
const util = require('util');
const exec = util.promisify(require('child_process').exec);
var Client = require('ssh2').Client;
var conn = new Client();
var config = JSON.parse(require('fs').readFileSync('config.json'));
const args = process.argv.slice(2);
var serverFile = config['serverFile'];
if (args.length == 1){
serverFile = args[0];
if (serverFile.substr(serverFile.length - 3) !== '.js'){
serverFile = serverFile + '.js';
}
}
function sshIn(){
conn.on('ready', function() {
console.log('Launching App using ' + serverFile);
conn.exec('pkill -SIGINT -f "node .*.js" && echo Public Address: http://$(curl http://checkip.amazonaws.com):5000 && node ' + serverFile, function(err, stream){
if (err) throw err
stream.on('close', function(code, signal) {
console.log('Connection closed');
conn.end();
}).on('data', function(data) {
console.log(data.toString());
if(!data.toString().includes("Public Address:")){
conn.end();
}
}).stderr.on('data', function(data) {
if (data !== ''){
//console.log('ERROR: ' + data);
}
});
});
}).connect({
host: config['ec2instance'],
port: 22,
username: config['ec2user'],
privateKey: require('fs').readFileSync(config['ec2keyfile'])
});
}
async function rsync() {
const { stdout, stderr } = await exec('rsync -av -e "ssh -i ' + config['ec2keyfile'] + '" --exclude "node_modules/" . ' + config['ec2user'] + '@' + config['ec2instance'] + ':~/');
if (stderr !== ''){
console.log('Error:', stderr);
} else {
console.log('Successfully deployed to ' + config['ec2instance']);
sshIn();
}
}
rsync();