forked from CoderDojo/cp-local-development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.js
139 lines (128 loc) · 3.56 KB
/
system.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var baseRepo = 'https://github.com/CoderDojo/';
var _ = require('lodash');
var defaultBranch = 'master';
// set any variables common to all systems here..
var globalEnv = {
POSTGRES_USERNAME: 'platform',
POSTGRES_PASSWORD: 'QdYx3D5y',
POSTGRES_HOST: 'localhost',
POSTGRES_PORT: 5432,
MAILTRAP_ENABLED: 'true',
SALESFORCE_ENABLED: 'false',
MAIL_HOST: 'mailtrap.io',
MAIL_PORT: '2525',
MAIL_USER: '397746d4abc52902b',
MAIL_PASS: '0383c445ef22d4',
GOOGLE_API_ENABLED: 'false',
GOOGLE_MAPS_KEY: 'AIzaSyD7i1_IMvI1ulfsvX7sntwlGULTL_iQ69U',
CDF_ADMINS: '[email protected],[email protected]'
};
module.exports = {
zen: {
systemBranch: 'master',
systemEnv: {
// put any system specific env vars here
},
get services () {
var self = this;
var services = [{
name: 'cp-salesforce-service'
}, {
name: 'cp-dojos-service',
database: 'cp-dojos-development',
testdata: './scripts/load_test_data.sh empty',
get serviceEnv () {
return {
POSTGRES_NAME: this.database
};
}
}, {
name: 'cp-users-service',
database: 'cp-users-development',
testdata: './scripts/load_test_data.sh empty',
get serviceEnv () {
return {
POSTGRES_NAME: this.database,
RECAPTCHA_SECRET_KEY: '6LfVKQgTAAAAAI3dhMSRsrTbFbx7cnGr4Fy2sn5_'
};
}
}, {
name: 'cp-events-service',
database: 'cp-events-development',
get serviceEnv () {
return {
// put any service specific env vars here
POSTGRES_NAME: this.database
};
}
}, {
name: 'cp-badges-service'
}, {
name: 'cp-zen-platform',
ignored: ['web/.build']
}];
// add default getter props to all services if not already overridden
addGetters(services, self);
return services;
},
// for easy debugging (the getters defined above to no console.log well!)
stringify: function () {
return stringify(this);
},
// system env getter, amalgamated with the global env
get env () {
return env(this);
}
}
};
var stringify = function (system) {
return {
systemBranch: system.systemBranch,
services: _.map(system.services, _.toPlainObject)
};
};
var env = function (system) {
var evars = _.clone(globalEnv);
_.each(system.systemEnv, function (v, k) {
evars[k] = v;
});
return evars;
};
var addGetters = function (services, self) {
_.each(services, function (service) {
if (!service.repo) {
service.__defineGetter__('repo', function () {
return baseRepo + service.name;
});
}
var serviceBranch = service.branch;
if (!service.branch) {
service.__defineGetter__('branch', function () {
return serviceBranch || self.systemBranch || defaultBranch;
});
}
// most services have the same start command
if (!service.start) {
service.__defineGetter__('start', function () {
return 'node ./service.js';
});
}
// env function returns the amalgamated environement variables
service.__defineGetter__('env', function () {
var evars = _.clone(self.env);
_.each(service.serviceEnv, function (v, k) {
evars[k] = v;
});
// see if user has anything to override
try {
var localenv = require('./local-env.js');
_.each(localenv, function (v, k) {
evars[k] = v;
});
}catch (x) {
// purposely ignored
}
return evars;
});
});
};