Last active
January 10, 2018 17:18
-
-
Save moski/996567eeaed532d11425 to your computer and use it in GitHub Desktop.
How to integrate rollbar with AWS opsworks
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
node_layers = node[:opsworks][:instance][:layers] | |
if (node_layers.include?("rails-app")) | |
node[:deploy].each do |application, deploy| | |
Chef::Log.debug("Trying rake for application #{deploy[:application_type]}") | |
if defined?(deploy[:application_type]) && deploy[:application_type] != 'rails' | |
Chef::Log.debug("Skipping Rollbar non rails apps") | |
next | |
end | |
access_token = deploy["rails_config"]["notifications"]["rollbar"]["access_token"] | |
env_var = deploy["rails_config"]["notifications"]["rollbar"]["env_var"] | |
# precompile assets into public/assets (which is symlinked to shared assets folder) | |
execute "rake rollback:notify" do | |
cwd release_path | |
command "bundle exec rake rollbar:notify -- --access_token #{access_token} --environment #{env_var}" | |
end | |
end | |
end |
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
require 'optparse' | |
require 'net/http' | |
namespace :rollbar do | |
desc "Notify Rollbar about a new deployment" | |
task :notify do | |
options = { | |
:environment => "staging", | |
:revision => `git log -n 1 --pretty=format:"%H"`, | |
:rollbar_username => "moski", | |
} | |
optparse = OptionParser.new do |opts| | |
opts.banner = "Usage: rake rollbar::notify [options]" | |
opts.on("-a", "--access_token ARG", String) { |token| options[:access_token] = token } | |
opts.on("-e", "--environment ARG", String) { |env| options[:environment] = env} | |
opts.on("-r", "--revision ARG", String) { |rev| options[:revision] = rev} | |
opts.on("-u", "--rollbar_username ARG", String) { |u| options[:rollbar_username] = u} | |
end | |
optparse.parse! | |
raise OptionParser::MissingArgument if options[:access_token].nil? | |
raise OptionParser::MissingArgument if options[:environment].nil? | |
raise OptionParser::MissingArgument if options[:revision].nil? | |
raise OptionParser::MissingArgument if options[:rollbar_username].nil? | |
options[:comment] = `git show -s --format=%B #{options[:revision]}`.strip | |
puts "access_token = #{options[:access_token]}" | |
puts "environment= #{options[:environment]}" | |
puts "revision= #{options[:revision]}" | |
puts "rollbar_username= #{options[:rollbar_username]}" | |
puts "comment= #{options[:comment]}" | |
uri = URI.parse 'https://api.rollbar.com/api/1/deploy/' | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request.body = ::JSON.dump(options) | |
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
http.request(request) | |
end | |
puts "Rollbar notification complete." | |
exit | |
end | |
end | |
# rake rollbar:notify -- --access_token XXXXXXX --rollbar_username moski |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment