forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshConnect.js
More file actions
44 lines (32 loc) · 1.12 KB
/
sshConnect.js
File metadata and controls
44 lines (32 loc) · 1.12 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
var Client = require('ssh2').Client;
var readHostFromSSHConfig = require('../lib/readHostFromSSHConfig');
var config = require('config');
var gutil = require('gulp-util');
var sshExec = require('./sshExec');
module.exports = function*(host) {
var client = new Client();
var sshHostConfig = yield* readHostFromSSHConfig(host);
var host = sshHostConfig ? sshHostConfig.HostName : host;
var options = {
privateKey: config.deploy.privateKey,
user: config.deploy.user,
host: host,
// must forward agent to push from remote host to the "more remote" git repo
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
};
client.connect(options);
yield function(callback) {
client.on('ready', callback);
};
client.runInBuild = function(cmd, options) {
return sshExec(client, `cd ${config.deploy.buildPath}; ${cmd}`, options);
};
client.run = function(cmd, options) {
return sshExec(client, cmd, options);
};
client.runInTarget = function(cmd, options) {
return sshExec(client, `cd ${config.deploy.targetPath}; ${cmd}`, options);
};
return client;
};