Skip to content
This repository has been archived by the owner on Jul 11, 2020. It is now read-only.

Commit

Permalink
more work on deploy
Browse files Browse the repository at this point in the history
dwradcliffe committed Dec 27, 2014
1 parent acab4ab commit caf2e13
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Berksfile.lock
Original file line number Diff line number Diff line change
@@ -275,7 +275,7 @@ GRAPH
dnsimple (>= 0.0.0)
hostname (>= 0.0.0)
rubygems-hosts (0.0.10)
rubygems-hubot (0.0.30)
rubygems-hubot (0.0.32)
chef-vault (>= 0.0.0)
hubot (~> 1.0.2)
nginx (>= 0.0.0)
35 changes: 20 additions & 15 deletions cookbooks/rubygems-hubot/files/default/scripts/deploy.coffee
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
# Allows hubot to interact with capistrano.
#
# Dependencies:
# None
# * async
#
# Configuration:
# None
@@ -11,41 +11,40 @@
# hubot deploy <env>
#
# Author:
# Shopify, David Radcliffe
# David Radcliffe

spawn = require('child_process').spawn
fs = require('fs')
child_process = require 'child_process'
fs = require 'fs'
async = require 'async'

exec = (command, args, logFile, callback) ->
data = ""
fs.appendFile(logFile, command + " " + args.join(" ") + "\n")
exec = (command, logFile, callback) ->
fs.appendFile(logFile, command + "\n")

options = { cwd: '/var/lib/hubot-capistrano/staging', env: { HOME: process.env["HOME"], PATH: process.env["PATH"], PWD: '/var/lib/hubot-capistrano/staging' } }
proc = spawn(command, args, options)
options = { cwd: process.env["HUBOT_DEPLOY_DIR"], env: { HOME: process.env["HOME"], PATH: process.env["PATH"], PWD: process.env["HUBOT_DEPLOY_DIR"] } }
proc = child_process.exec(command, options)

proc.stdout.on "data", (chunk) ->
data += chunk
fs.appendFile(logFile, chunk)

proc.stderr.on "data", (chunk) ->
data += chunk
fs.appendFile(logFile, chunk)

proc.on "error", (err) ->
callback "Error: #{err}"

proc.on "close", (exit_code)->
if exit_code == 0
callback null, data
callback null
else
callback "Exited with #{exit_code}\n#{data}"
callback "Exited with #{exit_code}"

allowedToDeploy = (username) ->
if username == 'dwradcliffe'
true
else
false


module.exports = (robot) ->

robot.respond /deploy\s+(production|staging)/i, (msg) ->
@@ -58,13 +57,19 @@ module.exports = (robot) ->
# branch = msg.match[2]
url = "https://bot.rubygems.org/deploy/#{deployKey}"
msg.send "Deploying to #{env}... "
exec "bundle", ["exec", "cap #{env} deploy -s user=hubot"], "/var/log/hubot_deploys/#{deployKey}.log", (err, result) ->

async.series [
(callback) ->
exec "bundle check || bundle install --local --without production", "#{process.env["HUBOT_DEPLOY_LOG_DIR"]}/#{deployKey}.log", callback
(callback) ->
exec "bundle exec cap #{env} deploy -s user=hubot", "#{process.env["HUBOT_DEPLOY_LOG_DIR"]}/#{deployKey}.log", callback
], (err, results) ->
if err
msg.send ":x: Deploy to #{env} failed! #{url}"
else
msg.send ":+1: Deployed to #{env}! #{url}"

robot.router.get '/deploy/:key', (req, res) ->
fs.readFile "/var/log/hubot_deploys/#{req.params.key}.log", (err, data) ->
fs.readFile "#{process.env["HUBOT_DEPLOY_LOG_DIR"]}/#{req.params.key}.log", (err, data) ->
res.set 'Content-Type', 'text/plain'
res.send data
2 changes: 1 addition & 1 deletion cookbooks/rubygems-hubot/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name 'rubygems-hubot'

version '0.0.30'
version '0.0.32'

depends 'chef-vault'
depends 'hubot', '~> 1.0.2'
10 changes: 3 additions & 7 deletions cookbooks/rubygems-hubot/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -15,18 +15,13 @@

node.set['hubot']['dependencies'] = {
'hubot-slack' => '~3.1.0',
'hubot-chef' => '>= 0.0.0',
'hubot-capistrano' => '1.0.2'
'async' => '^0.9.0',
}

node.set['hubot']['hubot_scripts'] = []

node.set['hubot']['external_scripts'] = []

# Disabled external scripts:
# hubot-chef
# hubot-capistrano

hubot_secrets = chef_vault_item('hubot', 'httpd')

node.set['hubot']['config'] = {
@@ -35,7 +30,8 @@
'HUBOT_SLACK_BOTNAME' => 'hubot',
'EXPRESS_USER' => hubot_secrets['user'],
'EXPRESS_PASSWORD' => hubot_secrets['password'],
# 'HUBOT_CAP_DIR' => '/var/lib/hubot-capistrano/'
'HUBOT_DEPLOY_DIR' => '/var/lib/hubot-deploy/staging',
'HUBOT_DEPLOY_LOG_DIR' => '/var/log/hubot_deploys',
}

template "#{node['hubot']['install_dir']}/external-scripts.json" do

0 comments on commit caf2e13

Please sign in to comment.