Created
September 24, 2015 10:29
-
-
Save wok/54a7686a3d15d8974209 to your computer and use it in GitHub Desktop.
raygun_opsworks.rb
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
# Copyright (c) 2015 Taikala Ltd (www.taikala.fi) | |
# | |
# MIT License | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
# | |
# Recipe for notifying raygun.io about new deployments when using OpsWorks | |
# | |
# | |
# Setup: | |
# ------ | |
# 1. Add this file to your cookbook | |
# 2. Download raygun bash script from https://raygun.io/docs/deployments/bash and save to cookbook templates directory | |
# 3. Add api_key and auth_token to your stack configuration as custom JSON | |
# { | |
# "raygun": { | |
# "api_key": "YOUR_API_KEY", | |
# "auth_token": "YOUR_AUTH_TOKEN" | |
# } | |
# } | |
# 4. Add this recipe to your runlist | |
# 5. Enjoy ! | |
# copy the raygun shell script so we can run it later | |
template "/usr/local/sbin/raygun_deployment.sh" do | |
source "raygun_deployment.sh" | |
mode "0700" | |
end | |
node[:deploy].each do |application, deploy| | |
deploy = node[:deploy][application] | |
user = deploy[:deploying_user] || "UNKNOWN" | |
# user contains the full ARN, we will only use the last part | |
user = user.split('/').last | |
# Notify only if someone is actually running the deploy action | |
# The deploy action (which usually includes this recipet ) | |
# is automatically run when the instance starts, | |
# but we don't want any notifications in that case | |
should_notify = node[:opsworks][:activity] == "deploy" | |
# if there are any credentials, we will notify raygun | |
if node[:raygun] | |
execute "raygun deployment notification for #{application}" do | |
token = node[:raygun][:auth_token] | |
api_key = node[:raygun][:api_key] | |
# app version is the first 8 character of git hash | |
# git hash is taken from REVISION file in applications current directory | |
cwd "#{deploy[:deploy_to]}/current" | |
params = { | |
t: token, | |
a: api_key, | |
n: user, | |
v: "`cat REVISION | cut -c 1-8`", | |
g: "`cat REVISION`" | |
}.map{ |k,v| "-#{k} #{v}" }.join(" ") | |
command "raygun_deployment.sh #{params}" | |
only_if do | |
should_notify | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment