cap_gun_reloaded 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +12 -0
- data/.gitignore +3 -0
- data/CHANGELOG +17 -0
- data/README.markdown +100 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/cap_gun_reloaded.gemspec +65 -0
- data/examples/cap_gun_example.rb +66 -0
- data/examples/example_helper.rb +19 -0
- data/examples/presenter_example.rb +86 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/cap_gun/presenter.rb +133 -0
- data/lib/cap_gun_reloaded.rb +75 -0
- data/manifest.txt +16 -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 +71 -0
- data/vendor/action_mailer_tls/sample/mailer.yml.sample +6 -0
- data/vendor/action_mailer_tls/sample/smtp_gmail.rb +12 -0
- data/version.yml +4 -0
- metadata +100 -0
data/.autotest
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'autotest/menu'
|
2
|
+
|
3
|
+
Autotest.add_hook :initialize do |at|
|
4
|
+
at.clear_mappings
|
5
|
+
|
6
|
+
at.add_mapping(%r%lib/(.*)\.rb$%) { |filename, match|
|
7
|
+
at.files_matching %r%^spec/#{match[1]}.*\.rb$%
|
8
|
+
}
|
9
|
+
at.add_mapping(%r%^spec/.*\.rb$%) { |filename, match|
|
10
|
+
filename
|
11
|
+
}
|
12
|
+
end
|
data/.gitignore
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
v0.0.9 Ruby 1.8.7 support via a small change to the Net::SMTP SSL hack
|
2
|
+
|
3
|
+
v0.0.8. Fix failing spec on runcoderun that depended on timezone; add redgreen to specs
|
4
|
+
|
5
|
+
v0.0.7. Pick up changelog and gemspec
|
6
|
+
|
7
|
+
v0.0.6. Fix subject line if there *is* a rails_env defined - this was a bug introduced with the 0.0.5 'fix'. Awesome.
|
8
|
+
|
9
|
+
v0.0.5. Fix subject line iv there is no rails_env defined
|
10
|
+
|
11
|
+
v0.0.4. Add dev dependency on echoe; update manifest
|
12
|
+
|
13
|
+
v0.0.3. Don't try to convert the RAILS_ENV if its not set to better support default capistrano deployments
|
14
|
+
|
15
|
+
v0.0.2. Converts the release times to the current time zone; improved docs.
|
16
|
+
|
17
|
+
v0.0.1. Initial release. Rock n roll mcdonalds.
|
data/README.markdown
ADDED
@@ -0,0 +1,100 @@
|
|
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, {
|
31
|
+
:from => "project.deployer@example.com", # Note, don't use the form "Someone project.deploy@example.com" as it'll blow up with ActionMailer 2.3+
|
32
|
+
:recipients => %w[joe@example.com, jane@example.com]
|
33
|
+
}
|
34
|
+
|
35
|
+
# register email as a callback after restart
|
36
|
+
after "deploy:restart", "cap_gun:email"
|
37
|
+
|
38
|
+
# Test everything out by running "cap cap_gun:email"
|
39
|
+
|
40
|
+
## USAGE
|
41
|
+
|
42
|
+
Good news: it just works.
|
43
|
+
|
44
|
+
By default CapGun includes info like the user who is deploying and what server its being deployed to. CapGun is biased for git (patches accepted for other SCMs), so it will include details like your current branch, the revisions since last deployment, the current commit being deployed.
|
45
|
+
|
46
|
+
Want to make the notifications even better and explain _why_ you're deploying?
|
47
|
+
Just include a comment in the cap command like so, and CapGun will add the comment to the email notification.
|
48
|
+
|
49
|
+
cap -s comment="fix for bug #303" deploy
|
50
|
+
|
51
|
+
## REQUIREMENTS
|
52
|
+
|
53
|
+
* Capistrano 2+
|
54
|
+
* A Gmail account to send from, or an MTA (mail transport agent) installed locally to send from
|
55
|
+
* Something to deploy
|
56
|
+
|
57
|
+
## TODO & KNOWN ISSUES
|
58
|
+
|
59
|
+
* displays the release times in UTC (Capistrano default) - could be flipped to specified time zone
|
60
|
+
* some stuff will probably break on windows - patches welcome
|
61
|
+
|
62
|
+
## INSTALL
|
63
|
+
|
64
|
+
* `sudo gem install cap_gun` and gem unpack into your vendor/plugins
|
65
|
+
* or just grab the tarball from github (see below)
|
66
|
+
|
67
|
+
## URLS
|
68
|
+
|
69
|
+
* Log bugs, issues, and suggestions at GitHub: http://github.com/relevance/cap_gun/issues
|
70
|
+
* View source: http://github.com/relevance/cap_gun
|
71
|
+
* Continuos Integration: http://runcoderun.com/relevance/cap_gun
|
72
|
+
* RDocs: http://thinkrelevance.rubyforge.org/cap_gun
|
73
|
+
|
74
|
+
== LICENSE
|
75
|
+
|
76
|
+
(The MIT License)
|
77
|
+
|
78
|
+
Copyright (c) 2009 Relevance, Inc. - http://thinkrelevance.com
|
79
|
+
|
80
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
81
|
+
a copy of this software and associated documentation files (the
|
82
|
+
'Software'), to deal in the Software without restriction, including
|
83
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
84
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
85
|
+
permit persons to whom the Software is furnished to do so, subject to
|
86
|
+
the following conditions:
|
87
|
+
|
88
|
+
The above copyright notice and this permission notice shall be
|
89
|
+
included in all copies or substantial portions of the Software.
|
90
|
+
|
91
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
92
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
93
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
94
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
95
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
96
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
97
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
98
|
+
|
99
|
+
|
100
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "cap_gun"
|
5
|
+
gemspec.summary = "Bang! You're deployed."
|
6
|
+
gemspec.email = "opensource@thinkrelevance.com"
|
7
|
+
gemspec.homepage = "http://github.com/relevance/cap_gun"
|
8
|
+
gemspec.description = 'Super simple capistrano deployment notifications.'
|
9
|
+
gemspec.authors = ["Rob Sanheim", "Muness Alrubaie", "Relevance"]
|
10
|
+
gemspec.add_development_dependency "micronaut"
|
11
|
+
gemspec.add_development_dependency "mocha"
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'micronaut/rake_task'
|
20
|
+
Micronaut::RakeTask.new(:examples) do |examples|
|
21
|
+
examples.pattern = 'examples/**/*_example.rb'
|
22
|
+
examples.ruby_opts << '-Ilib -Iexamples'
|
23
|
+
end
|
24
|
+
|
25
|
+
Micronaut::RakeTask.new(:rcov) do |examples|
|
26
|
+
examples.pattern = 'examples/**/*_example.rb'
|
27
|
+
examples.rcov_opts = %[-Ilib -Iexamples --exclude "gems/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
|
28
|
+
examples.rcov = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if RUBY_VERSION =~ /1.8/
|
33
|
+
task :default => [:check_dependencies, :rcov]
|
34
|
+
else
|
35
|
+
task :default => [:check_dependencies, :examples]
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
%w{sdoc sdoc-helpers rdiscount}.each { |name| gem name }
|
40
|
+
require 'sdoc_helpers'
|
41
|
+
rescue LoadError => ex
|
42
|
+
puts "sdoc support not enabled:"
|
43
|
+
puts ex.inspect
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "cap_gun #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{cap_gun_reloaded}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Rob Sanheim", "Muness Alrubaie", "Relevance", "Leigh Caplan"]
|
9
|
+
s.date = %q{2009-06-21}
|
10
|
+
s.description = %q{Super simple capistrano deployment notifications.}
|
11
|
+
s.email = %q{opensource@thinkrelevance.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.markdown"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".autotest",
|
17
|
+
".gitignore",
|
18
|
+
"CHANGELOG",
|
19
|
+
"README.markdown",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"cap_gun_reloaded.gemspec",
|
23
|
+
"examples/cap_gun_example.rb",
|
24
|
+
"examples/example_helper.rb",
|
25
|
+
"examples/presenter_example.rb",
|
26
|
+
"init.rb",
|
27
|
+
"install.rb",
|
28
|
+
"lib/cap_gun_reloaded.rb",
|
29
|
+
"lib/cap_gun/presenter.rb",
|
30
|
+
"manifest.txt",
|
31
|
+
"tasks/cap_bot_tasks.rake",
|
32
|
+
"vendor/action_mailer_tls/README",
|
33
|
+
"vendor/action_mailer_tls/init.rb",
|
34
|
+
"vendor/action_mailer_tls/lib/smtp_tls.rb",
|
35
|
+
"vendor/action_mailer_tls/sample/mailer.yml.sample",
|
36
|
+
"vendor/action_mailer_tls/sample/smtp_gmail.rb",
|
37
|
+
"version.yml"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/texel/cap_gun_reloaded}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.4}
|
43
|
+
s.summary = %q{Bang! You're deployed. And you work with Onehub's deploy strategy!}
|
44
|
+
s.test_files = [
|
45
|
+
"examples/cap_gun_example.rb",
|
46
|
+
"examples/example_helper.rb",
|
47
|
+
"examples/presenter_example.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<spicycode-micronaut>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<spicycode-micronaut>, [">= 0"])
|
59
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<spicycode-micronaut>, [">= 0"])
|
63
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[example_helper])
|
2
|
+
|
3
|
+
describe CapGun do
|
4
|
+
|
5
|
+
it "uses action mailer hack" do
|
6
|
+
Net::SMTP.new('').respond_to?(:starttls, true).should == true
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "mail settings" do
|
10
|
+
|
11
|
+
it "raises if we don't have settings" do
|
12
|
+
capistrano = stub_everything
|
13
|
+
lambda {
|
14
|
+
CapGun::Mailer.load_mailer_config(capistrano)
|
15
|
+
}.should raise_error(ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets action mailer config from capistrano" do
|
19
|
+
capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"}, :exists? => true)
|
20
|
+
capistrano.stubs(:[]).returns({:recipients => 'foo'})
|
21
|
+
CapGun::Mailer.load_mailer_config(capistrano)
|
22
|
+
ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises if don't have a cap gun email envelope" do
|
26
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :exists? => false)
|
27
|
+
lambda {
|
28
|
+
CapGun::Mailer.load_mailer_config capistrano
|
29
|
+
}.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises if we don't have at least one recipient" do
|
33
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {})
|
34
|
+
lambda {
|
35
|
+
CapGun::Mailer.load_mailer_config capistrano
|
36
|
+
}.should raise_error(ArgumentError)
|
37
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {:recipients => []})
|
38
|
+
lambda {
|
39
|
+
CapGun::Mailer.load_mailer_config capistrano
|
40
|
+
}.should raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe CapGun::Mailer do
|
46
|
+
|
47
|
+
it "calls Net::SMTP to send the mail correctly (we test this because SMTP internals changed between 1.8.6 and newer versions of Ruby)" do
|
48
|
+
ActionMailer::Base.smtp_settings = {
|
49
|
+
:address => "smtp.gmail.com",
|
50
|
+
:port => 587,
|
51
|
+
:domain => "foo.com",
|
52
|
+
:authentication => :plain,
|
53
|
+
:user_name => "username",
|
54
|
+
:password => "password"
|
55
|
+
}
|
56
|
+
|
57
|
+
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
|
58
|
+
smtp = Net::SMTP.new('gmail.com', 25)
|
59
|
+
Net::SMTP.expects(:new).returns(smtp)
|
60
|
+
smtp.expects(:start)
|
61
|
+
CapGun::Mailer.deliver_deployment_notification capistrano
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'net/smtp'
|
3
|
+
require "mocha"
|
4
|
+
require 'micronaut'
|
5
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib cap_gun_reloaded])
|
6
|
+
|
7
|
+
def silence_warnings
|
8
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
$VERBOSE = old_verbose
|
12
|
+
end
|
13
|
+
|
14
|
+
Micronaut.configure do |config|
|
15
|
+
config.mock_with :mocha
|
16
|
+
config.formatter = :documentation
|
17
|
+
config.color_enabled = true
|
18
|
+
config.filter_run :options => { :focused => true }
|
19
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[example_helper])
|
2
|
+
|
3
|
+
describe CapGun::Presenter do
|
4
|
+
|
5
|
+
describe "git details" do
|
6
|
+
|
7
|
+
it "does nothing if git is not the scm" do
|
8
|
+
presenter = CapGun::Presenter.new(stub("capistrano", :scm => :svn))
|
9
|
+
presenter.git_details.should == nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "collects branch and git log details if git is scm" do
|
13
|
+
capistrano = {:scm => :git, :branch => "edge"}
|
14
|
+
presenter = CapGun::Presenter.new(capistrano)
|
15
|
+
presenter.expects(:git_log).returns("xxxxx")
|
16
|
+
|
17
|
+
details = presenter.git_details
|
18
|
+
details.should include("Branch: edge")
|
19
|
+
details.should include("xxxxx")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "git log messages" do
|
24
|
+
|
25
|
+
it "returns N/A if the git log call returns an error" do
|
26
|
+
capistrano = { :previous_revision => "previous-sha", :current_revision => "current-sha" }
|
27
|
+
presenter = CapGun::Presenter.new(capistrano)
|
28
|
+
presenter.stubs(:`).returns("fatal: Not a git repo")
|
29
|
+
presenter.stubs(:exit_code).returns(stub("process status", :success? => false))
|
30
|
+
presenter.git_log_messages.should == "N/A"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "calls git log with previous_rev..current_rev" do
|
34
|
+
capistrano = { :previous_revision => "previous-sha", :current_revision => "current-sha" }
|
35
|
+
presenter = CapGun::Presenter.new(capistrano)
|
36
|
+
presenter.stubs(:exit_code).returns(stub("process status", :success? => true))
|
37
|
+
presenter.expects(:`).with(includes("git log previous-sha..current-sha"))
|
38
|
+
presenter.git_log_messages
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "release time" do
|
43
|
+
|
44
|
+
before do # make DateTime act as if local timezone is CDT
|
45
|
+
@presenter = CapGun::Presenter.new(nil)
|
46
|
+
@presenter.stubs(:local_timezone).returns("CDT")
|
47
|
+
@presenter.stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns nil for weird release path" do
|
51
|
+
@presenter.humanize_release_time("/data/foo/my_release").should == nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "parse datetime from release path" do
|
55
|
+
@presenter.humanize_release_time("/data/foo/releases/20080227120000").should == "February 27th, 2008 8:00 AM CDT"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "converts time from release into localtime" do
|
59
|
+
@presenter.humanize_release_time("/data/foo/releases/20080410040000").should == "April 10th, 2008 12:00 AM CDT"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "from and to emails" do
|
65
|
+
|
66
|
+
it "gets recipients from email envelope" do
|
67
|
+
capistrano = { :cap_gun_email_envelope => { :recipients => ["foo@here.com", "bar@here.com"] } }
|
68
|
+
presenter = CapGun::Presenter.new(capistrano)
|
69
|
+
presenter.recipients.should == ["foo@here.com", "bar@here.com"]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have a default sender" do
|
73
|
+
capistrano = { :cap_gun_email_envelope => { } }
|
74
|
+
presenter = CapGun::Presenter.new(capistrano)
|
75
|
+
presenter.from.should == "\"CapGun\" <cap_gun@example.com>"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should override sender from email envelope" do
|
79
|
+
capistrano = { :cap_gun_email_envelope => { :from => "booyakka!@example.com" } }
|
80
|
+
presenter = CapGun::Presenter.new(capistrano)
|
81
|
+
presenter.from.should == "booyakka!@example.com"
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
module CapGun
|
4
|
+
class Presenter
|
5
|
+
DEFAULT_SENDER = %("CapGun" <cap_gun@example.com>)
|
6
|
+
DEFAULT_EMAIL_PREFIX = "[DEPLOY]"
|
7
|
+
|
8
|
+
attr_accessor :capistrano
|
9
|
+
|
10
|
+
def initialize(capistrano)
|
11
|
+
self.capistrano = capistrano
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def recipients
|
16
|
+
capistrano[:cap_gun_email_envelope][:recipients]
|
17
|
+
end
|
18
|
+
|
19
|
+
def email_prefix
|
20
|
+
capistrano[:cap_gun_email_envelope][:email_prefix] || DEFAULT_EMAIL_PREFIX
|
21
|
+
end
|
22
|
+
|
23
|
+
def from
|
24
|
+
capistrano[:cap_gun_email_envelope][:from] || DEFAULT_SENDER
|
25
|
+
end
|
26
|
+
|
27
|
+
def current_user
|
28
|
+
Etc.getlogin
|
29
|
+
end
|
30
|
+
|
31
|
+
def summary
|
32
|
+
%[#{capistrano[:application]} was #{deployed_to} by #{current_user} at #{release_time}.]
|
33
|
+
end
|
34
|
+
|
35
|
+
def deployed_to
|
36
|
+
return "deployed to #{capistrano[:rails_env]}" if capistrano[:rails_env]
|
37
|
+
"deployed"
|
38
|
+
end
|
39
|
+
|
40
|
+
def branch
|
41
|
+
"Branch: #{capistrano[:branch]}" unless capistrano[:branch].nil? || capistrano[:branch].empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
def git_details
|
45
|
+
return unless capistrano[:scm].to_sym == :git
|
46
|
+
<<-EOL
|
47
|
+
#{branch}
|
48
|
+
#{git_log}
|
49
|
+
EOL
|
50
|
+
rescue
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def git_log
|
55
|
+
"\nCommits since last release\n====================\n#{git_log_messages}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def git_log_messages
|
59
|
+
messages = `git log #{capistrano[:previous_revision]}..#{capistrano[:current_revision]} --pretty=format:%h:%s`
|
60
|
+
exit_code.success? ? messages : "N/A"
|
61
|
+
end
|
62
|
+
|
63
|
+
def exit_code
|
64
|
+
$?
|
65
|
+
end
|
66
|
+
|
67
|
+
# Gives you a prettier date/time for output from the standard Capistrano timestamped release directory.
|
68
|
+
# This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
|
69
|
+
# machine timezone.
|
70
|
+
def humanize_release_time(path)
|
71
|
+
return unless path
|
72
|
+
match = path.match(/(\d+)$/)
|
73
|
+
return unless match
|
74
|
+
local = convert_from_utc(match[1])
|
75
|
+
local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip
|
76
|
+
end
|
77
|
+
|
78
|
+
# Use some DateTime magicrey to convert UTC to the current time zone
|
79
|
+
# When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
|
80
|
+
def convert_from_utc(timestamp)
|
81
|
+
# we know Capistrano release timestamps are UTC, but Ruby doesn't, so make it explicit
|
82
|
+
utc_time = timestamp << "UTC"
|
83
|
+
datetime = DateTime.parse(utc_time)
|
84
|
+
datetime.new_offset(local_datetime_zone_offset)
|
85
|
+
end
|
86
|
+
|
87
|
+
def local_datetime_zone_offset
|
88
|
+
@local_datetime_zone_offset ||= DateTime.now.offset
|
89
|
+
end
|
90
|
+
|
91
|
+
def local_timezone
|
92
|
+
@current_timezone ||= Time.now.zone
|
93
|
+
end
|
94
|
+
|
95
|
+
def release_time
|
96
|
+
humanize_release_time(capistrano[:current_release])
|
97
|
+
end
|
98
|
+
|
99
|
+
def previous_release_time
|
100
|
+
humanize_release_time(capistrano[:previous_release])
|
101
|
+
end
|
102
|
+
|
103
|
+
def subject
|
104
|
+
"#{email_prefix} #{capistrano[:application]} #{deployed_to}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def comment
|
108
|
+
"Comment: #{capistrano[:comment]}.\n" if capistrano[:comment]
|
109
|
+
end
|
110
|
+
|
111
|
+
def body
|
112
|
+
<<-EOL
|
113
|
+
#{summary}
|
114
|
+
#{comment}
|
115
|
+
Deployment details
|
116
|
+
==================
|
117
|
+
Release: #{capistrano[:current_release]}
|
118
|
+
Release Time: #{release_time}
|
119
|
+
Release Revision: #{capistrano[:current_revision]}
|
120
|
+
|
121
|
+
Previous Release: #{capistrano[:previous_release]}
|
122
|
+
Previous Release Time: #{previous_release_time}
|
123
|
+
Previous Release Revision: #{capistrano[:previous_revision]}
|
124
|
+
|
125
|
+
Repository: #{capistrano[:repository]}
|
126
|
+
Deploy path: #{capistrano[:deploy_to]}
|
127
|
+
Domain: #{capistrano[:domain]}
|
128
|
+
#{git_details}
|
129
|
+
EOL
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[cap_gun presenter])
|
4
|
+
require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib smtp_tls])
|
5
|
+
|
6
|
+
# Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
7
|
+
#
|
8
|
+
# We include the ActionMailer hack to play nice with Gmail, so that's a super easy way
|
9
|
+
# to do this without setting up your own MTA.
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# Want to just shoot everyone an email about the latest status?
|
14
|
+
#
|
15
|
+
# cap cap_gun:email
|
16
|
+
#
|
17
|
+
# Include comments?
|
18
|
+
#
|
19
|
+
# cap -s comment="hi mom" cap_gun:email
|
20
|
+
#
|
21
|
+
# Enable emails after every deploy by adding this to your deploy.rb:
|
22
|
+
#
|
23
|
+
# after "deploy", "cap_gun:email"
|
24
|
+
#
|
25
|
+
# Now, next time you deploy, you can optionally include comments:
|
26
|
+
#
|
27
|
+
# cap -s comment="fix for bug #303" deploy
|
28
|
+
#
|
29
|
+
# See README for full install/config instructions.
|
30
|
+
module CapGun
|
31
|
+
VERSION = '0.0.11'
|
32
|
+
|
33
|
+
# This mailer is configured with a capistrano variable called "cap_gun_email_envelope"
|
34
|
+
class Mailer < ActionMailer::Base
|
35
|
+
|
36
|
+
def self.load_mailer_config(cap)
|
37
|
+
raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config
|
38
|
+
raise ArgumentError, "Need at least one recipient." if !cap.exists?(:cap_gun_email_envelope) || cap[:cap_gun_email_envelope][:recipients].blank?
|
39
|
+
|
40
|
+
ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
|
41
|
+
end
|
42
|
+
|
43
|
+
# Grab the options for emailing from capistrano[:cap_gun_email_envelope] (should be set in your deploy file)
|
44
|
+
#
|
45
|
+
# Valid options:
|
46
|
+
# :recipients (required) an array or string of email address(es) that should get notifications
|
47
|
+
# :from the sender of the notification, defaults to cap_gun@example.com
|
48
|
+
# :email_prefix subject prefix, defaults to [DEPLOY]
|
49
|
+
def deployment_notification(capistrano)
|
50
|
+
presenter = Presenter.new(capistrano)
|
51
|
+
|
52
|
+
content_type "text/plain"
|
53
|
+
from presenter.from
|
54
|
+
recipients presenter.recipients
|
55
|
+
subject presenter.subject
|
56
|
+
body presenter.body
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if Object.const_defined?("Capistrano")
|
63
|
+
|
64
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
65
|
+
|
66
|
+
namespace :cap_gun do
|
67
|
+
desc "Send notification of the current release and the previous release via email."
|
68
|
+
task :email, :roles => :app do
|
69
|
+
CapGun::Mailer.load_mailer_config(self)
|
70
|
+
CapGun::Mailer.deliver_deployment_notification(self)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
cap_gun_reloaded.gemspec
|
2
|
+
CHANGELOG
|
3
|
+
init.rb
|
4
|
+
install.rb
|
5
|
+
lib/cap_gun_reloaded.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,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,71 @@
|
|
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
|
+
if user or secret
|
9
|
+
if RUBY_VERSION == "1.8.7"
|
10
|
+
check_auth_args user, secret
|
11
|
+
else
|
12
|
+
check_auth_args user, secret, authtype
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
|
17
|
+
@socket = Net::InternetMessageIO.new(sock)
|
18
|
+
@socket.read_timeout = 60 #@read_timeout
|
19
|
+
|
20
|
+
check_response(critical { recv_response() })
|
21
|
+
do_helo(helodomain)
|
22
|
+
|
23
|
+
if starttls
|
24
|
+
raise 'openssl library not installed' unless defined?(OpenSSL)
|
25
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
|
26
|
+
ssl.sync_close = true
|
27
|
+
ssl.connect
|
28
|
+
@socket = Net::InternetMessageIO.new(ssl)
|
29
|
+
@socket.read_timeout = 60 #@read_timeout
|
30
|
+
do_helo(helodomain)
|
31
|
+
end
|
32
|
+
|
33
|
+
authenticate user, secret, authtype if user
|
34
|
+
@started = true
|
35
|
+
ensure
|
36
|
+
unless @started
|
37
|
+
# authentication failed, cancel connection.
|
38
|
+
@socket.close if not @started and @socket and not @socket.closed?
|
39
|
+
@socket = nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def do_helo(helodomain)
|
44
|
+
begin
|
45
|
+
if @esmtp
|
46
|
+
ehlo helodomain
|
47
|
+
else
|
48
|
+
helo helodomain
|
49
|
+
end
|
50
|
+
rescue Net::ProtocolError
|
51
|
+
if @esmtp
|
52
|
+
@esmtp = false
|
53
|
+
@error_occured = false
|
54
|
+
retry
|
55
|
+
end
|
56
|
+
raise
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def starttls
|
61
|
+
getok('STARTTLS') rescue return false
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
|
65
|
+
def quit
|
66
|
+
begin
|
67
|
+
getok('QUIT')
|
68
|
+
rescue EOFError
|
69
|
+
end
|
70
|
+
end
|
71
|
+
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
|
data/version.yml
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap_gun_reloaded
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Sanheim
|
8
|
+
- Muness Alrubaie
|
9
|
+
- Relevance
|
10
|
+
- Leigh Caplan
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-06-21 00:00:00 -07:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: spicycode-micronaut
|
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: mocha
|
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 deployment notifications.
|
39
|
+
email: opensource@thinkrelevance.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.markdown
|
46
|
+
files:
|
47
|
+
- .autotest
|
48
|
+
- .gitignore
|
49
|
+
- CHANGELOG
|
50
|
+
- README.markdown
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- cap_gun_reloaded.gemspec
|
54
|
+
- examples/cap_gun_example.rb
|
55
|
+
- examples/example_helper.rb
|
56
|
+
- examples/presenter_example.rb
|
57
|
+
- init.rb
|
58
|
+
- install.rb
|
59
|
+
- lib/cap_gun_reloaded.rb
|
60
|
+
- lib/cap_gun/presenter.rb
|
61
|
+
- manifest.txt
|
62
|
+
- tasks/cap_bot_tasks.rake
|
63
|
+
- vendor/action_mailer_tls/README
|
64
|
+
- vendor/action_mailer_tls/init.rb
|
65
|
+
- vendor/action_mailer_tls/lib/smtp_tls.rb
|
66
|
+
- vendor/action_mailer_tls/sample/mailer.yml.sample
|
67
|
+
- vendor/action_mailer_tls/sample/smtp_gmail.rb
|
68
|
+
- version.yml
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://github.com/texel/cap_gun_reloaded
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --charset=UTF-8
|
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: "0"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Bang! You're deployed. And you work with Onehub's deploy strategy!
|
97
|
+
test_files:
|
98
|
+
- examples/cap_gun_example.rb
|
99
|
+
- examples/example_helper.rb
|
100
|
+
- examples/presenter_example.rb
|