Skip to content

Instantly share code, notes, and snippets.

@johnthepink
Created September 19, 2014 22:28
Show Gist options
  • Save johnthepink/1fc66f05c38e7184b9e1 to your computer and use it in GitHub Desktop.
Save johnthepink/1fc66f05c38e7184b9e1 to your computer and use it in GitHub Desktop.
Deploy from Github to Heroku using Hipchat/Hubot
#!/bin/sh
# Mostly stolen from https://github.com/vidpresso/hubot-syncer/blob/master/pullpushprod.sh
cd /app
echo "Setting up SSH."
mkdir /app/.ssh
echo "$SSH_PRIVATE_KEY" > .ssh/id_rsa
echo "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
echo "Host heroku.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
echo "Cloning repo."
git clone $APPNAME_GITHUB_URL
cd /app/appname
echo "Adding heroku url."
git remote add prod $APPNAME_PRODUCTION_URL
echo "Pushing to heroku."
git checkout master # makes sure there's a master branch to push.
git push prod master
echo "Cleaning up..."
rm -Rf /app/appname
rm -Rf /app/.ssh
exit 0
# Description:
# Deploy is used to deploy from git repositories to servers.
#
# Commands:
# hubot deploy <repo>
#
# Author:
# johnthepink
util = require "util"
exec = require("child_process").exec
module.exports = (robot) ->
robot.respond /deploy (.*)/i, (msg) ->
# return unless deploy role
unless robot.auth.hasRole(msg.envelope.user,'deploy')
msg.send 'You do not have the deploy permissions. Contact the admin.'
return
repo = msg.match[1]
# you can extend this if statement to deploy more than one app
if repo == 'app'
msg.send "Deploying #{repo}"
child = exec "./deploy-app.sh", (err, stdout, stderr) ->
msg.send err if err
msg.send stderr if stderr
msg.send stdout
else
msg.send 'I do not know him'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment