From 8c1ab33d524fd3ac3602787ae7953a6bb9ab6a08 Mon Sep 17 00:00:00 2001 From: "B.J. Rossiter" Date: Wed, 10 Oct 2012 15:33:07 +1100 Subject: [PATCH] Deploy script now accepts command lines arguments to specify if img and vendor directories should be synced --- deploy.js | 47 +++++++++++++++++++++++------------------------ package.json | 3 ++- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/deploy.js b/deploy.js index 4197f6e..4cb6fd6 100755 --- a/deploy.js +++ b/deploy.js @@ -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); } } @@ -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 }); @@ -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); diff --git a/package.json b/package.json index e8c1db1..9118ea1 100644 --- a/package.json +++ b/package.json @@ -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"