This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from Financial-Times/nbt-scale
nbt scale
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
var packageJson = require(process.cwd() + '/package.json'); | ||
var herokuAuthToken = require('../lib/heroku-auth-token'); | ||
var normalizeName = require('../lib/normalize-name'); | ||
var fetchres = require('fetchres'); | ||
var scale = require('haikro/lib/scale'); | ||
|
||
module.exports = function(opts) { | ||
|
||
var source = opts.source || normalizeName(packageJson.name, { version: false }); | ||
var target = opts.target || packageJson.name; | ||
var overrides = {}; | ||
var token; | ||
|
||
if (opts.overrides) { | ||
opts.overrides.map(function (o) { | ||
var t = o.split('='); | ||
overrides[t[0]] = t[1]; | ||
}); | ||
} | ||
|
||
function getProcessInfo(serviceData) { | ||
return serviceData && | ||
serviceData.versions && | ||
serviceData.versions[Object.keys(serviceData.versions).length.toString()] && | ||
serviceData.versions[Object.keys(serviceData.versions).length.toString()].processes; | ||
} | ||
|
||
console.log('Scaling ' + target + ' using service registry information for ' + source); | ||
return herokuAuthToken() | ||
.then(function(authToken) { | ||
token = authToken; | ||
}) | ||
.then(function() { | ||
return fetch('https://ft-next-service-registry.herokuapp.com/services'); | ||
}) | ||
.then(fetchres.json) | ||
.then(function(data) { | ||
var serviceData = data.filter(function(service) { | ||
return service.name === source; | ||
}); | ||
serviceData = serviceData.length ? serviceData[0] : null; | ||
|
||
var processInfo = getProcessInfo(serviceData); | ||
|
||
if(!processInfo) { | ||
throw new Error("Could not get process info for " + serviceData.name + ". Please check the service registry."); | ||
} | ||
var processProfiles = { | ||
updates: [] | ||
}; | ||
|
||
for( var process in processInfo ) { | ||
if(processInfo.hasOwnProperty(process)) { | ||
processProfiles.updates.push({ | ||
process: process, | ||
size: processInfo[process].size, | ||
quantity: processInfo[process].scale | ||
}); | ||
} | ||
} | ||
|
||
return scale({ | ||
token: token, | ||
app: target, | ||
processProfiles: processProfiles | ||
}); | ||
|
||
|
||
}) | ||
.then(function(processProfiles) { | ||
console.log(target + " config vars are set to", processProfiles); | ||
}) | ||
.catch(function(err) { | ||
console.log ('Error scaling processes - ' + err); | ||
}); | ||
}; |