rebuy_deployment 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rebuy_deployment/deploy.rb +50 -1
  2. metadata +19 -8
@@ -1,3 +1,5 @@
1
+ require 'mail'
2
+
1
3
  def prompt_if_unset(name, default = '')
2
4
  unless exists? name
3
5
  set name do
@@ -12,6 +14,38 @@ def prompt_if_unset(name, default = '')
12
14
  end
13
15
  end
14
16
 
17
+ # code based on http://madebynathan.com/2011/03/01/capistrano-task-show-deployed-revisions-diffs/
18
+ def get_git_log
19
+ current, previous, latest = current_revision[0,7], previous_revision[0,7], real_revision[0,7]
20
+ body = "The application #{application} was deployed.\n"
21
+
22
+ if exists?(:fqdn) && :fqdn != ""
23
+ body << "It was deployed into stage #{stage} (#{fqdn})\n\n"
24
+ else
25
+ body << "It was deployed into stage #{stage}\n\n"
26
+ end
27
+ body << "Master Revision: #{latest}\n"
28
+ body << "Deployed Revision: #{current}\n"
29
+ body << "Previous Revision: #{previous}\n\n"
30
+
31
+ # If deployed and master are the same, show the difference between the last 2 deployments.
32
+ base_label, new_label, base_rev, new_rev = latest != current ? \
33
+ ["deployed", "master", current, latest] : \
34
+ ["previous", "deployed", previous, current]
35
+
36
+ # Show difference between master and deployed revisions.
37
+ if (diff = `git log #{base_rev}..#{new_rev} --oneline`) != ""
38
+ diff = " " << diff.gsub("\n", "\n ") << "\n"
39
+ # Indent commit messages nicely, max 80 chars per line, line has to end with space.
40
+ diff = diff.split("\n").map{|l|l.scan(/.{1,120}/).join("\n"<<" "*14).gsub(/([^ ]*)\n {14}/m,"\n"<<" "*14<<"\\1")}.join("\n")
41
+ body << "Difference between #{base_label} revision and #{new_label} revision:\n\n"
42
+ body << diff
43
+ return body
44
+ else
45
+ body << "An old version was redeployed. No changes."
46
+ end
47
+ end
48
+
15
49
  set :stages, %w(production sandbox)
16
50
  set :default_stage, 'sandbox'
17
51
  set :stage_dir, './deployment/multistage'
@@ -71,7 +105,7 @@ namespace :deploy do
71
105
 
72
106
  task :new_relic, :roles => :web, :on_error => :continue do
73
107
  if exists?(:new_relic_api_key)
74
- logMsg = `git log -n 1 --format=oneline`
108
+ logMsg = get_git_log()
75
109
 
76
110
  run "curl -H 'x-api-key:#{new_relic_api_key}'
77
111
  -d 'deployment[app_name]=#{application}'
@@ -82,10 +116,25 @@ namespace :deploy do
82
116
  logger.info "Skipping New Relic deployment because no api key is present."
83
117
  end
84
118
  end
119
+
120
+ # Mail.defaults has to be configured in order for this task to work properly
121
+ task :notify, :on_error => :continue do
122
+ if exists?(:mail_sender) && exists?(:mail_receiver)
123
+ sender, receiver, subject, body = "#{mail_sender}", "#{mail_receiver}", "#{application} deployed", get_git_log()
124
+
125
+ Mail.deliver do
126
+ to receiver
127
+ from sender
128
+ subject subject
129
+ body body
130
+ end
131
+ end
132
+ end
85
133
  end
86
134
 
87
135
  after 'deploy:finalize_update', 'deploy:symlink_shared'
88
136
  after 'deploy:finalize_update', 'deploy:change_owner'
89
137
  after 'deploy:symlink', 'deploy:restart'
90
138
  after 'deploy:symlink', 'deploy:new_relic'
139
+ after 'deploy:symlink', 'deploy:notify'
91
140
  after 'deploy:setup', 'deploy:prepare_directory_structure'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rebuy_deployment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &20262700 !ruby/object:Gem::Requirement
16
+ requirement: &12242160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 2.12.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *20262700
27
+ version_requirements: *12242160
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: railsless-deploy
30
- requirement: &20279980 !ruby/object:Gem::Requirement
30
+ requirement: &12240520 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 1.0.2
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *20279980
38
+ version_requirements: *12240520
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rake
41
- requirement: &20279240 !ruby/object:Gem::Requirement
41
+ requirement: &12239680 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,7 +46,18 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *20279240
49
+ version_requirements: *12239680
50
+ - !ruby/object:Gem::Dependency
51
+ name: mail
52
+ requirement: &12238720 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 2.4.4
58
+ type: :runtime
59
+ prerelease: false
60
+ version_requirements: *12238720
50
61
  description: This gem offers deployment for all rebuy.de projects
51
62
  email:
52
63
  - m.roetgers@rebuy.de