Created
May 29, 2012 06:00
-
-
Save eric/2822861 to your computer and use it in GitHub Desktop.
Capistrano notification for Boundary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load plugin | |
load 'boundary' | |
# Notify boundary with your orgid, apikey | |
boundary.register 'cdd7261592bca18539eae9bb5f1bcfdd', 'f9e6282c4727c5733585a4be86e0f990' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
not, "ruby should make this easier"?
Not when you've been deep into bash for the past few months, building a Capistrano alternative ; ).
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
When I see this, I'm thinking: "hmm.... currrl"