├── lib ├── capistrano-newrelic.rb └── capistrano │ ├── newrelic.rb │ ├── newrelic │ └── version.rb │ └── tasks │ └── newrelic.rake ├── Rakefile ├── Gemfile ├── .gitignore ├── CONTRIBUTORS.md ├── capistrano-newrelic.gemspec ├── LICENSE.txt └── README.md /lib/capistrano-newrelic.rb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/capistrano/newrelic.rb: -------------------------------------------------------------------------------- 1 | load File.expand_path("../tasks/newrelic.rake", __FILE__) 2 | -------------------------------------------------------------------------------- /lib/capistrano/newrelic/version.rb: -------------------------------------------------------------------------------- 1 | module Capistrano 2 | module NewRelic 3 | VERSION = '0.10.2' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in capistrano-newrelic.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | .idea 19 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | - [Bryan Ricker] (https://github.com/bricker) 2 | - [James Kahn] (https://github.com/jisk) 3 | - [Wojciech Wnętrzak] (https://github.com/morgoth) 4 | - [Bill Kayser (New Relic)] (https://github.com/bkayser) 5 | - [Derek Schneider] (https://github.com/schneiderderek) 6 | - [Nathan Parry] (https://github.com/nparry) -------------------------------------------------------------------------------- /capistrano-newrelic.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'capistrano/newrelic/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'capistrano-newrelic' 8 | spec.version = Capistrano::NewRelic::VERSION 9 | spec.authors = ['Abdelkader Boudih'] 10 | spec.email = ['terminale@gmail.com'] 11 | spec.description = %q{New Relic integration for Capistrano 3} 12 | spec.summary = %q{New Relic integration for Capistrano} 13 | spec.homepage = 'https://github.com/seuros/capistrano-newrelic' 14 | spec.license = 'MIT' 15 | 16 | spec.files = `git ls-files`.split($/) 17 | spec.require_paths = ['lib'] 18 | 19 | spec.add_dependency 'capistrano', '~> 3.0' 20 | spec.add_dependency 'newrelic_rpm' 21 | end 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Abdelkader Boudih 2 | Copyright (c) 2015 New Relic 3 | 4 | MIT License 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | IF THIS SOFTWARE ACCIDENTALLY CAUSE YOUR NEW RELIC HELICOPTER TO CRASH, 25 | CAUSES EVERYTHING ON THE GALAXY TO TRY TO KILL YOU, HACKS INTO A NUCLEAR 26 | SUBMARINE AND TARGETS YOUR HOUSE, ADD YOUR NAME TO THE NO FLY LIST , 27 | OPEN A BLACKHOLE UNDER YOUR DESK OR DOES ANYTHING ELSE YOU DON'T WANT IT TO DO, 28 | DON'T BLAME THE AUTHOR OF THIS GEM! 29 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/newrelic.rake: -------------------------------------------------------------------------------- 1 | require 'newrelic_rpm' 2 | require 'new_relic/cli/command' 3 | 4 | namespace :newrelic do 5 | desc "Record a deployment in New Relic (newrelic.com)" 6 | task :notice_deployment do 7 | changelog = fetch :newrelic_changelog 8 | if changelog.nil? && fetch(:scm) == :git && !fetch(:previous_revision).nil? 9 | on primary(:app) do 10 | within repo_path do 11 | changelog = capture(:git, "--no-pager log --no-color --pretty=format:'* %an: %s' --abbrev-commit --no-merges #{fetch(:previous_revision)[/^.*$/]}..#{fetch(:current_revision)}") 12 | end 13 | end 14 | end 15 | 16 | 17 | run_locally do 18 | deploy_options = { 19 | :environment => fetch(:newrelic_env, fetch(:stage, fetch(:rack_env, fetch(:rails_env, fetch(:stage))))), 20 | :revision => ENV['NEWRELIC_REVISION'] || fetch(:newrelic_revision, fetch(:current_revision, release_timestamp.strip)), 21 | :description => fetch(:newrelic_desc), 22 | :user => fetch(:newrelic_deploy_user), 23 | :appname => fetch(:newrelic_appname,fetch(:application)), 24 | :license_key => fetch(:newrelic_key) 25 | } 26 | 27 | deploy_options[:changelog] = changelog unless changelog.nil? 28 | 29 | if deploy_options[:user].nil? 30 | case fetch(:scm) 31 | when :git 32 | git_user = capture('git config user.name', raise_on_non_zero_exit: false).strip 33 | deploy_options[:user] = git_user unless git_user.empty? 34 | else 35 | deploy_options[:user] = ENV['USER'] 36 | end 37 | end 38 | 39 | debug "Uploading deployment to New Relic" 40 | begin 41 | deployment = NewRelic::Cli::Deployments.new deploy_options 42 | deployment.run 43 | info "Uploaded deployment information to New Relic" 44 | rescue => e 45 | error e 46 | end 47 | 48 | end 49 | end 50 | end 51 | 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Gem Version](https://badge.fury.io/rb/capistrano-newrelic.svg)](https://badge.fury.io/rb/capistrano-newrelic) 2 | # Capistrano::Newrelic 3 | 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | gem 'capistrano-newrelic' 10 | 11 | And then execute: 12 | 13 | $ bundle 14 | 15 | Or install it yourself as: 16 | 17 | $ gem install capistrano-newrelic 18 | 19 | ## Usage 20 | 21 | #### In Capfile 22 | 23 | require 'capistrano/newrelic' 24 | 25 | #### In stage files 26 | 27 | In your Capfile, or stage configuration files for multi-stage configuration add: 28 | 29 | ```ruby 30 | before 'deploy:finished', 'newrelic:notice_deployment' 31 | ``` 32 | License key and application name are retrieved from `config/newrelic.yml` based 33 | on the environment setting (defaults to value of `rails_env`, 34 | `rack_env` and can be overridden by setting `newrelic_env`). 35 | 36 | #### In deploy.rb 37 | 38 | Configurable options, shown here with defaults: 39 | 40 | ```ruby 41 | # New Relic Application Name to deploy to. Default to :application if no value set 42 | set :newrelic_appname, "" 43 | 44 | # New Relic environment to deploy to. Sets config based on section of newrelic.yml 45 | set :newrelic_env, fetch(:stage, fetch(:rack_env, fetch(:rails_env, 'production'))) 46 | 47 | # Deployment changelog defaults to the git changelog, if using git 48 | set :newrelic_changelog, "" 49 | 50 | # Deployment description 51 | set :newrelic_desc, "" 52 | 53 | # Deploy user if set will be used instead of the VCS user. 54 | set :newrelic_deploy_user 55 | ``` 56 | 57 | ## Changelog 58 | 59 | 0.0.10: 60 | * Use git --no-pager option when printing the log 61 | 62 | 0.0.9: 63 | * Added changelog capture for git 64 | * Populate revision with `current_revision` from scm if available; 65 | i.e., the git SHA 66 | 67 | 0.0.8: 68 | * Hook was removed, please set it in your deploy.rb or deploy/'stage'.rb 69 | ```ruby 70 | before 'deploy:finished', 'newrelic:notice_deployment' 71 | ``` 72 | 73 | * Revision can be set with : 74 | ```ruby 75 | set :newrelic_revision, "Your text here" 76 | ``` 77 | or 78 | ```ruby 79 | $ NEWRELIC_REVISION='Your text here' bundle exe cap .... 80 | ``` 81 | 82 | ## Contributing 83 | 84 | 1. Fork it 85 | 2. Create your feature branch (`git checkout -b my-new-feature`) 86 | 3. Commit your changes (`git commit -am 'Add some feature'`) 87 | 4. Push to the branch (`git push origin my-new-feature`) 88 | 5. Create new Pull Request 89 | --------------------------------------------------------------------------------