Skip to content

Commit

Permalink
Deploy script now accepts command lines arguments to specify if img a…
Browse files Browse the repository at this point in the history
…nd vendor directories should be synced
  • Loading branch information
bxjx committed Oct 10, 2012
1 parent f499504 commit 8c1ab33
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
47 changes: 23 additions & 24 deletions deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ var exec = require('child_process').exec;
var async = require("async");
var colors = require('colors');
var request = require('request');
var argv = require('optimist')
.usage('Usage: $0 -e [environment] -p [apikey]')
.demand(['e','k'])
.alias('e', 'env')
.describe('e', 'Environment to deploy to')
.alias('k', 'key')
.describe('k', 'Rackspace API key')
.alias('a', 'all')
.describe('a', 'Sync all asssets (not just build files)')
.argv;

var auth = 'ac2aa55ec8adecc56501fc32cc22ec38';
var apiKey, env;

function parseArgs(){
if (process.argv.length !== 4){
console.error('Usage: ./deploy.js staging RACKSPACE_API_KEY');
process.exit(1);
}
env = process.argv[2];
apiKey = process.argv[3];
}

function getContainer(){
if (env === 'staging'){
if (argv.env === 'staging'){
return 'budget2012-staging';
}else if (env === 'production'){
}else if (argv.env === 'production'){
return 'budget2012';
}else{
console.error('unknown environment: ' + env + '. Should be staging or production');
console.error('unknown environment: ' + argv.env + '. Should be staging or production');
process.exit(1);
}
}

function getServers(){
if (env === 'staging'){
if (argv.env === 'staging'){
return ['50.56.185.86'];
}else if (env === 'production'){
}else if (argv.env === 'production'){
return ['50.56.172.114', '198.101.231.69'];
}else{
console.error('unknown environment: ' + env + '. Should be staging or production');
console.error('unknown environment: ' + argv.env + '. Should be staging or production');
process.exit(1);
}
}
Expand All @@ -45,13 +45,14 @@ function build(cb){

function cdnSync(cb){
var container = getContainer();
async.forEach(['build', 'img', 'vendor'], function(dir, next){
console.error('Syncing ' + dir + ' to ' + container + '...');
var syncDirs = argv.all ? ['build', 'img', 'vendor'] : ['build'];
async.forEach(syncDirs, function(dir, next){
console.error('Syncing ' + dir + ' to ' + container);
mirror = CloudfilesMirror({
localPath: './web/' + dir,
remoteBase: dir,
container: container,
auth : { username: 'theglobalmail', apiKey: apiKey},
auth : { username: 'theglobalmail', apiKey: argv.key},
cdnEnabled: true,
pushOnBoot: true
});
Expand Down Expand Up @@ -84,21 +85,19 @@ function deploy(cb){
request({method: 'POST', url: 'http://' + server + '/deploy', form: {auth: auth}}, function(err, res, body){
if (err){
console.error(('ERROR: ' + err).red);
return cb('Triggering deploy on ' + server + ' ERROR');
return done('Triggering deploy on ' + server + ' ERROR');
}
if (res.statusCode != 200){
console.error(('ERROR: status code was ' + res.statusCode).red);
console.error(('ERROR: ' + body).red);
return cb('Triggering deploy on ' + server + ' ERROR');
return done('Triggering deploy on ' + server + ' ERROR');
}
console.error(body);
console.error(('Triggering deploy on ' + server + ' OK').green);
cb();
done();
});
});
}

parseArgs();
async.series([build, cdnSync, deploy], function(err){
if (err){
console.error(('ERROR: ' + err).red);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"should": "~1.1.0",
"async": "~0.1.22",
"cloudfiles-mirror": "*",
"colors": "~0.6.0-1"
"colors": "~0.6.0-1",
"optimist": "~0.3.4"
},
"devDependencies": {
"wd": "0.0.21"
Expand Down

0 comments on commit 8c1ab33

Please sign in to comment.