From bfe9831a275937458a00702a50b85ddafe880ba0 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Tue, 13 Dec 2016 15:49:38 +0000 Subject: [PATCH 1/2] Add 'inhibit' option to scale task to scale all dynos to 0 --- tasks/scale.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tasks/scale.js b/tasks/scale.js index 5693b04c..20686186 100644 --- a/tasks/scale.js +++ b/tasks/scale.js @@ -36,9 +36,20 @@ function task (opts) { } const processProfiles = Object.keys(processInfo).map(process => { - return process + '=' + (opts.minimal ? 1 : processInfo[process].scale) - + ':' + (opts.minimal ? 'standard-1X' : processInfo[process].size); - }); + let scale = processInfo[process].scale; + let size = processInfo[process].size; + + if (opts.minimal) { + scale = 1; + size = 'standard-1X'; + } + + if (opts.inhibit) { + scale = 0; + } + + return `${process}=${scale}:${size}`; + }); return shellpromise('heroku ps:scale ' + processProfiles.join(' ') + ' --app ' + target, { verbose: true }); @@ -57,12 +68,14 @@ module.exports = function (program, utils) { program .command('scale [source] [target]') .description('downloads process information from next-service-registry and scales/sizes the application servers') - .option('-m, --minimal', 'scales each dyno to a single instance (useful for provisioning a test app)') + .option('-m, --minimal', 'scales each dyno to a single instance') + .option('-i, --inhibit', 'scales each dyno down to 0') .action(function (source, target, options) { task({ source: source, target: target, - minimal: options.minimal + minimal: options.minimal, + inhibit: options.inhibit }).catch(utils.exit); }); }; From 790107adcad306f56d41c9164da37932c37f8d9f Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Tue, 13 Dec 2016 15:54:34 +0000 Subject: [PATCH 2/2] Update ship task to use minimal/inhibit scale options --- tasks/ship.js | 6 ++++-- test/ship.test.js | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tasks/ship.js b/tasks/ship.js index 9e52bb18..10829ac7 100644 --- a/tasks/ship.js +++ b/tasks/ship.js @@ -56,7 +56,7 @@ function task (opts) { } log.info('Scale staging app to 1 dyno'); - yield scale({target:apps.staging, scale:'web=1'}).catch(function (){ + yield scale({ source: appName, target: apps.staging, minimal: true }).catch(function (){ log.info('Failed to scale up staging app - is this the first run?') }); @@ -86,7 +86,9 @@ function task (opts) { } log.info('scale staging app back to 0'); - yield scale({target:apps.staging, scale:'web=0'}); + yield scale({ source: appName, target: apps.staging, inhibit: true }).catch(() => { + log.warn('Failed to scale down staging app'); + }); log.success('Shipped!'); log.art.ship(appName); diff --git a/test/ship.test.js b/test/ship.test.js index 3d13acbd..fa776246 100644 --- a/test/ship.test.js +++ b/test/ship.test.js @@ -58,10 +58,12 @@ describe('tasks/ship', function (){ it('Should scale to staging app up to 1 web dyno before deploying', function (){ let pipelineName = 'test'; + let appName = 'sample-app'; + return co(function* (){ yield ship({pipeline:pipelineName}); - sinon.assert.calledWith(mockScale.task, {target:mockApps.staging, scale:'web=1'}); + sinon.assert.calledWith(mockScale.task, {source:appName, target:mockApps.staging, minimal:true}); }); }); @@ -98,10 +100,12 @@ describe('tasks/ship', function (){ it('Should scale the staging app down to 0 when complete', function (){ let pipelineName = 'test'; + let appName = 'sample-app'; + return co(function* (){ yield ship({pipeline:pipelineName}); - sinon.assert.calledWith(mockScale.task, {target:mockApps.staging, scale:'web=0'}); + sinon.assert.calledWith(mockScale.task, {source:appName, target:mockApps.staging, inhibit:true}); }); });