forked from snodgrass23/base12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision
executable file
·95 lines (76 loc) · 2.07 KB
/
provision
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
#!/usr/bin/env node
var cmd = require('commander');
var async = require('async');
var config, constants, env_file, pkg_file, host, script, remote;
init();
function safe_json(file) {
var result;
try {
result = require(file);
return result;
}
catch(e) {
console.warn("Unable to require '" + file + "'");
return;
}
}
function section(name) {
console.log('\n=== ' + name + ' ===');
}
function command() {
cmd
.version('0.0.2')
.usage('provision <environment> <host> [name]');
cmd.on('--help', function(){
console.log(' Examples:');
console.log('');
console.log(' $ scripts/provision config/prod.db.env.json 1.2.3.4');
console.log(' $ scripts/provision config/prod.web.env.json 1.2.3.5 web1');
console.log(' $ scripts/provision config/prod.web.env.json 1.2.3.6 web2');
console.log(' $ scripts/provision config/prod.media.env.json 1.2.3.7 media1');
console.log('');
});
cmd.parse(process.argv);
if (cmd.args.length < 2) {
console.warn("Environment and host are required.");
process.exit();
}
}
function init() {
command();
env_file = process.cwd() + '/' + cmd.args[0];
pkg_file = process.cwd() + '/package.json';
host = cmd.args[1];
remote = cmd.args[2];
console.log('\nProvisioning ' + host );
console.log('Using ' + env_file + ' and ' + pkg_file);
config = safe_json(env_file);
if (!config) {
console.warn("Environment file required");
process.exit();
}
var pkg = safe_json(pkg_file);
if (!pkg) {
console.warn("Package file required");
process.exit();
}
constants = pkg.constants;
constants.name = pkg.name;
var options = {
dir: process.cwd(),
host: host,
config: config,
constants: constants,
config_file: env_file,
remote: remote
};
var script_file = './lib/' + config.deployment.type + '/provision';
console.log("Script:", script_file);
delete config.deployment.type;
script = require(script_file);
script.provision(options, complete);
function complete(err) {
console.log('\ncomplete.');
process.exit();
}
}