Skip to content

Commit 35a0c64

Browse files
committed
deploy notification added
1 parent 0f6bfba commit 35a0c64

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

config/deploy/cap_notify.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env ruby
2+
3+
=begin
4+
Capistrano deployment email notifier for Rails 3
5+
6+
Do you need to send email notifications after application deployments?
7+
8+
Christopher Sexton developed a Simple Capistrano email notifier for rails. You can find details at http://www.codeography.com/2010/03/24/simple-capistrano-email-notifier-for-rails.html.
9+
10+
Here is Rails 3 port of the notifier.
11+
12+
The notifier sends an email after application deployment has been completed.
13+
14+
How to use it?
15+
16+
1. Add this file to config/deploy folder.
17+
2. Update the file with your google credentials and from email address.
18+
3. Add the following content to config/deploy.rb.
19+
20+
require 'config/deploy/cap_notify.rb'
21+
22+
# add email addresses for people who should receive deployment notifications
23+
set :notify_emails, ["[email protected]", "[email protected]"]
24+
25+
after :deploy, 'deploy:send_notification'
26+
27+
# Create task to send a notification
28+
namespace :deploy do
29+
desc "Send email notification"
30+
task :send_notification do
31+
Notifier.deploy_notification(self).deliver
32+
end
33+
end
34+
35+
4. Update deploy.rb with destination email addresses for the notifications.
36+
5. To test run this command:
37+
38+
cap deploy:send_notification
39+
40+
=end
41+
42+
require "action_mailer"
43+
44+
ActionMailer::Base.delivery_method = :smtp
45+
#ActionMailer::Base.default_url_options = {:host => 'localhost:3000'}
46+
#config.action_mailer.default_url_options = {:host => 'localhost:3000'}
47+
ActionMailer::Base.default :charset => "utf-8"
48+
49+
ActionMailer::Base.smtp_settings = {
50+
address: "smtp.mailgun.org",
51+
port: 25,
52+
domain: "rs9499.mailgun.org",
53+
authentication: :login,
54+
user_name: '[email protected]',
55+
password: '6vw8xeiho5s9',
56+
enable_starttls_auto: true
57+
}
58+
59+
class Notifier < ActionMailer::Base
60+
default :from => "[email protected]"
61+
62+
def deploy_notification(cap_vars)
63+
now = Time.now
64+
subject = "#{`sh -c 'git log -i -1 --pretty="format:%an <%ae>" --author="$1"'`.rstrip} Performed a deploy operation on #{now.strftime("%m/%d/%Y")} at #{now.strftime("%I:%M %p")} to #{cap_vars.host}"
65+
@change_log = "HERE IS THE LAST 10 COMMIT MESSAGES\n\n" + `git log --stat -n 10`
66+
mail(:to => cap_vars.notify_emails, :subject => subject, :body => @change_log)
67+
end
68+
end

0 commit comments

Comments
 (0)