Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from Financial-Times/preboot
Browse files Browse the repository at this point in the history
enable preboot for all apps
  • Loading branch information
matthew-andrews committed Apr 15, 2015
2 parents 4f3d110 + 103b697 commit e5056db
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions bin/next-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');
Expand All @@ -39,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
Expand Down Expand Up @@ -119,7 +124,7 @@ program
});

program
.command('purge [url')
.command('purge [url]')
.option('-s, --soft <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){
Expand All @@ -130,6 +135,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('')
Expand Down
21 changes: 21 additions & 0 deletions lib/enable-preboot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'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)
.then(function() {
console.log("Preboot enabled for " + app);
});
};
18 changes: 18 additions & 0 deletions tasks/enable-preboot.js
Original file line number Diff line number Diff line change
@@ -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);
});
};

0 comments on commit e5056db

Please sign in to comment.