public
Rubygem
Description: Bang! You've deployed!
Homepage: http://opensource.thinkrelevance.com/
Clone URL: git://github.com/relevance/cap_gun.git
Search Repo:
initial commit
rsanheim (author)
Fri Apr 04 07:15:34 -0700 2008
commit  fdaf82a1fe2b81ec35a59daac65e6c6372f25adf
tree    bd6167e968feddd3ae08c854be01dfaf901f35f0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -0,0 +1,21 @@
0
+require 'autotest/menu'
0
+require 'log_buddy'
0
+LogBuddy.init
0
+include LogBuddy::Mixin
0
+
0
+Autotest.add_hook :initialize do |at|
0
+ at.clear_mappings
0
+ # at.add_mapping(/^lib\/(.*)\.rb$/) { |filename, m|
0
+ # d "this one works!"
0
+ # file = File.basename(filename).gsub("_", "_?").gsub(".rb", "")
0
+ # foo = at.files_matching %r%^test/.*#{file}_test.rb$%
0
+ # foo
0
+ # }
0
+
0
+ at.add_mapping(%r%lib/(.*)\.rb$%) { |filename, match|
0
+ at.files_matching %r%^spec/#{match[1]}.*\.rb$%
0
+ }
0
+ at.add_mapping(%r%^spec/.*\.rb$%) { |filename, match|
0
+ filename
0
+ }
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -0,0 +1,20 @@
0
+Copyright (c) 2008 Relevance, Inc.
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+"Software"), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -0,0 +1,13 @@
0
+CapBot
0
+======
0
+
0
+Introduction goes here.
0
+
0
+
0
+Example
0
+=======
0
+
0
+Example goes here.
0
+
0
+
0
+Copyright (c) 2008 [name of plugin creator], released under the MIT license
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -0,0 +1,22 @@
0
+require 'rake'
0
+require 'rake/testtask'
0
+require 'rake/rdoctask'
0
+
0
+desc 'Default: run unit tests.'
0
+task :default => :test
0
+
0
+desc 'Test the cap_bot plugin.'
0
+Rake::TestTask.new(:test) do |t|
0
+ t.libs << 'lib'
0
+ t.pattern = 'test/**/*_test.rb'
0
+ t.verbose = true
0
+end
0
+
0
+desc 'Generate documentation for the cap_bot plugin.'
0
+Rake::RDocTask.new(:rdoc) do |rdoc|
0
+ rdoc.rdoc_dir = 'rdoc'
0
+ rdoc.title = 'CapBot'
0
+ rdoc.options << '--line-numbers' << '--inline-source'
0
+ rdoc.rdoc_files.include('README')
0
+ rdoc.rdoc_files.include('lib/**/*.rb')
0
+end
...
 
...
1
0
@@ -0,0 +1 @@
0
+# Include hook code here
...
 
...
1
0
@@ -0,0 +1 @@
0
+# Install hook code here
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
0
@@ -0,0 +1,119 @@
0
+require 'active_support'
0
+require 'action_mailer'
0
+require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib smtp_tls])
0
+
0
+# Tell everyone about your releases!
0
+#
0
+# You must set up your mail settings in config/capinator_config.yml. We include
0
+# the ActionMailer hack to play nice with gmail, so thats a super easy way
0
+# to do this without setting up your own MTA.
0
+#
0
+# Example:
0
+#
0
+# Want to just shoot everyone an email about the latest status?
0
+#
0
+# cap capinator:email
0
+#
0
+# Include comments?
0
+#
0
+# cap -s comment="hi mom" capinator:email
0
+#
0
+# Enable emails after every deploy by adding this to your deploy.rb:
0
+#
0
+# after "deploy", "capinator:email"
0
+#
0
+# Then when you deploy, you can optionally include comments:
0
+# cap -s comment="fix for bug #303" deploy
0
+#
0
+module Capinator
0
+
0
+ module Helper
0
+
0
+ def load_mailer_config
0
+ mailer_config = File.open("#{rails_root}/config/capinator_config.yml")
0
+ mailer_options = YAML.load(mailer_config)
0
+ ActionMailer::Base.smtp_settings = mailer_options
0
+ end
0
+
0
+ # Capistrano doesn't set this for some reason
0
+ def rails_root
0
+ Object.const_set("RAILS_ROOT", File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. .. ..]))) unless Object.const_defined?("RAILS_ROOT")
0
+ RAILS_ROOT
0
+ end
0
+
0
+ def current_user
0
+ `id -un`.strip
0
+ end
0
+
0
+ def time_from_release(path, timezone)
0
+ timestamp = path[(path.rindex("/") + 1)..-1]
0
+ datetime = DateTime.parse(timestamp)
0
+ datetime.strftime("%B #{datetime.day.ordinalize}, %Y %l:%M %p #{timezone}").gsub(/\s+/, ' ').strip
0
+ end
0
+
0
+ extend self
0
+ end
0
+
0
+ class Mailer < ActionMailer::Base
0
+ include Capinator::Helper
0
+ DEFAULT_SENDER = %("Capinator" <capinator@example.com>)
0
+
0
+ @@email_prefix = "[DEPLOY] "
0
+ cattr_accessor :email_prefix
0
+
0
+ def deployment_notification(capistrano)
0
+ options = capistrano[:capinator_options]
0
+
0
+ content_type "text/plain"
0
+ subject "#{email_prefix} #{capistrano[:application]} deployed to #{capistrano[:rails_env]}"
0
+
0
+ recipients options[:recipients]
0
+ from options[:sender_address] || DEFAULT_SENDER
0
+
0
+ body <<-EOL
0
+#{capistrano[:application]} was deployed to #{capistrano[:rails_env]} by #{current_user} at #{time_from_release(capistrano[:current_release], capistrano[:timezone])}.
0
+
0
+Comment: #{capistrano[:comment] || "[none given]"}
0
+
0
+Nerd details
0
+============
0
+Release: #{capistrano[:current_release]}
0
+Release Time: #{time_from_release(capistrano[:current_release], capistrano[:timezone])}
0
+Release Revision: #{capistrano[:current_revision]}
0
+
0
+Previous Release: #{capistrano[:previous_release]}
0
+Previous Release Time: #{time_from_release(capistrano[:previous_release], capistrano[:timezone])}
0
+Previous Release Revision: #{capistrano[:previous_revision]}
0
+
0
+Repository: #{capistrano[:repository]}
0
+Deploy path: #{capistrano[:deploy_to]}
0
+EOL
0
+ end
0
+
0
+ end
0
+
0
+
0
+end
0
+
0
+if Object.const_defined?("Capistrano")
0
+
0
+ Capistrano::Configuration.instance(:must_exist).load do
0
+
0
+ namespace :capinator do
0
+ desc "Get the time zone from the server"
0
+ task :get_timezone, :roles => :app do
0
+ set "timezone", capture('date "+%Z"').strip
0
+ end
0
+
0
+ desc "Send notification via email"
0
+ task :email do
0
+ Capinator::Helper.load_mailer_config
0
+ Capinator::Mailer.deliver_deployment_notification(self)
0
+ end
0
+
0
+ end
0
+
0
+ before "capinator:email", "capinator:get_timezone"
0
+
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -0,0 +1,21 @@
0
+ENV["RAILS_ENV"] = "test"
0
+require 'rubygems'
0
+require 'test/unit'
0
+require 'test/spec'
0
+require 'mocha'
0
+require 'net/smtp'
0
+require File.join(File.dirname(__FILE__), *%w[.. lib cap_bot])
0
+
0
+describe "Capinator" do
0
+ it "uses action mailer hack" do
0
+ Net::SMTP.new('').respond_to?(:starttls, true).should == true
0
+ end
0
+end
0
+
0
+describe "Capinator" do
0
+ include Capinator::Helper
0
+
0
+ it "parses datetime from release path" do
0
+ time_from_release("/data/foo/releases/20080402152141", "PDT").should == "April 2nd, 2008 3:21 PM PDT"
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
...
1
2
3
4
0
@@ -0,0 +1,4 @@
0
+# desc "Explaining what the task does"
0
+# task :cap_bot do
0
+# # Task goes here
0
+# end
...
 
...
1
0
@@ -0,0 +1 @@
0
+# Uninstall hook code here
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -0,0 +1,19 @@
0
+= SMTP_TLS + ActionMailer + Gmail
0
+
0
+Configure Rails To Use Gmail's SMTP
0
+
0
+Originally from http://blog.pomozov.info/posts/how-to-send-actionmailer-mails-to-gmailcom.html
0
+
0
+See "sample" directory for further instructions
0
+
0
+== Resources
0
+
0
+Blog post
0
+
0
+* http://www.rubyinside.com/how-to-use-gmails-smtp-server-with-rails-394.html
0
+
0
+* http://www.prestonlee.com/archives/63
0
+
0
+== Author
0
+
0
+* Marc Chung - marc [dot] chung [at] openrain [dot] com
...
 
...
1
0
@@ -0,0 +1 @@
0
+require_dependency 'smtp_tls'
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
0
@@ -0,0 +1,65 @@
0
+require "openssl"
0
+require "net/smtp"
0
+
0
+Net::SMTP.class_eval do
0
+ private
0
+ def do_start(helodomain, user, secret, authtype)
0
+ raise IOError, 'SMTP session already started' if @started
0
+ check_auth_args user, secret, authtype if user or secret
0
+
0
+ sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
0
+ @socket = Net::InternetMessageIO.new(sock)
0
+ @socket.read_timeout = 60 #@read_timeout
0
+
0
+ check_response(critical { recv_response() })
0
+ do_helo(helodomain)
0
+
0
+ if starttls
0
+ raise 'openssl library not installed' unless defined?(OpenSSL)
0
+ ssl = OpenSSL::SSL::SSLSocket.new(sock)
0
+ ssl.sync_close = true
0
+ ssl.connect
0
+ @socket = Net::InternetMessageIO.new(ssl)
0
+ @socket.read_timeout = 60 #@read_timeout
0
+ do_helo(helodomain)
0
+ end
0
+
0
+ authenticate user, secret, authtype if user
0
+ @started = true
0
+ ensure
0
+ unless @started
0
+ # authentication failed, cancel connection.
0
+ @socket.close if not @started and @socket and not @socket.closed?
0
+ @socket = nil
0
+ end
0
+ end
0
+
0
+ def do_helo(helodomain)
0
+ begin
0
+ if @esmtp
0
+ ehlo helodomain
0
+ else
0
+ helo helodomain
0
+ end
0
+ rescue Net::ProtocolError
0
+ if @esmtp
0
+ @esmtp = false
0
+ @error_occured = false
0
+ retry
0
+ end
0
+ raise
0
+ end
0
+ end
0
+
0
+ def starttls
0
+ getok('STARTTLS') rescue return false
0
+ return true
0
+ end
0
+
0
+ def quit
0
+ begin
0
+ getok('QUIT')
0
+ rescue EOFError
0
+ end
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
...
1
2
3
4
5
6
0
@@ -0,0 +1,6 @@
0
+---
0
+ :address: smtp.gmail.com
0
+ :port: 587
0
+ :user_name: email@dress.com
0
+ :password: h@ckme
0
+ :authentication: :plain
...
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -0,0 +1,12 @@
0
+#
0
+# For Rails 2.x:
0
+# A copy of this file should be placed in RAILS_ROOT/initializers/
0
+# A file named mailer.yml should be placed in RAILS_ROOT/config/
0
+# See mailer.yml.sample
0
+#
0
+
0
+require "smtp_tls"
0
+
0
+mailer_config = File.open("#{RAILS_ROOT}/config/mailer.yml")
0
+mailer_options = YAML.load(mailer_config)
0
+ActionMailer::Base.smtp_settings = mailer_options

Comments

    No one has commented yet.