-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdeploy.js
More file actions
53 lines (50 loc) · 1.71 KB
/
deploy.js
File metadata and controls
53 lines (50 loc) · 1.71 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
var Promise = require('bluebird');
var fs = require('fs');
var _ = require('lodash');
var keys = require('./keys');
var bundler = require('./bundler');
var remotely = require('./remotely')
var getConnectionOptions = function(config, callback) {
keys.getPrivateKey(config.privateKey, function(err, res) {
if (err) return callback(err);
else if (_.isArray(config.hosts) && config.hosts.length > 0) {
return callback(null, _.map(config.hosts, function(host) {
return {
host: host,
port: 22,
username: config.user,
privateKey: res
}
}));
} else callback(new Error("Must provide one or more hosts"));
})
}
module.exports = {
configure: function(config, done) {
return function(context, done) {
getConnectionOptions(config, function(err, hosts) {
if (err) return done(err);
var projectName = context.job.project.name.replace('/', '_');
bundler.bundleProject(context.dataDir, projectName, function(tar) {
context.comment("Compressing ... "+Math.round(tar.percentage)+"%")
}, function(err, bundlePath) {
if (err) {
return done(new Error("Could not create bundle "+bundlePath))
} else {
var promises = _.map(hosts, function(sshOpts) {
return remotely.deploy(
context.out, projectName, bundlePath, config.script, sshOpts,
function(sftp) { context.comment("Uploading ... "+Math.round(sftp.percentage)+"%") }
)
});
Promise.all(promises).then(function() {
done(0);
}).catch(function(err) {
done(err);
})
}
})
})
}
}
}