Browse files

releasing pushbot from the clutches of zamboni

  • Loading branch information...
1 parent 1cdf62e commit 7abafd99625d2bdcc5023f95068a8ef8e1055919 @jbalogh jbalogh committed Oct 20, 2011
Showing with 64 additions and 20 deletions.
  1. +25 −5 README.rst
  2. +39 −15 pushbot.js
View
30 README.rst
@@ -6,7 +6,7 @@ Dependencies
::
- npm install underscore nomnom request
+ npm install irc redis underscore nomnom request
pushbot.js
@@ -16,14 +16,34 @@ pushbot subscribes to a redis channel and waits for chief to tell it about
pushes. Then it parses the push logs to tell us what's going on with the push in
real-time.
-To run it for prod, just do::
+Here's all of pushbot's options::
- node pushbot.js
+ options:
+ --channel irc channel
+ --name bot name
+ --pubsub redis pubsub channel
+ --logs http path to the chief log directory
+ --notify who should be notified about the deploy?
+ --revision http path showing the current revision of the site
+ --github path to the github repo
+ --site name of the site getting pushed
+
+Since all the defaults are for addons.mozilla.org, just do::
+
+ node pushbot.js --notify=krupa --notify=clouserw
To run pushbot for addons-stage start it with these options::
- node pushbot.js --name=stagebot --pubsub=deploy.addons-stage
- --logs=/addons-stage-chief/logs/ --quiet --channel='#stagebot'
+ node pushbot.js --channel='#woo'
+ --name=stagebot
+ --pubsub=deploy.addons-stage
+ --logs='http://addonsadm.private.phx1.mozilla.com/chief/addons.stage/logs/'
+ --notify=jbalogh
+ --revision='https://addons-stage.allizom.org/media/git-rev.txt'
+ --github='https://github.com/mozilla/zamboni'
+ --site='addons-stage'
+
+That's a lot of options! Put it in a script.
During a push, you can ask pushbot for more details::
View
54 pushbot.js
@@ -22,24 +22,45 @@ var options = nomnom.opts({
help: 'redis pubsub channel'
},
logs: {
- default: '/addons-chief/logs/',
- help: 'relative path to the chief logs'
+ default: 'http://addonsadm.private.phx1.mozilla.com/chief/addons/logs/',
+ help: 'http path to the chief log directory'
+ },
+ notify: {
+ help: 'who should be notified about the deploy?',
+ list: true,
+ },
+ revision: {
+ default: 'https://addons.mozilla.org/media/git-rev.txt',
+ help: 'http path showing the current revision of the site'
+ },
+ github: {
+ default: 'https://github.com/mozilla/zamboni/',
+ help: 'path to the github repo'
+ },
+ site: {
+ default: 'zamboni',
+ help: "name of the site getting pushed"
},
- quiet: {
- flag: true,
- default: false,
- help: "don't tell krupa to check it"
- }
}).parseArgs();
console.log(options);
var amo = options.channel,
me = options.name,
pushbot = new irc_.Client('irc.mozilla.org', me, {channels: [amo]}),
redis = redis_.createClient(6382, '10.8.83.29'),
- logURL = 'http://addonsadm.private.phx1.mozilla.com' + options.logs,
- revisionURL = 'https://addons.mozilla.org/media/git-rev.txt',
- compareURL = 'https://github.com/mozilla/zamboni/compare/{0}...{1}';
+ logURL = options.logs,
+ revisionURL = options.revision,
+ compareURL = join(options.github, 'compare/{0}...{1}');
+
+
+/* Like os.path.join. */
+function join(/* args */) {
+ return _.reduce(_.tail(arguments), function(a, b) {
+ a = a[a.length - 1] == '/' ? a : a + '/';
+ b = b[0] == '/' ? b.substring(1) : b;
+ return a + b;
+ }, _.head(arguments));
+}
// Pull out messages that look like "<pushbot>: ..." and act on the ... part.
@@ -60,6 +81,7 @@ pushbot.on('message', function(from, to, message) {
}
});
+
// Hook up to chief through pub/sub.
redis.on('message', function(channel, message) {
sys.puts(channel, message);
@@ -71,11 +93,13 @@ redis.on('message', function(channel, message) {
});
redis.subscribe(options.pubsub);
+
// Handle events chief publishes through redis.
// It should go BEGIN => PUSH => DONE but a FAIL can interrupt.
function chiefSays(channel, msg) {
+ msg = _.extend(msg, options);
if (msg.event == 'BEGIN') {
- pushbot.say(channel, format('oh god, {who} is pushing zamboni {ref} ', msg));
+ pushbot.say(channel, format('oh god, {who} is pushing {site} {ref} ', msg));
// If we push origin/master the logfile is name origin.master.
logWatcher.start(msg.ref.replace('/', '.'));
request(revisionURL, function(err, response, body) {
@@ -85,7 +109,7 @@ function chiefSays(channel, msg) {
pushbot.say(channel, format('the push is now going to the webheads!! ' +
'({ref} {who})', msg));
} else if (msg.event == 'DONE') {
- pushbot.say(channel, format('{who} pushed zamboni {ref}', msg));
+ pushbot.say(channel, format('{who} pushed {site} {ref}', msg));
logWatcher.stop();
} else if (msg.event == 'FAIL') {
pushbot.say(channel, format('something terrible happened. check the logs ' +
@@ -113,8 +137,8 @@ var logWatcher = (function(){
var f = _.map(finished, function(x) { return format('{0} ({1}s)', x[0], x[1]);})
pushbot.say(amo, 'Finished: ' + f.join(', '));
// deploy_app means everything is out on the webheads.
- if (!options.quiet && _.contains(_.map(finished, _.first), 'deploy_app')) {
- pushbot.say(amo, 'krupa: check it');
+ if (options.notify && _.contains(_.map(finished, _.first), 'deploy_app')) {
+ pushbot.say(amo, format('{0}: check it', options.notify.join(': ')));
}
}
@@ -133,7 +157,7 @@ var logWatcher = (function(){
var self = {
start: function(filename) {
- var path = filename.indexOf('http://') === 0 ? filename : logURL + filename,
+ var path = filename.indexOf('http') === 0 ? filename : join(logURL, filename),
cmd = format('curl -s {path} | ./captain.py', {path: path});
pushbot.say(amo, 'watching ' + path);

0 comments on commit 7abafd9

Please sign in to comment.