GithubHelp home page GithubHelp logo

capistrano_mailer's Introduction

CapistranoMailer

A Gem For Capistrano Deployment Email Notification

Project CapistranoMailer
gem name capistrano_mailer
license MIT
expert support Get help on Codementor
download rank Total Downloads
version Gem Version
dependencies Dependency Status
code quality Code Climate
inline documenation Inline docs
continuous integration Build Status
test coverage Coverage Status
homepage on Github.com
documentation on Rdoc.info
live chat Join the chat at https://gitter.im/pboling/capistrano_mailer
Spread ♡ⓛⓞⓥⓔ♡ 🌏, 👼, :shipit:, Tweet Peter, 🌹

Summary

  • It is a Capistrano Plugin / Ruby Gem that requires ActionMailer
  • It is MIT licensed
  • It is old as duck, and it might be almost dead, maybe. (I started this project in 2007)
  • rails2 branch, releases will be in 3.x range, requires Rails 2.X
  • master branch, releases will be in 4.x range, requires Rails 3.X
  • Requires at least Capistrano 2.4.3 (might work with capistrano as old as 2.1.0, but has not been tested)
  • Known to be compatible with SCMs as of version 3.1.2: Perforce, SVN, and Git
  • Known to be compatible with, but does not require, the deprec gem.

About

Ever wanted to be emailed whenever someone on the team does a cap deploy of trunk or some tag to some server. Wouldn't it be nice to know about it every time a release was deployed? For large rails projects this type of coordination is essential, and this plugin makes sure everyone on the need to know list is notified when something new is deployed.

This plugin/gem is an extension to Capistrano.

That means it registers itself with Capistrano as a plugin and is therefore available to call in your recipes.

If you are looking to roll your own email integration into capistrano then try this pastie: http://pastie.org/146264 (thanks to Mislav Marohnić). But if you want to take the easy road to riches then keep reading ;) -- figurative "riches" of course, I promise nothing in return for your using this plugin

Important Note:

The first time you deploy to a server (a 'cold' deploy) capistrano mailer will cause an error because it uses capistrano's previous release variables, and when there are no previous releases capistrano throws an error. In the next version this will be fixed, just don't have time at the moment. If you would like to work on this 'first deploy' problem please fork my repo and work on it!

Installation

Add this line to your application's Gemfile:

gem 'capistrano_mailer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano_mailer

With Rails >= 3.x.x

The 4.x+ versions of this gem require at least Rails 3

With Rails <= 2.3.x

Switch to the rails2 branch (releases will be in 3.x range)

Usage

  1. You need to have already setup capistrano in the project, including the 'capify .' command.

  2. Add this line to the top of your config/deploy.rb:

    For plugin:

    You must make capistrano_mailer's libraries available in Ruby's load path. This is one way to do that:

    Add to the top of your config/deploy.rb file:

    $:.unshift 'vendor/plugins/capistrano_mailer/lib'

    For frozen gem:

    You must make capistrano_mailer's libraries available in Ruby's load path. This is one way to do that:

    Add to the top of your config/deploy.rb file:

    $:.unshift 'vendor/gems/capistrano_mailer-x.x.x/lib'

    then for gem or plugin:

    ####################################

    Capistrano Plugins go here

    require 'capistrano/mailer' #configure capistrano_mailer:

    The configuration file can go anywhere, but in past versions of the gem it was required to be in the config/ dir.

    require 'config/cap_mailer_settings' ####################################

  3. Configure Caistrano Mailer in the settings file required in step 2:

    If installed as a plugin might need the require here as well

    ActionMailer::Base.delivery_method = :smtp # or :sendmail, or whatever ActionMailer::Base.smtp_settings = { # if using :smtp :address => "mail.example.com", :port => 25, :domain => 'default.com', :perform_deliveries => true, :user_name => "[email protected]", :password => "mypassword", :authentication => :login } ActionMailer::Base.default_charset = "utf-8"# or "latin1" or whatever you are using

    CapMailer.configure do |config| config[:recipient_addresses] = ["[email protected]"]

    NOTE: THERE IS A BUG IN RAILS 2.3.3 which forces us to NOT use anything but a simple email address string for the sender address.

    Therefore %("Capistrano Deployment" [email protected]) style addresses may not work in Rails 2.3.3

    config[:sender_address] = "[email protected]" config[:subject_prepend] = "[EMPTY-CAP-DEPLOY]" config[:site_name] = "Empty Example.com App" end

  4. Add these two tasks to your deploy.rb:

    namespace :show do desc "Show some internal Cap-Fu: What's mah NAYM?!?" task :me do set :task_name, task_call_frames.first.task.fully_qualified_name #puts "Running #{task_name} task" end end

    namespace :deploy do ...

    desc "Send email notification of deployment (only send variables you want to be in the email)" task :notify, :roles => :app do show.me # this sets the task_name variable mailer.send_notification_email(self) end

    ... end

  5. Make sure you've defined rails_env, repository, deploy_to, host, and application. task_name is defined by the show:me task above, and the others are defined behind the scenes by Capistrano!

  6. The only parameter to mailer.send_notification_email that is required is the first. Minimally you need to define the capistrano variables:

    :rails_env :repository :task_name (provided by the show:me task included in this readme) :deploy_to :host :application

But there are tons of others - just take a look at lib/mailer/cap_mailer.rb.

If anyone has a cool way of recording the output into a capistrano accessible variable, so that it can be shoved into the release email that would be an excellent contribution!

  1. Then add the hook somewhere in your deploy.rb:

    after "deploy", "deploy:notify"

  2. Enjoy and Happy Capping!

Customization

If you want to use your own views you'll need to recreate the notification_email view: First you need to define where your templates are:

CapMailer.configure_capistrano_mailer do |config|
  config[:template_root]      = "app/views/capistrano_mailer/"
end

Then you'll need to create templates there called:

notification_email.text.html.erb

and / or

notification_email.text.plain.erb

Take a look at the templates that comes with the plugin to see how it is done (views/cap_mailer/...)

Credit where Credit is Due

Peter Boling (pboling) - Wrote original & maintainer Dave Nolan (textgoeshere) - lots of refactoring for 3.2 release Jason Rust (jrust) - Updated for Rails 3 compatibility

Thanks to Dustin Deyoung (ddeyoung) for the beautiful HTML email templates. Thanks to mixonix and Yoan Blanc (greut) for work on SCMs compatibility

How you can help!

Take a look at the reek list which is the file called REEK and stat fixing things. Once you complete a change, run the tests:

bundle exec rake test:all

If the tests pass refresh the reek list:

bundle exec rake reek > REEK

Follow the instructions for "Contributing" below.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency 'capistrano_mailer', '~> 0.5'

License

  • MIT License - See LICENSE file in this project
  • Copyright (c) 2008-2014 Peter H. Boling of Rails Bling
  • Copyright (c) 2007-8 Peter Boling & Sagebit, LLC

capistrano_mailer's People

Contributors

artem-mindrov avatar bartlomiejdanek avatar devinfoley avatar dreamnid avatar dreamwords avatar lawitschka avatar marksim avatar pboling avatar rrrene avatar textgoeshere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

capistrano_mailer's Issues

Hability to display the deployed branch

It's possible to deploy a specific branch when using git or mercurial with set :branch, "my-branch" and I'd like to be able to display it from the mailer. Any clue?

Rails 3.2.3: undefined method `inheritable_copy'

Was trying to use the gem for a 'railsless' deployment (if this makes any difference) with Rails 3.2.3, and was getting this exception on mail delivery:

/home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/action_view/helpers/controller_helper.rb:18:in `assign_controller': undefined method `inheritable_copy' for #<Hash:0xa16245c> (NoMethodError)
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/action_view/base.rb:214:in `initialize'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:76:in `new'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:76:in `view_context'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:110:in `_render_template'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:103:in `render_to_body'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:88:in `render'
        from /home/admoney/capistrano/recipes/cap_mailer_settings.rb:103:in `block (2 levels) in notification_email'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/collector.rb:26:in `custom'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/collector.rb:10:in `html'
        from /home/admoney/capistrano/recipes/cap_mailer_settings.rb:103:in `block in notification_email'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:684:in `collect_responses_and_parts_order'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:635:in `mail'
        from /home/admoney/capistrano/recipes/cap_mailer_settings.rb:102:in `notification_email'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:167:in `process_action'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:121:in `process'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:45:in `process'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:456:in `process'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:451:in `initialize'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:438:in `new'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:438:in `method_missing'
        from /home/admoney/capistrano/recipes/admoney.rb:27:in `block (3 levels) in <top (required)>'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/execution.rb:139:in `instance_eval'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/execution.rb:139:in `invoke_task_directly'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/execution.rb:101:in `find_and_execute_task'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/callback.rb:38:in `call'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/callbacks.rb:123:in `block in trigger'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/callbacks.rb:123:in `each'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/callbacks.rb:123:in `trigger'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/callbacks.rb:27:in `invoke_task_directly_with_callbacks'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/configuration/execution.rb:101:in `find_and_execute_task'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/cli/execute.rb:46:in `block in execute_requested_actions'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/cli/execute.rb:45:in `each'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/cli/execute.rb:45:in `execute_requested_actions'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/cli/help.rb:19:in `execute_requested_actions_with_help'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/cli/execute.rb:34:in `execute!'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/lib/capistrano/cli/execute.rb:14:in `execute'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/gems/capistrano-2.11.2/bin/cap:4:in `<top (required)>'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/bin/cap:19:in `load'
        from /home/admoney/.rvm/gems/ruby-1.9.3-p125/bin/cap:19:in `<main>'

Not sure if this is a proper solution, but making "@config" variable an instance of ActiveSupport::Configurable::Configuration (instead of a standard Hash) makes it work.

multiple emails if multiple app servers used

I'm using this gem with a railsless capistrano deployment routine and its working well, however because the capistrano recipes have multiple app servers (hence using capistrano in the first place) we get multiple deployment emails, one per server.

how can i go about configuring this so that it will only send one email per deployment ( i would also assume that if one server fails deployment the task is considered a fail - much like capistrano handles the failure already)

Failure notifications

I'm wondering if there's a way to make Mailer use different templates on success and failure. One possible way I see (though I didn't try it) to do this is:

  • create separate hooks for after:deploy and after:rollback
  • make them call notification_email with a config instance specifying the appropriate :template_path for each event

Even if this works, I think it's a bit cumbersome for such a routine case. Any chance to have failure notifications integrated into the gem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.