From 9c510f629f1ad7046def1bc842a83e71c3b2e953 Mon Sep 17 00:00:00 2001 From: Matthew Andrews Date: Wed, 15 Apr 2015 11:15:00 +0100 Subject: [PATCH 1/3] enable preboot for all apps --- README.md | 3 ++- bin/next-build-tools.js | 10 +++++++++- lib/enable-preboot.js | 18 ++++++++++++++++++ tasks/deploy.js | 6 +++++- tasks/enable-preboot.js | 18 ++++++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 lib/enable-preboot.js create mode 100644 tasks/enable-preboot.js diff --git a/README.md b/README.md index 1027aec0..32c30dcf 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ deploy-hashed-assets deploys hashed asset files to S3 (if AWS keys set correctly) build build javascript and css destroy [app] deletes the app from heroku - purge [options] [ur] purges the given url from the Fastly cache. Requires a FASTLY_KEY environment variable set to your fastly api key + purge [options] [url] purges the given url from the Fastly cache. Requires a FASTLY_KEY environment variable set to your fastly api key + enable-preboot [app] enables prebooting of an application to smooth over deploys * Options: diff --git a/bin/next-build-tools.js b/bin/next-build-tools.js index 01f8155c..d599ef11 100755 --- a/bin/next-build-tools.js +++ b/bin/next-build-tools.js @@ -16,6 +16,7 @@ var destroy = require('../tasks/destroy'); var purge = require('../tasks/purge'); var nightwatch = require('../tasks/nightwatch'); var deployHashedAssets = require('../tasks/deploy-hashed-assets'); +var enablePreboot = require('../tasks/enable-preboot'); function list(val) { return val.split(','); @@ -119,7 +120,7 @@ program }); program - .command('purge [url') + .command('purge [url]') .option('-s, --soft ', 'Perform a "Soft Purge (will invalidate the content rather than remove it"') .description('purges the given url from the Fastly cache. Requires a FASTLY_KEY environment variable set to your fastly api key') .action(function(url, options){ @@ -130,6 +131,13 @@ program } }); + program + .command('enable-preboot [app]') + .description('enables prebooting of an application to smooth over deploys') + .action(function(app) { + return enablePreboot({ app: app }).catch(exit); + }); + program .command('*') .description('') diff --git a/lib/enable-preboot.js b/lib/enable-preboot.js new file mode 100644 index 00000000..9c47e34e --- /dev/null +++ b/lib/enable-preboot.js @@ -0,0 +1,18 @@ +'use strict'; + +var fetchres = require('fetchres'); + +module.exports = function(opts) { + var token = opts.token; + var app = opts.app; + return fetch('https://api.heroku.com/apps/' + app + '/features/preboot', { + method: 'PATCH', + headers: { + 'Accept': 'Accept: application/vnd.heroku+json; version=3', + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + token + }, + body: JSON.stringify({ enabled: true }) + }) + .then(fetchres.json); +}; diff --git a/tasks/deploy.js b/tasks/deploy.js index 528342f7..b26f1d2f 100644 --- a/tasks/deploy.js +++ b/tasks/deploy.js @@ -8,6 +8,7 @@ var build = require('haikro/lib/build'); var deploy = require('haikro/lib/deploy'); var logger = require('haikro/lib/logger'); var normalizeName = require('../lib/normalize-name'); +var enablePreboot = require('../lib/enable-preboot'); module.exports = function(app) { logger.setLevel('debug'); @@ -22,7 +23,10 @@ module.exports = function(app) { .then(function(results) { token = results[0]; commit = results[1]; - return build({ project: process.cwd() }); + return Promise.all([ + build({ project: process.cwd() }), + enablePreboot({ app: app, token: token }) + ]); }) .then(function() { console.log('Next Build Tools going to deploy to ' + name); diff --git a/tasks/enable-preboot.js b/tasks/enable-preboot.js new file mode 100644 index 00000000..37fd864b --- /dev/null +++ b/tasks/enable-preboot.js @@ -0,0 +1,18 @@ +'use strict'; + +var packageJson = require(process.cwd() + '/package.json'); +var herokuAuthToken = require('../lib/heroku-auth-token'); +var normalizeName = require('../lib/normalize-name'); +var enablePreboot = require('../lib/enable-preboot'); + +module.exports = function(opts) { + var app = opts.app || 'ft-next-' + normalizeName(packageJson.name); + + return herokuAuthToken() + .then(function(token) { + return enablePreboot({ app: app, token: token }); + }) + .then(function() { + console.log('Preboot enabled for ' + app); + }); +}; From 0bcbdb425af55baa17cb15194605c87bf28c5b73 Mon Sep 17 00:00:00 2001 From: Matthew Andrews Date: Wed, 15 Apr 2015 11:22:20 +0100 Subject: [PATCH 2/3] Don't couple build and preboot so closely --- bin/next-build-tools.js | 6 +++++- tasks/deploy.js | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/next-build-tools.js b/bin/next-build-tools.js index d599ef11..2be34f1d 100755 --- a/bin/next-build-tools.js +++ b/bin/next-build-tools.js @@ -40,7 +40,11 @@ program .command('deploy [app]') .description('runs haikro deployment scripts with sensible defaults for Next projects') .action(function(app) { - deploy(app).catch(exit); + enablePreboot(app) + .then(function() { + return deploy(app); + }) + .catch(exit); }); program diff --git a/tasks/deploy.js b/tasks/deploy.js index b26f1d2f..528342f7 100644 --- a/tasks/deploy.js +++ b/tasks/deploy.js @@ -8,7 +8,6 @@ var build = require('haikro/lib/build'); var deploy = require('haikro/lib/deploy'); var logger = require('haikro/lib/logger'); var normalizeName = require('../lib/normalize-name'); -var enablePreboot = require('../lib/enable-preboot'); module.exports = function(app) { logger.setLevel('debug'); @@ -23,10 +22,7 @@ module.exports = function(app) { .then(function(results) { token = results[0]; commit = results[1]; - return Promise.all([ - build({ project: process.cwd() }), - enablePreboot({ app: app, token: token }) - ]); + return build({ project: process.cwd() }); }) .then(function() { console.log('Next Build Tools going to deploy to ' + name); From 103b6975885fa291f3a651aefd46dd7cf7b17671 Mon Sep 17 00:00:00 2001 From: Matthew Andrews Date: Wed, 15 Apr 2015 11:25:31 +0100 Subject: [PATCH 3/3] Add some console output --- lib/enable-preboot.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/enable-preboot.js b/lib/enable-preboot.js index 9c47e34e..3b6856e4 100644 --- a/lib/enable-preboot.js +++ b/lib/enable-preboot.js @@ -14,5 +14,8 @@ module.exports = function(opts) { }, body: JSON.stringify({ enabled: true }) }) - .then(fetchres.json); + .then(fetchres.json) + .then(function() { + console.log("Preboot enabled for " + app); + }); };