-
Notifications
You must be signed in to change notification settings - Fork 9
/
deploy.js
96 lines (80 loc) · 3 KB
/
deploy.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function() {
var logger = console;
this.init = function(customLogger)
{
logger = customLogger;
}
this.run = function(params, done)
{
logger.info("======================================================================");
logger.info("Running job " + __dirname);
logger.info("======================================================================");
logger.debug(params);
var exec = require('child_process').exec;
var commands = [
"rvm use 2.3.1",
"rm -Rf " + __dirname + "/data/resources/*",
"bundle install",
"bundle exec middleman resources",
"bundle exec middleman build",
"rm -Rf " + __dirname + "/live",
"mv " + __dirname + "/build " + __dirname + "/live"
];
var environment = process.env;
// Deploy to github pages if this is the production branch, otherwise
// just compile it locally
if (params.branch == "production" || params.branch == "community")
{
environment.KO_QA = "false";
}
else
{
environment.KO_QA = "true";
}
environment.PATH = "/home/nathanr/.rvm/gems/ruby-2.3.1/bin:/home/nathanr/.rvm/gems/ruby-2.3.1@global/bin:/home/nathanr/.rvm/rubies/ruby-2.3.1/bin:/home/nathanr/.rvm/bin:/home/nathanr/.nvm/v0.10.25/bin:" + environment.PATH;
environment.GEM_HOME = "/home/nathanr/.rvm/gems/ruby-2.3.1";
environment.GEM_PATH = "/home/nathanr/.rvm/gems/ruby-2.3.1:/home/nathanr/.rvm/gems/ruby-2.3.1@global";
var envVars = require(__dirname + "/../komodo-website-" + params.branch + ".env.js");
for (var env in envVars)
{
environment[env] = envVars[env];
}
var runCommand = function(index)
{
if ( ! (index in commands)) return done();
var command = commands[index];
logger.info("Executing " + command);
exec(command, {
maxBuffer: 1000*1024,
env: environment,
cwd: __dirname
},
function(err, stdo, stde)
{
if (err) return done(err);
logger.debug("Result: " + stdo + stde + "\n");
runCommand(++index);
});
}
runCommand(0);
};
this.schedule = function(branch, cron, deploy)
{
logger.info("Scheduling deployment for " + __dirname + " : " + branch);
var doDeploy = function()
{
deploy({
name: 'komodo-website-' + branch,
path: __dirname,
repository: 'komodo-website',
branch: branch
});
};
// Deploy latest version every 3 hours
new cron('0 */3 * * *', function(){
logger.info('Running scheduled deploy for ' + __dirname);
doDeploy();
}, null, true);
doDeploy();
};
}).apply(module.exports);