deployinator 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/deployinator/deploy.rb +38 -20
  2. metadata +2 -2
@@ -221,7 +221,7 @@ namespace :deploy do
221
221
  end
222
222
  before 'bundler:install', 'deploy:install_bundler'
223
223
 
224
- desc 'Restart application'
224
+ desc 'Restart application using bluepill restart inside the docker container.'
225
225
  task :restart => [:set_www_data_user_id, :install_config_files] do
226
226
  on roles(:app), in: :sequence, wait: 5 do
227
227
  if test "docker", "inspect", fetch(:ruby_container_name), "&>", "/dev/null"
@@ -229,8 +229,39 @@ namespace :deploy do
229
229
  "--format='{{.State.Restarting}}'",
230
230
  fetch(:ruby_container_name)).strip == "true"
231
231
  execute("docker", "stop", fetch(:ruby_container_name))
232
- execute("docker", "wait", fetch(:ruby_container_name))
233
232
  end
233
+ if (capture "docker", "inspect",
234
+ "--format='{{.State.Running}}'",
235
+ fetch(:ruby_container_name)).strip == "true"
236
+ execute(
237
+ "docker", "exec", "--tty",
238
+ fetch(:ruby_container_name),
239
+ "#{fetch(:deploy_to)}/shared/bundle/bin/bluepill",
240
+ fetch(:application), "restart"
241
+ )
242
+ end
243
+ else
244
+ as :root do
245
+ paths = [
246
+ fetch(:external_socket_path),
247
+ "#{fetch(:deploy_to)}/current/public",
248
+ "#{fetch(:deploy_to)}/shared/tmp",
249
+ "#{fetch(:deploy_to)}/shared/log/production.log"
250
+ ].join(' ')
251
+ execute "chown", "-R", "#{fetch(:www_data_user_id)}:#{fetch(:www_data_user_id)}", paths
252
+ execute "chown", "-R", "#{fetch(:deployer_user_id)}:#{fetch(:deployer_user_id)}", "#{fetch(:deploy_to)}/shared/bundle"
253
+ execute("rm", "-f", "#{fetch(:external_socket_path)}/unicorn.pid")
254
+ end
255
+ execute("docker", "run", fetch(:docker_run_bluepill_command))
256
+ end
257
+ end
258
+ end
259
+ after :publishing, :restart
260
+
261
+ desc 'Restart application by recreating the docker container.'
262
+ namespace :restart do
263
+ task :force do
264
+ on roles(:app), in: :sequence, wait: 5 do
234
265
  if (capture "docker", "inspect",
235
266
  "--format='{{.State.Running}}'",
236
267
  fetch(:ruby_container_name)).strip == "true"
@@ -241,10 +272,9 @@ namespace :deploy do
241
272
  fetch(:application), "stop"
242
273
  )
243
274
  sleep 5
244
- execute("docker", "stop", fetch(:ruby_container_name))
245
- execute("docker", "wait", fetch(:ruby_container_name))
246
275
  end
247
- sleep 2
276
+ execute("docker", "stop", fetch(:ruby_container_name))
277
+ execute("docker", "wait", fetch(:ruby_container_name))
248
278
  begin
249
279
  execute("docker", "rm", fetch(:ruby_container_name))
250
280
  rescue
@@ -252,29 +282,17 @@ namespace :deploy do
252
282
  begin
253
283
  execute("docker", "rm", fetch(:ruby_container_name))
254
284
  rescue
255
- fatal "We were not able to remove the container for some reason. Try running 'cap <stage> deploy:restart' again."
285
+ fatal "We were not able to remove the container for some reason. Try running 'cap <stage> deploy:restart:force' again."
256
286
  end
257
287
  end
288
+ Rake::Task['deploy:restart'].invoke
258
289
  end
259
- as :root do
260
- [
261
- fetch(:external_socket_path),
262
- "#{fetch(:deploy_to)}/current/public",
263
- "#{fetch(:deploy_to)}/shared/tmp",
264
- "#{fetch(:deploy_to)}/shared/log/production.log"
265
- ].each do |directory|
266
- execute "chown", "-R", "#{fetch(:www_data_user_id)}:#{fetch(:www_data_user_id)}", directory
267
- end
268
- execute "chown", "-R", "#{fetch(:deployer_user_id)}:#{fetch(:deployer_user_id)}", "#{fetch(:deploy_to)}/shared/bundle"
269
- execute("rm", "-f", "#{fetch(:external_socket_path)}/unicorn.pid")
270
- end
271
- execute("docker", "run", fetch(:docker_run_bluepill_command))
272
290
  end
273
291
  end
274
- after :publishing, :restart
275
292
 
276
293
  after :publishing, :check_nginx_running do
277
294
  on primary fetch(:migration_role) do
295
+ # TODO fix false negative when nginx_container_name is unset
278
296
  if test "docker", "inspect", fetch(:nginx_container_name), "&>", "/dev/null"
279
297
  if (capture "docker", "inspect",
280
298
  "--format='{{.State.Running}}'",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deployinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-12 00:00:00.000000000 Z
12
+ date: 2014-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano