relevance-cap_gun 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +84 -0
- data/Rakefile +20 -0
- data/cap_gun.gemspec +97 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/cap_gun.rb +156 -0
- data/manifest.txt +16 -0
- data/spec/cap_gun_spec.rb +130 -0
- data/tasks/cap_bot_tasks.rake +4 -0
- data/vendor/action_mailer_tls/README +19 -0
- data/vendor/action_mailer_tls/init.rb +1 -0
- data/vendor/action_mailer_tls/lib/smtp_tls.rb +65 -0
- data/vendor/action_mailer_tls/sample/mailer.yml.sample +6 -0
- data/vendor/action_mailer_tls/sample/smtp_gmail.rb +12 -0
- metadata +94 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
v0.0.4. Add dev dependency on echoe; update manifest
|
2
|
+
|
3
|
+
v0.0.3. Don't try to convert the RAILS_ENV if its not set to better support default capistrano deployments
|
4
|
+
|
5
|
+
v0.0.2. Converts the release times to the current time zone; improved docs.
|
6
|
+
|
7
|
+
v0.0.1. Initial release. Rock n roll mcdonalds.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Relevance, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= CapGun
|
2
|
+
|
3
|
+
== DESCRIPTION
|
4
|
+
|
5
|
+
Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
6
|
+
|
7
|
+
Drop your ActionMailer configuration information into your deploy.rb file, configure recipients for the deployment notifications, and setup the callback task.
|
8
|
+
|
9
|
+
Setup and configuration are done entirely inside your deploy.rb file to keep it super simple. Your emails are sent locally from the box performing the deployment, but CapGun queries the server to grab the necessary release info.
|
10
|
+
|
11
|
+
This even includes the Net::SMTP TLS hack inside as a vendored dependancy to allow super easy email sending without setting up an MTA.
|
12
|
+
|
13
|
+
== CONFIG
|
14
|
+
|
15
|
+
In your Capistrano config file (usually deploy.rb):
|
16
|
+
|
17
|
+
# require cap_gun (the path will depend on where you unpacked or if you are just using it as a gem)
|
18
|
+
require 'vendor/plugins/cap_gun/lib/cap_gun' # typical Rails vendor/plugins location
|
19
|
+
|
20
|
+
# setup action mailer with a hash of options
|
21
|
+
set :cap_gun_action_mailer_config, {
|
22
|
+
:address => "smtp.gmail.com",
|
23
|
+
:port => 587,
|
24
|
+
:user_name => "[YOUR_USERNAME]@gmail.com",
|
25
|
+
:password => "[YOUR_PASSWORD]",
|
26
|
+
:authentication => :plain
|
27
|
+
}
|
28
|
+
|
29
|
+
# define the options for the actual emails that go out -- :recipients is the only required option
|
30
|
+
set :cap_gun_email_envelope, { :recipients => %w[joe@example.com, jane@example.com] }
|
31
|
+
|
32
|
+
# register email as a callback after restart
|
33
|
+
after "deploy:restart", "cap_gun:email"
|
34
|
+
|
35
|
+
# Test everything out by running "cap cap_gun:email"
|
36
|
+
|
37
|
+
== REQUIREMENTS
|
38
|
+
|
39
|
+
* Capistrano 2+
|
40
|
+
* A Gmail account to send from, or an MTA (mail transport agent) installed locally to send from
|
41
|
+
* Something to deploy
|
42
|
+
|
43
|
+
== TODO & KNOWN ISSUES
|
44
|
+
|
45
|
+
* displays the release times in UTC (Capistrano default) - could be flipped to specified time zone
|
46
|
+
* some stuff will probably break on windows
|
47
|
+
|
48
|
+
== INSTALL
|
49
|
+
|
50
|
+
* sudo gem install cap_gun and gem unpack into your vendor/plugins
|
51
|
+
* or just grab the tarball from github (see below)
|
52
|
+
|
53
|
+
|
54
|
+
== URLS
|
55
|
+
|
56
|
+
* Log bugs, issues, and suggestions on Trac: http://opensource.thinkrelevance.com/wiki/cap_gun
|
57
|
+
* View source: http://github.com/relevance/cap_gun/tree/master
|
58
|
+
* Git: git clone git://github.com/relevance/cap_gun.git
|
59
|
+
* RDocs: http://thinkrelevance.rubyforge.org/cap_gun/
|
60
|
+
|
61
|
+
== LICENSE
|
62
|
+
|
63
|
+
(The MIT License)
|
64
|
+
|
65
|
+
Copyright (c) 2008 Relevance, Inc. - http://thinkrelevance.com
|
66
|
+
|
67
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
68
|
+
a copy of this software and associated documentation files (the
|
69
|
+
'Software'), to deal in the Software without restriction, including
|
70
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
71
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
72
|
+
permit persons to whom the Software is furnished to do so, subject to
|
73
|
+
the following conditions:
|
74
|
+
|
75
|
+
The above copyright notice and this permission notice shall be
|
76
|
+
included in all copies or substantial portions of the Software.
|
77
|
+
|
78
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
79
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
80
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
81
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
82
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
83
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
84
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'echoe'
|
3
|
+
require './lib/cap_gun.rb'
|
4
|
+
|
5
|
+
echoe = Echoe.new('cap_gun') do |p|
|
6
|
+
p.rubyforge_name = 'thinkrelevance'
|
7
|
+
p.author = ["Rob Sanheim", "Relevance"]
|
8
|
+
p.email = 'opensource@thinkrelevance.com'
|
9
|
+
p.version = CapGun::VERSION
|
10
|
+
p.summary = "Bang! You're deployed!"
|
11
|
+
p.description = 'Super simple capistrano deployments.'
|
12
|
+
p.url = "http://opensource.thinkrelevance.com/wiki/cap_gun"
|
13
|
+
p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc|CHANGELOG|MIT-LICENSE$/
|
14
|
+
rdoc_template = `allison --path`.strip << ".rb"
|
15
|
+
p.rdoc_template = rdoc_template
|
16
|
+
p.test_pattern = 'spec/**/*_spec.rb'
|
17
|
+
p.manifest_name = 'manifest.txt'
|
18
|
+
end
|
19
|
+
|
20
|
+
echoe.spec.add_development_dependency "echoe"
|
data/cap_gun.gemspec
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Cap_gun-0.0.4
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
--- !ruby/object:Gem::Specification
|
6
|
+
name: cap_gun
|
7
|
+
version: !ruby/object:Gem::Version
|
8
|
+
version: 0.0.4
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Rob Sanheim, Relevance
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
|
15
|
+
date: 2008-06-30 00:00:00 -04:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: echoe
|
20
|
+
type: :development
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: "0"
|
27
|
+
version:
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: echoe
|
30
|
+
type: :development
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: "0"
|
37
|
+
version:
|
38
|
+
description: Super simple capistrano deployments.
|
39
|
+
email: opensource@thinkrelevance.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- CHANGELOG
|
46
|
+
- lib/cap_gun.rb
|
47
|
+
- MIT-LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
files:
|
50
|
+
- cap_gun.gemspec
|
51
|
+
- CHANGELOG
|
52
|
+
- init.rb
|
53
|
+
- install.rb
|
54
|
+
- lib/cap_gun.rb
|
55
|
+
- manifest.txt
|
56
|
+
- MIT-LICENSE
|
57
|
+
- Rakefile
|
58
|
+
- README.rdoc
|
59
|
+
- spec/cap_gun_spec.rb
|
60
|
+
- tasks/cap_bot_tasks.rake
|
61
|
+
- vendor/action_mailer_tls/init.rb
|
62
|
+
- vendor/action_mailer_tls/lib/smtp_tls.rb
|
63
|
+
- vendor/action_mailer_tls/README
|
64
|
+
- vendor/action_mailer_tls/sample/mailer.yml.sample
|
65
|
+
- vendor/action_mailer_tls/sample/smtp_gmail.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://opensource.thinkrelevance.com/wiki/cap_gun
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --line-numbers
|
71
|
+
- --inline-source
|
72
|
+
- --title
|
73
|
+
- Cap_gun
|
74
|
+
- --main
|
75
|
+
- README.rdoc
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "1.2"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project: thinkrelevance
|
93
|
+
rubygems_version: 1.2.0
|
94
|
+
specification_version: 2
|
95
|
+
summary: Bang! You're deployed!
|
96
|
+
test_files:
|
97
|
+
- spec/cap_gun_spec.rb
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/cap_gun.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'action_mailer'
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib smtp_tls])
|
4
|
+
|
5
|
+
# Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
6
|
+
#
|
7
|
+
# We include the ActionMailer hack to play nice with Gmail, so that's a super easy way
|
8
|
+
# to do this without setting up your own MTA.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# Want to just shoot everyone an email about the latest status?
|
13
|
+
#
|
14
|
+
# cap cap_gun:email
|
15
|
+
#
|
16
|
+
# Include comments?
|
17
|
+
#
|
18
|
+
# cap -s comment="hi mom" cap_gun:email
|
19
|
+
#
|
20
|
+
# Enable emails after every deploy by adding this to your deploy.rb:
|
21
|
+
#
|
22
|
+
# after "deploy", "cap_gun:email"
|
23
|
+
#
|
24
|
+
# Now, next time you deploy, you can optionally include comments:
|
25
|
+
#
|
26
|
+
# cap -s comment="fix for bug #303" deploy
|
27
|
+
#
|
28
|
+
# See README for full install/config instructions.
|
29
|
+
module CapGun
|
30
|
+
VERSION = '0.0.4'
|
31
|
+
|
32
|
+
module Helper
|
33
|
+
|
34
|
+
# Loads ActionMailer settings from a Capistrano variable called "cap_gun_action_mailer_config"
|
35
|
+
def load_mailer_config(cap)
|
36
|
+
raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config
|
37
|
+
raise ArgumentError, "Need at least one recipient." if !cap.exists?(:cap_gun_email_envelope) || cap[:cap_gun_email_envelope][:recipients].blank?
|
38
|
+
|
39
|
+
ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
|
40
|
+
end
|
41
|
+
|
42
|
+
# Current user - unsupported on Windows, patches welcome
|
43
|
+
def current_user
|
44
|
+
platform.include?('mswin') ? nil : `id -un`.strip
|
45
|
+
end
|
46
|
+
|
47
|
+
# stub hook purposes only
|
48
|
+
def platform
|
49
|
+
RUBY_PLATFORM
|
50
|
+
end
|
51
|
+
|
52
|
+
# Gives you a prettier date/time for output from the standard Capistrano timestamped release directory.
|
53
|
+
# This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
|
54
|
+
# machine timezone.
|
55
|
+
def humanize_release_time(path)
|
56
|
+
return unless path
|
57
|
+
match = path.match(/(\d+)$/)
|
58
|
+
return unless match
|
59
|
+
local = convert_from_utc(match[1])
|
60
|
+
local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip
|
61
|
+
end
|
62
|
+
|
63
|
+
# Use some DateTime magicrey to convert UTC to the current time zone
|
64
|
+
# When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
|
65
|
+
def convert_from_utc(timestamp)
|
66
|
+
# we know Capistrano release timestamps are UTC, but Ruby doesn't, so make it explicit
|
67
|
+
utc_time = timestamp << "UTC"
|
68
|
+
datetime = DateTime.parse(utc_time)
|
69
|
+
datetime.new_offset(local_datetime_zone_offset)
|
70
|
+
end
|
71
|
+
|
72
|
+
def local_datetime_zone_offset
|
73
|
+
@local_datetime_zone_offset ||= DateTime.now.offset
|
74
|
+
end
|
75
|
+
|
76
|
+
def local_timezone
|
77
|
+
@current_timezone ||= Time.now.zone
|
78
|
+
end
|
79
|
+
|
80
|
+
extend self
|
81
|
+
end
|
82
|
+
|
83
|
+
# This mailer is configured with a capistrano variable called "cap_gun_email_envelope"
|
84
|
+
class Mailer < ActionMailer::Base
|
85
|
+
include CapGun::Helper
|
86
|
+
DEFAULT_SENDER = %("CapGun" <cap_gun@example.com>)
|
87
|
+
DEFAULT_EMAIL_PREFIX = "[DEPLOY] "
|
88
|
+
|
89
|
+
adv_attr_accessor :email_prefix
|
90
|
+
attr_accessor :summary
|
91
|
+
|
92
|
+
# Grab the options for emailing from cap_gun_email_envelope (should be set in your deploy file)
|
93
|
+
#
|
94
|
+
# Valid options:
|
95
|
+
# :recipients (required) an array or string of email address(es) that should get notifications
|
96
|
+
# :from the sender of the notification, defaults to cap_gun@example.com
|
97
|
+
# :email_prefix subject prefix, defaults to [DEPLOY]
|
98
|
+
def init(envelope = {})
|
99
|
+
recipients envelope[:recipients]
|
100
|
+
from (envelope[:from] || DEFAULT_SENDER)
|
101
|
+
email_prefix (envelope[:email_prefix] || DEFAULT_EMAIL_PREFIX)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Do the actual email
|
105
|
+
def deployment_notification(capistrano)
|
106
|
+
init(capistrano[:cap_gun_email_envelope])
|
107
|
+
self.summary = create_summary(capistrano)
|
108
|
+
|
109
|
+
content_type "text/plain"
|
110
|
+
subject "#{email_prefix} #{capistrano[:application]} deployed to #{capistrano[:rails_env]}"
|
111
|
+
body create_body(capistrano)
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_summary(capistrano)
|
115
|
+
%[#{capistrano[:application]} was deployed#{" to " << capistrano[:rails_env] if capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Create the body of the message using a bunch of values from Capistrano
|
119
|
+
def create_body(capistrano)
|
120
|
+
<<-EOL
|
121
|
+
#{summary}
|
122
|
+
|
123
|
+
Comment: #{capistrano[:comment] || "[none given]"}
|
124
|
+
|
125
|
+
Nerd details
|
126
|
+
============
|
127
|
+
Release: #{capistrano[:current_release]}
|
128
|
+
Release Time: #{humanize_release_time(capistrano[:current_release])}
|
129
|
+
Release Revision: #{capistrano[:current_revision]}
|
130
|
+
|
131
|
+
Previous Release: #{capistrano[:previous_release]}
|
132
|
+
Previous Release Time: #{humanize_release_time(capistrano[:previous_release])}
|
133
|
+
Previous Release Revision: #{capistrano[:previous_revision]}
|
134
|
+
|
135
|
+
Repository: #{capistrano[:repository]}
|
136
|
+
Deploy path: #{capistrano[:deploy_to]}
|
137
|
+
EOL
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
if Object.const_defined?("Capistrano")
|
144
|
+
|
145
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
146
|
+
|
147
|
+
namespace :cap_gun do
|
148
|
+
desc "Send notification of the current release and the previous release via email."
|
149
|
+
task :email do
|
150
|
+
CapGun::Helper.load_mailer_config(self)
|
151
|
+
CapGun::Mailer.deliver_deployment_notification(self)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
data/manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
cap_gun.gemspec
|
2
|
+
CHANGELOG
|
3
|
+
init.rb
|
4
|
+
install.rb
|
5
|
+
lib/cap_gun.rb
|
6
|
+
manifest.txt
|
7
|
+
MIT-LICENSE
|
8
|
+
Rakefile
|
9
|
+
README.rdoc
|
10
|
+
spec/cap_gun_spec.rb
|
11
|
+
tasks/cap_bot_tasks.rake
|
12
|
+
vendor/action_mailer_tls/init.rb
|
13
|
+
vendor/action_mailer_tls/lib/smtp_tls.rb
|
14
|
+
vendor/action_mailer_tls/README
|
15
|
+
vendor/action_mailer_tls/sample/mailer.yml.sample
|
16
|
+
vendor/action_mailer_tls/sample/smtp_gmail.rb
|
@@ -0,0 +1,130 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'test/spec'
|
5
|
+
require 'mocha'
|
6
|
+
require 'net/smtp'
|
7
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib cap_gun])
|
8
|
+
|
9
|
+
describe "CapGun" do
|
10
|
+
it "uses action mailer hack" do
|
11
|
+
Net::SMTP.new('').respond_to?(:starttls, true).should == true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "CapGun" do
|
16
|
+
|
17
|
+
describe "mail settings" do
|
18
|
+
include CapGun::Helper
|
19
|
+
|
20
|
+
it "raises if we don't have settings" do
|
21
|
+
capistrano = stub_everything
|
22
|
+
lambda { CapGun::Helper.load_mailer_config(capistrano) }.should.raise(ArgumentError).message.should == "You must define ActionMailer settings in 'cap_gun_action_mailer_config'"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "gets action mailer config from capistrano" do
|
26
|
+
capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"}, :exists? => true)
|
27
|
+
capistrano.stubs(:[]).returns({:recipients => 'foo'})
|
28
|
+
CapGun::Helper.load_mailer_config(capistrano)
|
29
|
+
ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises if we have no cap gun email envelope" do
|
33
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :exists? => false)
|
34
|
+
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises if we don't have at least one recipient" do
|
38
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {})
|
39
|
+
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
40
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {:recipients => []})
|
41
|
+
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "misc helpers" do
|
47
|
+
include CapGun::Helper
|
48
|
+
|
49
|
+
it "returns nil for current user if platform is win32" do
|
50
|
+
expects(:platform).returns("mswin")
|
51
|
+
current_user.should.be nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should get current user from *nix id command" do
|
55
|
+
expects(:"`").with('id -un').returns("joe")
|
56
|
+
current_user
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "handling release time" do
|
62
|
+
include CapGun::Helper
|
63
|
+
|
64
|
+
before do # make DateTime act as if local timezone is EDT
|
65
|
+
stubs(:local_timezone).returns("EDT")
|
66
|
+
stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns nil for weird release path" do
|
70
|
+
humanize_release_time("/data/foo/my_release").should == nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "parse datetime from release path" do
|
74
|
+
humanize_release_time("/data/foo/releases/20080227120000").should == "February 27th, 2008 8:00 AM EDT"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "converts time from release into localtime" do
|
78
|
+
humanize_release_time("/data/foo/releases/20080410040000").should == "April 10th, 2008 12:00 AM EDT"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "Mailer" do
|
84
|
+
|
85
|
+
it "passes capistrano into create body" do
|
86
|
+
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
|
87
|
+
CapGun::Mailer.any_instance.expects(:create_body).with(capistrano).returns("foo")
|
88
|
+
CapGun::Mailer.create_deployment_notification capistrano
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "Mail envelope" do
|
94
|
+
before { CapGun::Mailer.any_instance.stubs(:create_body).returns("email body!") }
|
95
|
+
|
96
|
+
it "gets recipients from email envelope" do
|
97
|
+
capistrano = { :cap_gun_email_envelope => { :recipients => ["foo@here.com", "bar@here.com"] } }
|
98
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
99
|
+
mail.to.should == ["foo@here.com", "bar@here.com"]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should have a default sender" do
|
103
|
+
capistrano = { :cap_gun_email_envelope => { :recipients => "foo@here.com" } }
|
104
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
105
|
+
mail.from.should == ["cap_gun@example.com"]
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should override sender from email envelope" do
|
109
|
+
capistrano = { :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
|
110
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
111
|
+
mail.from.should == ["booyakka!@example.com"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "creating body" do
|
116
|
+
it "has a friendly summary line" do
|
117
|
+
capistrano = { :application => "my app", :rails_env => "staging", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
|
118
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
119
|
+
mail.body.split("\n").first.should == "my app was deployed to staging by rsanheim at February 27th, 2008 8:00 AM EDT."
|
120
|
+
end
|
121
|
+
|
122
|
+
it "does not include rails env in summary if not defined" do
|
123
|
+
capistrano = { :application => "my app", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
|
124
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
125
|
+
mail.body.split("\n").first.should == "my app was deployed by rsanheim at February 27th, 2008 8:00 AM EDT."
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
= SMTP_TLS + ActionMailer + Gmail
|
2
|
+
|
3
|
+
Configure Rails To Use Gmail's SMTP
|
4
|
+
|
5
|
+
Originally from http://blog.pomozov.info/posts/how-to-send-actionmailer-mails-to-gmailcom.html
|
6
|
+
|
7
|
+
See "sample" directory for further instructions
|
8
|
+
|
9
|
+
== Resources
|
10
|
+
|
11
|
+
Blog post
|
12
|
+
|
13
|
+
* http://www.rubyinside.com/how-to-use-gmails-smtp-server-with-rails-394.html
|
14
|
+
|
15
|
+
* http://www.prestonlee.com/archives/63
|
16
|
+
|
17
|
+
== Author
|
18
|
+
|
19
|
+
* Marc Chung - marc [dot] chung [at] openrain [dot] com
|
@@ -0,0 +1 @@
|
|
1
|
+
require_dependency 'smtp_tls'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "net/smtp"
|
3
|
+
|
4
|
+
Net::SMTP.class_eval do
|
5
|
+
private
|
6
|
+
def do_start(helodomain, user, secret, authtype)
|
7
|
+
raise IOError, 'SMTP session already started' if @started
|
8
|
+
check_auth_args user, secret, authtype if user or secret
|
9
|
+
|
10
|
+
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
|
11
|
+
@socket = Net::InternetMessageIO.new(sock)
|
12
|
+
@socket.read_timeout = 60 #@read_timeout
|
13
|
+
|
14
|
+
check_response(critical { recv_response() })
|
15
|
+
do_helo(helodomain)
|
16
|
+
|
17
|
+
if starttls
|
18
|
+
raise 'openssl library not installed' unless defined?(OpenSSL)
|
19
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
|
20
|
+
ssl.sync_close = true
|
21
|
+
ssl.connect
|
22
|
+
@socket = Net::InternetMessageIO.new(ssl)
|
23
|
+
@socket.read_timeout = 60 #@read_timeout
|
24
|
+
do_helo(helodomain)
|
25
|
+
end
|
26
|
+
|
27
|
+
authenticate user, secret, authtype if user
|
28
|
+
@started = true
|
29
|
+
ensure
|
30
|
+
unless @started
|
31
|
+
# authentication failed, cancel connection.
|
32
|
+
@socket.close if not @started and @socket and not @socket.closed?
|
33
|
+
@socket = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def do_helo(helodomain)
|
38
|
+
begin
|
39
|
+
if @esmtp
|
40
|
+
ehlo helodomain
|
41
|
+
else
|
42
|
+
helo helodomain
|
43
|
+
end
|
44
|
+
rescue Net::ProtocolError
|
45
|
+
if @esmtp
|
46
|
+
@esmtp = false
|
47
|
+
@error_occured = false
|
48
|
+
retry
|
49
|
+
end
|
50
|
+
raise
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def starttls
|
55
|
+
getok('STARTTLS') rescue return false
|
56
|
+
return true
|
57
|
+
end
|
58
|
+
|
59
|
+
def quit
|
60
|
+
begin
|
61
|
+
getok('QUIT')
|
62
|
+
rescue EOFError
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#
|
2
|
+
# For Rails 2.x:
|
3
|
+
# A copy of this file should be placed in RAILS_ROOT/initializers/
|
4
|
+
# A file named mailer.yml should be placed in RAILS_ROOT/config/
|
5
|
+
# See mailer.yml.sample
|
6
|
+
#
|
7
|
+
|
8
|
+
require "smtp_tls"
|
9
|
+
|
10
|
+
mailer_config = File.open("#{RAILS_ROOT}/config/mailer.yml")
|
11
|
+
mailer_options = YAML.load(mailer_config)
|
12
|
+
ActionMailer::Base.smtp_settings = mailer_options
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: relevance-cap_gun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Sanheim, Relevance
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
date: 2008-06-29 21:00:00 -07:00
|
12
|
+
default_executable:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: echoe
|
16
|
+
type: :development
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: echoe
|
26
|
+
type: :development
|
27
|
+
version_requirement:
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: "0"
|
33
|
+
version:
|
34
|
+
description: Super simple capistrano deployments.
|
35
|
+
email: opensource@thinkrelevance.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- CHANGELOG
|
42
|
+
- lib/cap_gun.rb
|
43
|
+
- MIT-LICENSE
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- cap_gun.gemspec
|
47
|
+
- CHANGELOG
|
48
|
+
- init.rb
|
49
|
+
- install.rb
|
50
|
+
- lib/cap_gun.rb
|
51
|
+
- manifest.txt
|
52
|
+
- MIT-LICENSE
|
53
|
+
- Rakefile
|
54
|
+
- README.rdoc
|
55
|
+
- spec/cap_gun_spec.rb
|
56
|
+
- tasks/cap_bot_tasks.rake
|
57
|
+
- vendor/action_mailer_tls/init.rb
|
58
|
+
- vendor/action_mailer_tls/lib/smtp_tls.rb
|
59
|
+
- vendor/action_mailer_tls/README
|
60
|
+
- vendor/action_mailer_tls/sample/mailer.yml.sample
|
61
|
+
- vendor/action_mailer_tls/sample/smtp_gmail.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://opensource.thinkrelevance.com/wiki/cap_gun
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --line-numbers
|
67
|
+
- --inline-source
|
68
|
+
- --title
|
69
|
+
- Cap_gun
|
70
|
+
- --main
|
71
|
+
- README.rdoc
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "1.2"
|
85
|
+
version:
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: thinkrelevance
|
89
|
+
rubygems_version: 1.2.0
|
90
|
+
signing_key:
|
91
|
+
specification_version: 2
|
92
|
+
summary: Bang! You're deployed!
|
93
|
+
test_files:
|
94
|
+
- spec/cap_gun_spec.rb
|