engineyard-serverside 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,144 +2,146 @@ require 'json'
2
2
  require 'thor'
3
3
 
4
4
  module EY
5
- class Deploy::Configuration
6
- DEFAULT_CONFIG = Thor::CoreExt::HashWithIndifferentAccess.new({
7
- "branch" => "master",
8
- "strategy" => "Git",
9
- })
10
-
11
- attr_reader :configuration
12
- alias :c :configuration
13
-
14
- attr_writer :release_path
5
+ module Serverside
6
+ class Deploy::Configuration
7
+ DEFAULT_CONFIG = Thor::CoreExt::HashWithIndifferentAccess.new({
8
+ "branch" => "master",
9
+ "strategy" => "Git",
10
+ })
11
+
12
+ attr_reader :configuration
13
+ alias :c :configuration
14
+
15
+ attr_writer :release_path
16
+
17
+ def initialize(opts={})
18
+ @release_path = opts[:release_path]
19
+ config = JSON.parse(opts["config"] || "{}")
20
+ @configuration = DEFAULT_CONFIG.merge(config).merge(opts)
21
+ end
15
22
 
16
- def initialize(opts={})
17
- @release_path = opts[:release_path]
18
- config = JSON.parse(opts["config"] || "{}")
19
- @configuration = DEFAULT_CONFIG.merge(config).merge(opts)
20
- end
23
+ # Delegate to the configuration objects
24
+ def method_missing(meth, *args, &blk)
25
+ c.key?(meth.to_s) ? c[meth.to_s] : super
26
+ end
21
27
 
22
- # Delegate to the configuration objects
23
- def method_missing(meth, *args, &blk)
24
- c.key?(meth.to_s) ? c[meth.to_s] : super
25
- end
28
+ def respond_to?(meth, include_private=false)
29
+ c.key?(meth.to_s) ? true : super
30
+ end
26
31
 
27
- def respond_to?(meth, include_private=false)
28
- c.key?(meth.to_s) ? true : super
29
- end
32
+ def [](key)
33
+ if respond_to?(key.to_sym)
34
+ send(key.to_sym)
35
+ else
36
+ c[key]
37
+ end
38
+ end
30
39
 
31
- def [](key)
32
- if respond_to?(key.to_sym)
33
- send(key.to_sym)
34
- else
35
- c[key]
40
+ def has_key?(key)
41
+ if respond_to?(key.to_sym)
42
+ true
43
+ else
44
+ c.has_key?(key)
45
+ end
36
46
  end
37
- end
38
47
 
39
- def has_key?(key)
40
- if respond_to?(key.to_sym)
41
- true
42
- else
43
- c.has_key?(key)
48
+ def to_json
49
+ configuration.to_json
44
50
  end
45
- end
46
51
 
47
- def to_json
48
- configuration.to_json
49
- end
52
+ def node
53
+ EY::Serverside.node
54
+ end
50
55
 
51
- def node
52
- EY.node
53
- end
56
+ def revision
57
+ IO.read(File.join(latest_release, 'REVISION'))
58
+ end
54
59
 
55
- def revision
56
- IO.read(File.join(latest_release, 'REVISION'))
57
- end
60
+ def repository_cache
61
+ configuration['repository_cache'] || File.join(deploy_to, "/shared/cached-copy")
62
+ end
58
63
 
59
- def repository_cache
60
- configuration['repository_cache'] || File.join(deploy_to, "/shared/cached-copy")
61
- end
64
+ def deploy_to
65
+ configuration['deploy_to'] || "/data/#{app}"
66
+ end
62
67
 
63
- def deploy_to
64
- configuration['deploy_to'] || "/data/#{app}"
65
- end
68
+ def migrate?
69
+ !!configuration['migrate']
70
+ end
66
71
 
67
- def migrate?
68
- !!configuration['migrate']
69
- end
72
+ def migration_command
73
+ configuration['migrate'] == "migrate" ? DEFAULT_CONFIG["migrate"] : configuration['migrate']
74
+ end
70
75
 
71
- def migration_command
72
- configuration['migrate'] == "migrate" ? DEFAULT_CONFIG["migrate"] : configuration['migrate']
73
- end
76
+ def user
77
+ configuration['user'] || ENV['USER']
78
+ end
74
79
 
75
- def user
76
- configuration['user'] || ENV['USER']
77
- end
80
+ def group
81
+ configuration['group'] || user
82
+ end
78
83
 
79
- def group
80
- configuration['group'] || user
81
- end
84
+ def role
85
+ node['instance_role']
86
+ end
82
87
 
83
- def role
84
- node['instance_role']
85
- end
88
+ def current_role
89
+ current_roles.first
90
+ end
86
91
 
87
- def current_role
88
- current_roles.first
89
- end
92
+ def copy_exclude
93
+ @copy_exclude ||= Array(configuration.fetch("copy_exclude", []))
94
+ end
90
95
 
91
- def copy_exclude
92
- @copy_exclude ||= Array(configuration.fetch("copy_exclude", []))
93
- end
96
+ def environment
97
+ configuration['framework_env']
98
+ end
94
99
 
95
- def environment
96
- configuration['framework_env']
97
- end
100
+ def latest_release
101
+ all_releases.last
102
+ end
98
103
 
99
- def latest_release
100
- all_releases.last
101
- end
104
+ def previous_release(current=latest_release)
105
+ index = all_releases.index(current)
106
+ all_releases[index-1]
107
+ end
102
108
 
103
- def previous_release(current=latest_release)
104
- index = all_releases.index(current)
105
- all_releases[index-1]
106
- end
109
+ def oldest_release
110
+ all_releases.first
111
+ end
107
112
 
108
- def oldest_release
109
- all_releases.first
110
- end
113
+ def all_releases
114
+ Dir.glob("#{release_dir}/*").sort
115
+ end
111
116
 
112
- def all_releases
113
- Dir.glob("#{release_dir}/*").sort
114
- end
117
+ def binstubs_path
118
+ release_path + '/ey_bundler_binstubs'
119
+ end
115
120
 
116
- def binstubs_path
117
- release_path + '/ey_bundler_binstubs'
118
- end
121
+ def framework_envs
122
+ "RAILS_ENV=#{environment} RACK_ENV=#{environment} MERB_ENV=#{environment}"
123
+ end
119
124
 
120
- def framework_envs
121
- "RAILS_ENV=#{environment} RACK_ENV=#{environment} MERB_ENV=#{environment}"
122
- end
125
+ def current_path
126
+ File.join(deploy_to, "current")
127
+ end
123
128
 
124
- def current_path
125
- File.join(deploy_to, "current")
126
- end
129
+ def shared_path
130
+ File.join(deploy_to, "shared")
131
+ end
127
132
 
128
- def shared_path
129
- File.join(deploy_to, "shared")
130
- end
133
+ def release_dir
134
+ File.join(deploy_to, "releases")
135
+ end
131
136
 
132
- def release_dir
133
- File.join(deploy_to, "releases")
134
- end
137
+ def release_path
138
+ @release_path ||= File.join(release_dir, Time.now.utc.strftime("%Y%m%d%H%M%S"))
139
+ end
135
140
 
136
- def release_path
137
- @release_path ||= File.join(release_dir, Time.now.utc.strftime("%Y%m%d%H%M%S"))
138
- end
141
+ def exclusions
142
+ copy_exclude.map { |e| %|--exclude="#{e}"| }.join(' ')
143
+ end
139
144
 
140
- def exclusions
141
- copy_exclude.map { |e| %|--exclude="#{e}"| }.join(' ')
142
145
  end
143
-
144
146
  end
145
147
  end
@@ -4,337 +4,339 @@ require 'fileutils'
4
4
  require 'json'
5
5
 
6
6
  module EY
7
- class DeployBase < Task
8
- include LoggedOutput
9
-
10
- # default task
11
- def deploy
12
- debug "Starting deploy at #{Time.now.asctime}"
13
- update_repository_cache
14
- cached_deploy
15
- end
7
+ module Serverside
8
+ class DeployBase < Task
9
+ include LoggedOutput
10
+
11
+ # default task
12
+ def deploy
13
+ debug "Starting deploy at #{Time.now.asctime}"
14
+ update_repository_cache
15
+ cached_deploy
16
+ end
16
17
 
17
- def cached_deploy
18
- debug "Deploying app from cached copy at #{Time.now.asctime}"
19
- require_custom_tasks
20
- push_code
18
+ def cached_deploy
19
+ debug "Deploying app from cached copy at #{Time.now.asctime}"
20
+ require_custom_tasks
21
+ push_code
22
+
23
+ info "~> Starting full deploy"
24
+ copy_repository_cache
25
+
26
+ with_failed_release_cleanup do
27
+ create_revision_file
28
+ run_with_callbacks(:bundle)
29
+ symlink_configs
30
+ conditionally_enable_maintenance_page
31
+ run_with_callbacks(:migrate)
32
+ callback(:before_symlink)
33
+ symlink
34
+ end
21
35
 
22
- info "~> Starting full deploy"
23
- copy_repository_cache
36
+ callback(:after_symlink)
37
+ run_with_callbacks(:restart)
38
+ disable_maintenance_page
39
+
40
+ cleanup_old_releases
41
+ debug "Finished deploy at #{Time.now.asctime}"
42
+ rescue Exception
43
+ debug "Finished failing to deploy at #{Time.now.asctime}"
44
+ puts_deploy_failure
45
+ raise
46
+ end
24
47
 
25
- with_failed_release_cleanup do
26
- create_revision_file
27
- run_with_callbacks(:bundle)
28
- symlink_configs
48
+ def restart_with_maintenance_page
49
+ require_custom_tasks
29
50
  conditionally_enable_maintenance_page
30
- run_with_callbacks(:migrate)
31
- callback(:before_symlink)
32
- symlink
51
+ restart
52
+ disable_maintenance_page
33
53
  end
34
54
 
35
- callback(:after_symlink)
36
- run_with_callbacks(:restart)
37
- disable_maintenance_page
55
+ def enable_maintenance_page
56
+ maintenance_page_candidates = [
57
+ "public/maintenance.html.custom",
58
+ "public/maintenance.html.tmp",
59
+ "public/maintenance.html",
60
+ "public/system/maintenance.html.default",
61
+ ].map do |file|
62
+ File.join(c.latest_release, file)
63
+ end
38
64
 
39
- cleanup_old_releases
40
- debug "Finished deploy at #{Time.now.asctime}"
41
- rescue Exception
42
- debug "Finished failing to deploy at #{Time.now.asctime}"
43
- puts_deploy_failure
44
- raise
45
- end
65
+ # this one is guaranteed to exist
66
+ maintenance_page_candidates << File.expand_path(
67
+ "default_maintenance_page.html",
68
+ File.dirname(__FILE__)
69
+ )
46
70
 
47
- def restart_with_maintenance_page
48
- require_custom_tasks
49
- conditionally_enable_maintenance_page
50
- restart
51
- disable_maintenance_page
52
- end
71
+ # put in the maintenance page
72
+ maintenance_file = maintenance_page_candidates.detect do |file|
73
+ File.exists?(file)
74
+ end
53
75
 
54
- def enable_maintenance_page
55
- maintenance_page_candidates = [
56
- "public/maintenance.html.custom",
57
- "public/maintenance.html.tmp",
58
- "public/maintenance.html",
59
- "public/system/maintenance.html.default",
60
- ].map do |file|
61
- File.join(c.latest_release, file)
76
+ @maintenance_up = true
77
+ roles :app_master, :app, :solo do
78
+ maint_page_dir = File.join(c.shared_path, "system")
79
+ visible_maint_page = File.join(maint_page_dir, "maintenance.html")
80
+ run Escape.shell_command(['mkdir', '-p', maint_page_dir])
81
+ run Escape.shell_command(['cp', maintenance_file, visible_maint_page])
82
+ end
62
83
  end
63
84
 
64
- # this one is guaranteed to exist
65
- maintenance_page_candidates << File.expand_path(
66
- "default_maintenance_page.html",
67
- File.dirname(__FILE__)
68
- )
69
-
70
- # put in the maintenance page
71
- maintenance_file = maintenance_page_candidates.detect do |file|
72
- File.exists?(file)
85
+ def conditionally_enable_maintenance_page
86
+ if c.migrate? || required_downtime_stack?
87
+ enable_maintenance_page
88
+ end
73
89
  end
74
90
 
75
- @maintenance_up = true
76
- roles :app_master, :app, :solo do
77
- maint_page_dir = File.join(c.shared_path, "system")
78
- visible_maint_page = File.join(maint_page_dir, "maintenance.html")
79
- run Escape.shell_command(['mkdir', '-p', maint_page_dir])
80
- run Escape.shell_command(['cp', maintenance_file, visible_maint_page])
91
+ def required_downtime_stack?
92
+ %w[ nginx_mongrel glassfish ].include? c.stack
81
93
  end
82
- end
83
94
 
84
- def conditionally_enable_maintenance_page
85
- if c.migrate? || required_downtime_stack?
86
- enable_maintenance_page
95
+ def disable_maintenance_page
96
+ @maintenance_up = false
97
+ roles :app_master, :app, :solo do
98
+ run "rm -f #{File.join(c.shared_path, "system", "maintenance.html")}"
99
+ end
87
100
  end
88
- end
89
-
90
- def required_downtime_stack?
91
- %w[ nginx_mongrel glassfish ].include? c.stack
92
- end
93
101
 
94
- def disable_maintenance_page
95
- @maintenance_up = false
96
- roles :app_master, :app, :solo do
97
- run "rm -f #{File.join(c.shared_path, "system", "maintenance.html")}"
102
+ def run_with_callbacks(task)
103
+ callback("before_#{task}")
104
+ send(task)
105
+ callback("after_#{task}")
98
106
  end
99
- end
100
107
 
101
- def run_with_callbacks(task)
102
- callback("before_#{task}")
103
- send(task)
104
- callback("after_#{task}")
105
- end
108
+ # task
109
+ def push_code
110
+ info "~> Pushing code to all servers"
111
+ barrier *(EY::Serverside::Server.all.map do |server|
112
+ need_later { server.sync_directory(config.repository_cache) }
113
+ end)
114
+ end
106
115
 
107
- # task
108
- def push_code
109
- info "~> Pushing code to all servers"
110
- barrier *(EY::Server.all.map do |server|
111
- need_later { server.sync_directory(config.repository_cache) }
112
- end)
113
- end
116
+ # task
117
+ def restart
118
+ @restart_failed = true
119
+ info "~> Restarting app servers"
120
+ roles :app_master, :app, :solo do
121
+ run(restart_command)
122
+ end
123
+ @restart_failed = false
124
+ end
114
125
 
115
- # task
116
- def restart
117
- @restart_failed = true
118
- info "~> Restarting app servers"
119
- roles :app_master, :app, :solo do
120
- run(restart_command)
126
+ def restart_command
127
+ "/engineyard/bin/app_#{c.app} deploy"
121
128
  end
122
- @restart_failed = false
123
- end
124
129
 
125
- def restart_command
126
- "/engineyard/bin/app_#{c.app} deploy"
127
- end
130
+ # task
131
+ def bundle
132
+ if File.exist?("#{c.release_path}/Gemfile")
133
+ info "~> Gemfile detected, bundling gems"
134
+ lockfile = File.join(c.release_path, "Gemfile.lock")
128
135
 
129
- # task
130
- def bundle
131
- if File.exist?("#{c.release_path}/Gemfile")
132
- info "~> Gemfile detected, bundling gems"
133
- lockfile = File.join(c.release_path, "Gemfile.lock")
136
+ bundler_installer = if File.exist?(lockfile)
137
+ get_bundler_installer(lockfile)
138
+ else
139
+ warn_about_missing_lockfile
140
+ bundler_09_installer(default_09_bundler)
141
+ end
134
142
 
135
- bundler_installer = if File.exist?(lockfile)
136
- get_bundler_installer(lockfile)
137
- else
138
- warn_about_missing_lockfile
139
- bundler_09_installer(default_09_bundler)
140
- end
143
+ sudo "#{$0} _#{EY::Serverside::VERSION}_ install_bundler #{bundler_installer.version}"
141
144
 
142
- sudo "#{$0} _#{VERSION}_ install_bundler #{bundler_installer.version}"
145
+ run "cd #{c.release_path} && bundle _#{bundler_installer.version}_ install #{bundler_installer.options}"
146
+ end
147
+ end
143
148
 
144
- run "cd #{c.release_path} && bundle _#{bundler_installer.version}_ install #{bundler_installer.options}"
149
+ # task
150
+ def cleanup_old_releases
151
+ @cleanup_failed = true
152
+ info "~> Cleaning up old releases"
153
+ sudo "ls #{c.release_dir} | head -n -3 | xargs -I{} rm -rf #{c.release_dir}/{}"
154
+ @cleanup_failed = false
145
155
  end
146
- end
147
156
 
148
- # task
149
- def cleanup_old_releases
150
- @cleanup_failed = true
151
- info "~> Cleaning up old releases"
152
- sudo "ls #{c.release_dir} | head -n -3 | xargs -I{} rm -rf #{c.release_dir}/{}"
153
- @cleanup_failed = false
154
- end
157
+ # task
158
+ def rollback
159
+ if c.all_releases.size > 1
160
+ rolled_back_release = c.latest_release
161
+ c.release_path = c.previous_release(rolled_back_release)
155
162
 
156
- # task
157
- def rollback
158
- if c.all_releases.size > 1
159
- rolled_back_release = c.latest_release
160
- c.release_path = c.previous_release(rolled_back_release)
161
-
162
- revision = File.read(File.join(c.release_path, 'REVISION')).strip
163
- info "~> Rolling back to previous release: #{short_log_message(revision)}"
164
-
165
- run_with_callbacks(:symlink)
166
- sudo "rm -rf #{rolled_back_release}"
167
- bundle
168
- info "~> Restarting with previous release"
169
- with_maintenance_page { run_with_callbacks(:restart) }
170
- else
171
- info "~> Already at oldest release, nothing to roll back to"
172
- exit(1)
173
- end
174
- end
163
+ revision = File.read(File.join(c.release_path, 'REVISION')).strip
164
+ info "~> Rolling back to previous release: #{short_log_message(revision)}"
175
165
 
176
- # task
177
- def migrate
178
- return unless c.migrate?
179
- @migrations_reached = true
180
- roles :app_master, :solo do
181
- cmd = "cd #{c.release_path} && PATH=#{c.binstubs_path}:$PATH #{c.framework_envs} #{c.migration_command}"
182
- info "~> Migrating: #{cmd}"
183
- run(cmd)
166
+ run_with_callbacks(:symlink)
167
+ sudo "rm -rf #{rolled_back_release}"
168
+ bundle
169
+ info "~> Restarting with previous release"
170
+ with_maintenance_page { run_with_callbacks(:restart) }
171
+ else
172
+ info "~> Already at oldest release, nothing to roll back to"
173
+ exit(1)
174
+ end
184
175
  end
185
- end
186
176
 
187
- # task
188
- def copy_repository_cache
189
- info "~> Copying to #{c.release_path}"
190
- run("mkdir -p #{c.release_path} && rsync -aq #{c.exclusions} #{c.repository_cache}/ #{c.release_path}")
177
+ # task
178
+ def migrate
179
+ return unless c.migrate?
180
+ @migrations_reached = true
181
+ roles :app_master, :solo do
182
+ cmd = "cd #{c.release_path} && PATH=#{c.binstubs_path}:$PATH #{c.framework_envs} #{c.migration_command}"
183
+ info "~> Migrating: #{cmd}"
184
+ run(cmd)
185
+ end
186
+ end
191
187
 
192
- info "~> Ensuring proper ownership"
193
- sudo("chown -R #{c.user}:#{c.group} #{c.deploy_to}")
194
- end
188
+ # task
189
+ def copy_repository_cache
190
+ info "~> Copying to #{c.release_path}"
191
+ run("mkdir -p #{c.release_path} && rsync -aq #{c.exclusions} #{c.repository_cache}/ #{c.release_path}")
195
192
 
196
- def create_revision_file
197
- run create_revision_file_command
198
- end
193
+ info "~> Ensuring proper ownership"
194
+ sudo("chown -R #{c.user}:#{c.group} #{c.deploy_to}")
195
+ end
199
196
 
200
- def symlink_configs(release_to_link=c.release_path)
201
- info "~> Symlinking configs"
202
- [ "chmod -R g+w #{release_to_link}",
203
- "rm -rf #{release_to_link}/log #{release_to_link}/public/system #{release_to_link}/tmp/pids",
204
- "mkdir -p #{release_to_link}/tmp",
205
- "ln -nfs #{c.shared_path}/log #{release_to_link}/log",
206
- "mkdir -p #{release_to_link}/public",
207
- "mkdir -p #{release_to_link}/config",
208
- "ln -nfs #{c.shared_path}/system #{release_to_link}/public/system",
209
- "ln -nfs #{c.shared_path}/pids #{release_to_link}/tmp/pids",
210
- "find #{c.shared_path}/config -type f -exec ln -s {} #{release_to_link}/config \\;",
211
- "ln -nfs #{c.shared_path}/config/database.yml #{release_to_link}/config/database.yml",
212
- "ln -nfs #{c.shared_path}/config/mongrel_cluster.yml #{release_to_link}/config/mongrel_cluster.yml",
213
- ].each do |cmd|
214
- run cmd
197
+ def create_revision_file
198
+ run create_revision_file_command
215
199
  end
216
200
 
217
- sudo "chown -R #{c.user}:#{c.group} #{release_to_link}"
218
- run "if [ -f \"#{c.shared_path}/config/newrelic.yml\" ]; then ln -nfs #{c.shared_path}/config/newrelic.yml #{release_to_link}/config/newrelic.yml; fi"
219
- end
201
+ def symlink_configs(release_to_link=c.release_path)
202
+ info "~> Symlinking configs"
203
+ [ "chmod -R g+w #{release_to_link}",
204
+ "rm -rf #{release_to_link}/log #{release_to_link}/public/system #{release_to_link}/tmp/pids",
205
+ "mkdir -p #{release_to_link}/tmp",
206
+ "ln -nfs #{c.shared_path}/log #{release_to_link}/log",
207
+ "mkdir -p #{release_to_link}/public",
208
+ "mkdir -p #{release_to_link}/config",
209
+ "ln -nfs #{c.shared_path}/system #{release_to_link}/public/system",
210
+ "ln -nfs #{c.shared_path}/pids #{release_to_link}/tmp/pids",
211
+ "find #{c.shared_path}/config -type f -exec ln -s {} #{release_to_link}/config \\;",
212
+ "ln -nfs #{c.shared_path}/config/database.yml #{release_to_link}/config/database.yml",
213
+ "ln -nfs #{c.shared_path}/config/mongrel_cluster.yml #{release_to_link}/config/mongrel_cluster.yml",
214
+ ].each do |cmd|
215
+ run cmd
216
+ end
220
217
 
221
- # task
222
- def symlink(release_to_link=c.release_path)
223
- info "~> Symlinking code"
224
- run "rm -f #{c.current_path} && ln -nfs #{release_to_link} #{c.current_path} && chown -R #{c.user}:#{c.group} #{c.current_path}"
225
- @symlink_changed = true
226
- rescue Exception
227
- sudo "rm -f #{c.current_path} && ln -nfs #{c.previous_release(release_to_link)} #{c.current_path} && chown -R #{c.user}:#{c.group} #{c.current_path}"
228
- @symlink_changed = false
229
- raise
230
- end
218
+ sudo "chown -R #{c.user}:#{c.group} #{release_to_link}"
219
+ run "if [ -f \"#{c.shared_path}/config/newrelic.yml\" ]; then ln -nfs #{c.shared_path}/config/newrelic.yml #{release_to_link}/config/newrelic.yml; fi"
220
+ end
221
+
222
+ # task
223
+ def symlink(release_to_link=c.release_path)
224
+ info "~> Symlinking code"
225
+ run "rm -f #{c.current_path} && ln -nfs #{release_to_link} #{c.current_path} && chown -R #{c.user}:#{c.group} #{c.current_path}"
226
+ @symlink_changed = true
227
+ rescue Exception
228
+ sudo "rm -f #{c.current_path} && ln -nfs #{c.previous_release(release_to_link)} #{c.current_path} && chown -R #{c.user}:#{c.group} #{c.current_path}"
229
+ @symlink_changed = false
230
+ raise
231
+ end
231
232
 
232
- def callback(what)
233
- @callbacks_reached ||= true
234
- if File.exist?("#{c.release_path}/deploy/#{what}.rb")
235
- run Escape.shell_command(base_callback_command_for(what)) do |server, cmd|
236
- per_instance_args = [
237
- '--current-roles', server.roles.join(' '),
238
- '--config', c.to_json,
239
- ]
240
- per_instance_args << '--current-name' << server.name.to_s if server.name
241
- cmd << " " << Escape.shell_command(per_instance_args)
233
+ def callback(what)
234
+ @callbacks_reached ||= true
235
+ if File.exist?("#{c.release_path}/deploy/#{what}.rb")
236
+ run Escape.shell_command(base_callback_command_for(what)) do |server, cmd|
237
+ per_instance_args = [
238
+ '--current-roles', server.roles.join(' '),
239
+ '--config', c.to_json,
240
+ ]
241
+ per_instance_args << '--current-name' << server.name.to_s if server.name
242
+ cmd << " " << Escape.shell_command(per_instance_args)
243
+ end
242
244
  end
243
245
  end
244
- end
245
246
 
246
- protected
247
+ protected
247
248
 
248
- def base_callback_command_for(what)
249
- [$0, version_specifier, 'hook', what.to_s,
250
- '--app', config.app.to_s,
251
- '--release-path', config.release_path.to_s,
252
- '--framework-env', c.environment.to_s,
253
- ].compact
254
- end
249
+ def base_callback_command_for(what)
250
+ [$0, version_specifier, 'hook', what.to_s,
251
+ '--app', config.app.to_s,
252
+ '--release-path', config.release_path.to_s,
253
+ '--framework-env', c.environment.to_s,
254
+ ].compact
255
+ end
255
256
 
256
- def version_specifier
257
- "_#{VERSION}_"
258
- end
257
+ def version_specifier
258
+ "_#{EY::Serverside::VERSION}_"
259
+ end
259
260
 
260
261
 
261
- def puts_deploy_failure
262
- if @cleanup_failed
263
- info "~> [Relax] Your site is running new code, but cleaning up old deploys failed"
264
- elsif @maintenance_up
265
- info "~> [Attention] Maintenance page still up, consider the following before removing:"
266
- info " * any deploy hooks ran, be careful if they were destructive" if @callbacks_reached
267
- info " * any migrations ran, be careful if they were destructive" if @migrations_reached
268
- if @symlink_changed
269
- info " * your new code is symlinked as current"
262
+ def puts_deploy_failure
263
+ if @cleanup_failed
264
+ info "~> [Relax] Your site is running new code, but cleaning up old deploys failed"
265
+ elsif @maintenance_up
266
+ info "~> [Attention] Maintenance page still up, consider the following before removing:"
267
+ info " * any deploy hooks ran, be careful if they were destructive" if @callbacks_reached
268
+ info " * any migrations ran, be careful if they were destructive" if @migrations_reached
269
+ if @symlink_changed
270
+ info " * your new code is symlinked as current"
271
+ else
272
+ info " * your old code is still symlinked as current"
273
+ end
274
+ info " * application servers failed to restart" if @restart_failed
270
275
  else
271
- info " * your old code is still symlinked as current"
276
+ info "~> [Relax] Your site is still running old code and nothing destructive could have occurred"
272
277
  end
273
- info " * application servers failed to restart" if @restart_failed
274
- else
275
- info "~> [Relax] Your site is still running old code and nothing destructive could have occurred"
276
278
  end
277
- end
278
279
 
279
- def with_maintenance_page
280
- conditionally_enable_maintenance_page
281
- yield if block_given?
282
- disable_maintenance_page
283
- end
280
+ def with_maintenance_page
281
+ conditionally_enable_maintenance_page
282
+ yield if block_given?
283
+ disable_maintenance_page
284
+ end
284
285
 
285
- def with_failed_release_cleanup
286
- yield
287
- rescue Exception
288
- sudo "rm -rf #{c.release_path}"
289
- raise
290
- end
286
+ def with_failed_release_cleanup
287
+ yield
288
+ rescue Exception
289
+ sudo "rm -rf #{c.release_path}"
290
+ raise
291
+ end
291
292
 
292
- def warn_about_missing_lockfile
293
- info "!>"
294
- info "!> WARNING: Gemfile.lock is missing!"
295
- info "!> You can get different gems in production than what you tested with."
296
- info "!> You can get different gems on every deployment even if your Gemfile hasn't changed."
297
- info "!> Deploying may take a long time."
298
- info "!>"
299
- info "!> Fix this by running \"git add Gemfile.lock; git commit\" and deploying again."
300
- info "!> If you don't have a Gemfile.lock, run \"bundle lock\" to create one."
301
- info "!>"
302
- info "!> This deployment will use bundler #{default_09_bundler} to run 'bundle install'."
303
- info "!>"
304
- end
293
+ def warn_about_missing_lockfile
294
+ info "!>"
295
+ info "!> WARNING: Gemfile.lock is missing!"
296
+ info "!> You can get different gems in production than what you tested with."
297
+ info "!> You can get different gems on every deployment even if your Gemfile hasn't changed."
298
+ info "!> Deploying may take a long time."
299
+ info "!>"
300
+ info "!> Fix this by running \"git add Gemfile.lock; git commit\" and deploying again."
301
+ info "!> If you don't have a Gemfile.lock, run \"bundle lock\" to create one."
302
+ info "!>"
303
+ info "!> This deployment will use bundler #{default_09_bundler} to run 'bundle install'."
304
+ info "!>"
305
+ end
305
306
 
306
- def get_bundler_installer(lockfile)
307
- parser = LockfileParser.new(File.read(lockfile))
308
- case parser.lockfile_version
309
- when :bundler09
310
- bundler_09_installer(parser.bundler_version || default_09_bundler)
311
- when :bundler10
312
- bundler_10_installer(parser.bundler_version || default_10_bundler)
313
- else
314
- raise "Unknown lockfile version #{parser.lockfile_version}"
307
+ def get_bundler_installer(lockfile)
308
+ parser = LockfileParser.new(File.read(lockfile))
309
+ case parser.lockfile_version
310
+ when :bundler09
311
+ bundler_09_installer(parser.bundler_version || default_09_bundler)
312
+ when :bundler10
313
+ bundler_10_installer(parser.bundler_version || default_10_bundler)
314
+ else
315
+ raise "Unknown lockfile version #{parser.lockfile_version}"
316
+ end
315
317
  end
316
- end
317
- public :get_bundler_installer
318
+ public :get_bundler_installer
318
319
 
319
- def bundler_09_installer(version)
320
- BundleInstaller.new(version, '--without=development --without=test')
321
- end
320
+ def bundler_09_installer(version)
321
+ BundleInstaller.new(version, '--without=development --without=test')
322
+ end
322
323
 
323
- def bundler_10_installer(version)
324
- BundleInstaller.new(version,
325
- "--deployment --path #{c.shared_path}/bundled_gems --binstubs #{c.binstubs_path} --without development test")
326
- end
324
+ def bundler_10_installer(version)
325
+ BundleInstaller.new(version,
326
+ "--deployment --path #{c.shared_path}/bundled_gems --binstubs #{c.binstubs_path} --without development test")
327
+ end
327
328
 
328
- def default_09_bundler() "0.9.26" end
329
- def default_10_bundler() "1.0.0" end
329
+ def default_09_bundler() "0.9.26" end
330
+ def default_10_bundler() "1.0.0" end
330
331
 
331
- end # DeployBase
332
+ end # DeployBase
332
333
 
333
- class Deploy < DeployBase
334
- def self.new(config)
335
- # include the correct fetch strategy
336
- include EY::Strategies.const_get(config.strategy)::Helpers
337
- super
334
+ class Deploy < DeployBase
335
+ def self.new(config)
336
+ # include the correct fetch strategy
337
+ include EY::Serverside::Strategies.const_get(config.strategy)::Helpers
338
+ super
339
+ end
338
340
  end
339
341
 
340
342
  end