Skip to content

Instantly share code, notes, and snippets.

@mtylty
Created April 6, 2013 01:08
Show Gist options
  • Save mtylty/5324075 to your computer and use it in GitHub Desktop.
Save mtylty/5324075 to your computer and use it in GitHub Desktop.
A hubot script to use the Pulsar gem to deploy via hubot
# Description:
# This script enables you to deploy via the Pulsar gem through hubot.
# Deploy authorization is enabled via the auth hubot script; to deploy
# you need to have either the 'admin' or the 'deployer' role.
#
# Dependencies:
# auth.coffee
#
# Configuration:
# HUBOT_INSTALL_DIR
# PULSAR_CONF_REPO
#
# Commands:
# hubot deploy <application> <stage> - Deploys an application on a stage via pulsar
#
# Author:
# NebuLab
util = require 'util'
child_process = require 'child_process'
exec = child_process.exec
module.exports = (robot) ->
robot.respond /deploy (.+) (.+)$/i, (msg) ->
admin = process.env.HUBOT_AUTH_ADMIN
user = "#{msg.message.user.name}"
application = msg.match[1]
stage = msg.match[2]
can_deploy = user.toLowerCase() in admin.toLowerCase().split(',') or
robot.Auth.hasRole(user, "deployer") or
robot.Auth.hasRole(user, "#{application}_deployer") or
robot.Auth.hasRole(user, "#{application}_#{stage}_deployer")
if can_deploy
gem_home = process.env.HUBOT_INSTALL_DIR
pulsar_conf = process.env.PULSAR_CONF_REPO
user = process.env.HUBOT_DEPLOY_USER || "hubot"
env_variables = "GEM_HOME=#{gem_home} PULSAR_CONF_REPO=#{pulsar_conf} USER=#{user}"
ssh_agent_forward = "eval `ssh-agent -s` && ssh-add"
console.log("Hubot is deploying: #{ssh_agent_forward} && #{env_variables} pulsar #{application} #{stage}")
exec "#{ssh_agent_forward} && #{env_variables} pulsar #{application} #{stage}", (err, stdout, stderr) ->
if err?
console.log(err)
msg.reply("uh oh something went wrong with the deploy...")
else
msg.reply("sorry but you have no permission to deploy...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment