-
Notifications
You must be signed in to change notification settings - Fork 3
/
blueGreen.js
45 lines (40 loc) · 1.49 KB
/
blueGreen.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
const _ = require('lodash');
const cf = require('push2cloud-cf-adapter');
const WF = require('push2cloud-workflow-utils');
const init = require('./init');
const switchRoutes = require('./switchRoutes');
const old = require('./old');
const missing = require('./missing');
const waterfall = WF.waterfall;
const map = WF.map;
const mapSeries = WF.mapSeries;
const mapLimit = WF.mapLimit(4);
const combine = WF.combine;
const packageApp = WF.packageApp;
const blueGreen = (deploymentConfig, api, log) =>
waterfall(
[ init(deploymentConfig, api, log)
, map(packageApp, missing.apps)
, mapSeries(api.createServiceInstance, missing.services)
, map(api.createRoute, missing.routes)
, mapLimit(api.pushApp, missing.apps)
, map(api.setEnv, missing.envVars)
, map(api.stageApp, missing.apps)
, map(api.waitForServiceInstance, missing.services)
, map(api.bindService, missing.serviceBindings)
, map(api.startAppAndWaitForInstances, missing.apps)
, map(api.associateRoute, missing.unAssociatedRoutes)
, map(switchRoutes(api), combine('desired.routes', old.associatedRoutes, (r) => (r.unversionedName + r.hostname + r.domain + (r.path || ''))))
, map(api.stopApp, old.apps)
, map(api.unbindService, old.serviceBindings)
, map(api.deleteApp, old.apps)
]
);
module.exports = function(config, log, cb) {
const api = cf(_.assign({
username: process.env.CF_USER
, password: process.env.CF_PWD
}
, config.target));
return blueGreen(config, api, log)({}, cb);
};