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 #19 from Financial-Times/destroy-before-provision
Browse files Browse the repository at this point in the history
Destroy before provision in case a branch build runs within 10 mins of the last branch build
  • Loading branch information
matthew-andrews committed Mar 12, 2015
2 parents 864c7d8 + 38be844 commit 1014745
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions tasks/provision.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
'use strict';

var denodeify = require('denodeify');
var exec = denodeify(require('child_process').exec, function(err, stdout, stderr) { return [err, stdout]; });
var create = require('haikro/lib/create');
var destroy = require('haikro/lib/destroy');
var logger = require('haikro/lib/logger');
var herokuAuthToken = require('../lib/heroku-auth-token');

// create a Heroku application server
module.exports = function (name) {
var heroku_auth = process.env.HEROKU_AUTH_TOKEN;

if (!heroku_auth) {
throw "You need to set a HEROKU_AUTH_TOKEN environment variables";
}

module.exports = function(name) {
var token;
return Promise.all([
process.env.HEROKU_AUTH_TOKEN ? Promise.resolve(process.env.HEROKU_AUTH_TOKEN) : exec('heroku auth:token'),
])
.then(function(results) {

return herokuAuthToken()
.then(function(result) {
logger.setLevel('debug');
token = results[0].trim();
token = result;
logger.verbose("Hack: Attempt to destroy app if already exists");
return destroy({
token: token,
app: name

// Suppress any errors
}).catch(function() {

});
})
.then(function() {
var server = {
app: name,
region: 'eu',
Expand Down

0 comments on commit 1014745

Please sign in to comment.