-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathecosystem.config.js
More file actions
103 lines (98 loc) · 2.53 KB
/
ecosystem.config.js
File metadata and controls
103 lines (98 loc) · 2.53 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
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
97
98
99
100
101
102
103
const homeDir = require('os').homedir();
const fs = require('fs');
const paramMap = {};
process.argv.forEach(v => {
if (v.indexOf("=")) {
if (v.startsWith("--")) {
v = v.substr(2);
}
const splits = v.split("=");
paramMap[splits[0]] = splits[1];
}
});
if (!paramMap['appChef']) {
throw new Error('appChef is missing');
}
if (!paramMap['appChefKey']) {
throw new Error('appChefKey is missing');
}
if (!paramMap['platforms']) {
throw new Error("Platforms is not specified");
}
const getWorkspaceDir = (ws) => {
const workspace = ws || `${homeDir}/.app_chef/`;
if (!fs.existsSync(workspace)) {
fs.mkdirSync(workspace, {
recursive: true
})
}
return workspace;
};
const prepareApp = (args) => {
const ws = getWorkspaceDir(args['wsDir']);
fs.readdirSync(ws).filter(f => {
if (f.endsWith('.lock')) {
fs.unlinkSync(ws + f);
}
});
const opi = Math.max(args['orderPullInterval'] || 30000);
return {
name: args['name'],
script: __dirname + '/cli.js',
namespace: args['processGroup'] || 'appchef-agent',
cwd: ws,
autorestart: true,
restart_delay: opi,
args: [
"manage",
`--appChef=${args['appChef']}`,
`--appChefKey=${args['appChefKey']}`,
`--platforms=${args['platforms']}`,
`--kill-timeout=${(args['kill-timeout'] ? args['kill-timeout'] : 40) * 60 * 1000}`,
`--orderPullInterval=${opi}`
],
instances: (args['instances'] && parseInt(args['instances'])) || 1,
};
return
};
const prepareArgs = (tag, paramMap, tagDefaults) => {
const tagParams = Object.assign({}, paramMap, tagDefaults);
Object.keys(tagParams).forEach(k => {
if (k.startsWith(tag)) {
k.substr(tag.length);
tagParams[k.substr(tag.length)] = tagParams[k];
}
});
return tagParams;
};
const apps = [];
if (paramMap['platforms'].indexOf('android') >= 0) {
apps.push(prepareApp(prepareArgs('android-', paramMap, {
name: 'apk-builder',
platforms: 'android',
instances: 1
})));
}
if (paramMap['platforms'].indexOf('ios') >= 0) {
apps.push(prepareApp(prepareArgs('ios-', paramMap, {
name: 'ipa-builder',
platforms: 'ios',
instances: 1
})));
}
//console.log(apps);
module.exports = {
apps: apps,
deploy: {
production: {
user: 'SSH_USERNAME',
host: 'SSH_HOSTMACHINE',
ref: 'origin/master',
repo: 'GIT_REPOSITORY',
path: 'DESTINATION_PATH',
'pre-deploy-local': '',
'post-deploy': 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': ''
}
}
};