Skip to content

Instantly share code, notes, and snippets.

@eric
Created May 29, 2012 06:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric/2822861 to your computer and use it in GitHub Desktop.
Save eric/2822861 to your computer and use it in GitHub Desktop.
Capistrano notification for Boundary
# load plugin
load 'boundary'
# Notify boundary with your orgid, apikey
boundary.register 'cdd7261592bca18539eae9bb5f1bcfdd', 'f9e6282c4727c5733585a4be86e0f990'
# Put this in a file that is loaded by your deploy.rb
namespace :boundary do
def register(orgid, token)
before 'deploy', "boundary:record_start"
before 'deploy:migrations', "boundary:record_start"
after 'deploy', "boundary:notify_finished"
after 'deploy:migrations', "boundary:notify_finished"
task :record_start do
set :deploy_start_time, Time.now
end
report = lambda do |annotation|
url = URI.parse("https://api.boundary.com/#{orgid}/annotations")
req = Net::HTTP::Post.new(url.path)
req.basic_auth(token, '')
req.body = annotation.to_json
req.content_type = 'application/json'
http = Net::HTTP.new(url.host, url.port)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.use_ssl = true
store = OpenSSL::X509::Store.new
store.set_default_paths
http.cert_store = store
case res = http.start { |http| http.request(req) }
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
end
task :notify_finished do
deployer = ENV['USER']
deployed = current_revision.to_s[0..7]
deploying = real_revision.to_s[0..7]
github_repo = repository[/github.com:(.*)\.git$/, 1]
compare_url = "http://github.com/#{github_repo}/compare/#{deployed}...#{deploying}"
annotation = {
:type => "deploy",
:subtype => "by #{deployer} with `cap #{ARGV.join(' ')}`",
:start_time => deploy_start_time.to_i,
:end_time => Time.now.to_i,
:tags => [ 'deploy', fetch(:rails_env, '') ],
:links => [
{
:rel => 'github',
:href => compare_url
}
]
}
report.call annotation
end
end
end
@gerhard
Copy link

gerhard commented Jun 12, 2012

When I see this, I'm thinking: "hmm.... currrl"

@eric
Copy link
Author

eric commented Jun 12, 2012

not, "ruby should make this easier"?

@gerhard
Copy link

gerhard commented Jun 12, 2012

Not when you've been deep into bash for the past few months, building a Capistrano alternative ; ).

@michaelfairley
Copy link

boundary.rb needs a handful of requires:

require 'uri'
require 'net/http'
require 'openssl'
require 'json'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment