From c37d69856ecf1ee0bec39e68da93efea054c2e49 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Wed, 3 Jun 2015 21:08:03 -0500 Subject: [PATCH 01/20] Collect callbacks to run before stopping, and after starting an image We need to tell our load balancers about these two events. We can provide callbacks that allow us to do so. --- lib/centurion/deploy_dsl.rb | 12 ++++++++++++ spec/deploy_dsl_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index 726778cf..e76aaa22 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -146,6 +146,18 @@ def defined_restart_policy Centurion::Service::RestartPolicy.new(fetch(:restart_policy_name, 'on-failure'), fetch(:restart_policy_max_retry_count, 10)) end + def before_stopping_image(callback = nil, &block) + callbacks = fetch(:before_stopping_image_callbacks, []) + callbacks << (callback || block) + set(:before_stopping_image_callbacks, callbacks) + end + + def after_image_started(callback = nil, &block) + callbacks = fetch(:after_image_started_callbacks, []) + callbacks << (callback || block) + set(:after_image_started_callbacks, callbacks) + end + private def build_server_group diff --git a/spec/deploy_dsl_spec.rb b/spec/deploy_dsl_spec.rb index cc6c3cbb..36a33af9 100644 --- a/spec/deploy_dsl_spec.rb +++ b/spec/deploy_dsl_spec.rb @@ -210,4 +210,36 @@ class DeployDSLTest DeployDSLTest.set(:image, 'charlemagne') expect(DeployDSLTest.defined_service.image).to eq('charlemagne:roland') end + + describe '#before_stopping_image' do + it 'collects before_stopping_image callbacks as procs' do + callback = ->(server) { } + DeployDSLTest.before_stopping_image callback + expect(DeployDSLTest.fetch(:before_stopping_image_callbacks)).to eq([callback]) + end + + it 'collects before_stopping_image callbacks as blocks' do + DeployDSLTest.before_stopping_image do |_| + 'from the block' + end + callback = DeployDSLTest.fetch(:before_stopping_image_callbacks)[0] + expect(callback.call).to eq('from the block') + end + end + + describe '#after_image_started' do + it 'collects after_image_started callbacks as procs' do + callback = ->(server) { } + DeployDSLTest.after_image_started callback + expect(DeployDSLTest.fetch(:after_image_started_callbacks)).to eq([callback]) + end + + it 'collects after_image_started callbacks as blocks' do + DeployDSLTest.after_image_started do |_| + 'from the block' + end + callback = DeployDSLTest.fetch(:after_image_started_callbacks)[0] + expect(callback.call).to eq('from the block') + end + end end From f6120ae98973620b9fbd97dd276108e0c0fd6694 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Fri, 5 Jun 2015 21:10:05 -0500 Subject: [PATCH 02/20] add before stopping callbacks --- lib/centurion/deploy.rb | 5 ++++ lib/centurion/deploy_callbacks.rb | 18 ++++++++++++++ spec/deploy_callbacks_spec.rb | 40 +++++++++++++++++++++++++++++++ spec/deploy_spec.rb | 1 + 4 files changed, 64 insertions(+) create mode 100644 lib/centurion/deploy_callbacks.rb create mode 100644 spec/deploy_callbacks_spec.rb diff --git a/lib/centurion/deploy.rb b/lib/centurion/deploy.rb index 74b8c450..ecf7ab19 100644 --- a/lib/centurion/deploy.rb +++ b/lib/centurion/deploy.rb @@ -1,11 +1,16 @@ require 'excon' require 'socket' +require_relative 'deploy_callbacks' + module Centurion; end module Centurion::Deploy + prepend Centurion::DeployCallbacks + FAILED_CONTAINER_VALIDATION = 100 + def stop_containers(target_server, service, timeout = 30) old_containers = if service.public_ports.nil? || service.public_ports.empty? || service.network_mode == 'host' info "Looking for containers with names like #{service.name}" diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb new file mode 100644 index 00000000..f8070aba --- /dev/null +++ b/lib/centurion/deploy_callbacks.rb @@ -0,0 +1,18 @@ +module Centurion + # Callbacks to allow hooking into the deploy lifecycle. This could + # be useful to communicate with a loadbalancer, chat room, etc. + module DeployCallbacks + def stop_containers(target_server, service, timeout = 30) + before_stopping_container_callbacks.each do |callback| + callback.call target_server + end + super target_server, service, timeout + end + + private + + def before_stopping_container_callbacks + fetch :before_stopping_container_callbacks, [] + end + end +end diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb new file mode 100644 index 00000000..65f93541 --- /dev/null +++ b/spec/deploy_callbacks_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' +require 'centurion' + +RSpec.describe Centurion::DeployCallbacks do + describe 'before stopping callback' do + let(:callback) { [double, double] } + let(:klass) do + Class.new do + prepend Centurion::DeployCallbacks + def stop_containers(server, service, timeout) + doing_it_now server, service, timeout + end + end + end + let(:object) do + klass.new.tap do |o| + allow(o).to receive(:fetch) + .with(:before_stopping_container_callbacks, []) + .and_return callbacks + end + end + let(:server) { double :server } + let(:service) { double :service } + let(:timeout) { double :timeout } + let(:callbacks) { [double, double] } + + it 'invokes all the callback before stopping the container' do + callbacks.each do |callback| + expect(callback).to receive(:call) + .with(server) + .ordered + end + expect(object).to receive(:doing_it_now) + .with(server, service, timeout) + .ordered + + object.stop_containers server, service, timeout + end + end +end diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index 83624f60..eb279f41 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -22,6 +22,7 @@ before do allow(test_deploy).to receive(:fetch).and_return nil allow(test_deploy).to receive(:host_ip).and_return('172.16.0.1') + allow(test_deploy).to receive(:fetch).with(:before_stopping_container_callbacks, []).and_return([]) end describe '#http_status_ok?' do From b51f31387251bac0face4efb1bf76bb64aedd1f4 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Fri, 5 Jun 2015 21:21:47 -0500 Subject: [PATCH 03/20] add after starting callbacks --- lib/centurion/deploy_callbacks.rb | 17 ++++++++-- spec/deploy_callbacks_spec.rb | 53 +++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb index f8070aba..6f103171 100644 --- a/lib/centurion/deploy_callbacks.rb +++ b/lib/centurion/deploy_callbacks.rb @@ -2,11 +2,18 @@ module Centurion # Callbacks to allow hooking into the deploy lifecycle. This could # be useful to communicate with a loadbalancer, chat room, etc. module DeployCallbacks - def stop_containers(target_server, service, timeout = 30) + def stop_containers(server, service, timeout = 30) before_stopping_container_callbacks.each do |callback| - callback.call target_server + callback.call server + end + super server, service, timeout + end + + def start_new_container(server, service, restart_policy) + super server, service, restart_policy + after_new_container_started_callbacks.each do |callback| + callback.call server end - super target_server, service, timeout end private @@ -14,5 +21,9 @@ def stop_containers(target_server, service, timeout = 30) def before_stopping_container_callbacks fetch :before_stopping_container_callbacks, [] end + + def after_new_container_started_callbacks + fetch :after_new_container_started_callbacks, [] + end end end diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb index 65f93541..829d88a7 100644 --- a/spec/deploy_callbacks_spec.rb +++ b/spec/deploy_callbacks_spec.rb @@ -2,16 +2,24 @@ require 'centurion' RSpec.describe Centurion::DeployCallbacks do - describe 'before stopping callback' do - let(:callback) { [double, double] } - let(:klass) do - Class.new do - prepend Centurion::DeployCallbacks - def stop_containers(server, service, timeout) - doing_it_now server, service, timeout - end + let(:server) { double :server } + let(:service) { double :service } + let(:callbacks) { [double, double] } + + let(:klass) do + Class.new do + prepend Centurion::DeployCallbacks + def stop_containers(server, service, timeout) + stopping_it_now server, service, timeout + end + + def start_new_container(server, service, restart_policy) + starting_it_now server, service, restart_policy end end + end + + describe 'before stopping callback' do let(:object) do klass.new.tap do |o| allow(o).to receive(:fetch) @@ -19,22 +27,41 @@ def stop_containers(server, service, timeout) .and_return callbacks end end - let(:server) { double :server } - let(:service) { double :service } let(:timeout) { double :timeout } - let(:callbacks) { [double, double] } - it 'invokes all the callback before stopping the container' do callbacks.each do |callback| expect(callback).to receive(:call) .with(server) .ordered end - expect(object).to receive(:doing_it_now) + expect(object).to receive(:stopping_it_now) .with(server, service, timeout) .ordered object.stop_containers server, service, timeout end end + + describe 'after started callback' do + let(:object) do + klass.new.tap do |o| + allow(o).to receive(:fetch) + .with(:after_new_container_started_callbacks, []) + .and_return callbacks + end + end + let(:restart_policy) { double } + it 'invokes all the callbacks after the container is started' do + expect(object).to receive(:starting_it_now) + .with(server, service, restart_policy) + .ordered + callbacks.each do |callback| + expect(callback).to receive(:call) + .with(server) + .ordered + end + + object.start_new_container server, service, restart_policy + end + end end From 7c49d1742f79f0ea1194232eb44cfb97013484fc Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Fri, 5 Jun 2015 21:37:51 -0500 Subject: [PATCH 04/20] converge on common names to store the callbacks --- lib/centurion/deploy_callbacks.rb | 7 ++++--- spec/deploy_callbacks_spec.rb | 4 ++-- spec/deploy_spec.rb | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb index 6f103171..7c2d64ac 100644 --- a/lib/centurion/deploy_callbacks.rb +++ b/lib/centurion/deploy_callbacks.rb @@ -10,20 +10,21 @@ def stop_containers(server, service, timeout = 30) end def start_new_container(server, service, restart_policy) - super server, service, restart_policy + result = super server, service, restart_policy after_new_container_started_callbacks.each do |callback| callback.call server end + result end private def before_stopping_container_callbacks - fetch :before_stopping_container_callbacks, [] + fetch :before_stopping_image_callbacks, [] end def after_new_container_started_callbacks - fetch :after_new_container_started_callbacks, [] + fetch :after_image_started_callbacks, [] end end end diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb index 829d88a7..49a8f6b5 100644 --- a/spec/deploy_callbacks_spec.rb +++ b/spec/deploy_callbacks_spec.rb @@ -23,7 +23,7 @@ def start_new_container(server, service, restart_policy) let(:object) do klass.new.tap do |o| allow(o).to receive(:fetch) - .with(:before_stopping_container_callbacks, []) + .with(:before_stopping_image_callbacks, []) .and_return callbacks end end @@ -46,7 +46,7 @@ def start_new_container(server, service, restart_policy) let(:object) do klass.new.tap do |o| allow(o).to receive(:fetch) - .with(:after_new_container_started_callbacks, []) + .with(:after_image_started_callbacks, []) .and_return callbacks end end diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index eb279f41..0893bcfe 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -22,7 +22,8 @@ before do allow(test_deploy).to receive(:fetch).and_return nil allow(test_deploy).to receive(:host_ip).and_return('172.16.0.1') - allow(test_deploy).to receive(:fetch).with(:before_stopping_container_callbacks, []).and_return([]) + allow(test_deploy).to receive(:fetch).with(:before_stopping_image_callbacks, []).and_return([]) + allow(test_deploy).to receive(:fetch).with(:after_image_started_callbacks, []).and_return([]) end describe '#http_status_ok?' do From 285bbd245c96ac4fd40ed49b30584c54618fe0d4 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Fri, 5 Jun 2015 21:38:25 -0500 Subject: [PATCH 05/20] make sure nil callbacks do not get added --- lib/centurion/deploy_dsl.rb | 2 ++ spec/deploy_dsl_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index e76aaa22..60d4ad8c 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -147,12 +147,14 @@ def defined_restart_policy end def before_stopping_image(callback = nil, &block) + return unless callback || block callbacks = fetch(:before_stopping_image_callbacks, []) callbacks << (callback || block) set(:before_stopping_image_callbacks, callbacks) end def after_image_started(callback = nil, &block) + return unless callback || block callbacks = fetch(:after_image_started_callbacks, []) callbacks << (callback || block) set(:after_image_started_callbacks, callbacks) diff --git a/spec/deploy_dsl_spec.rb b/spec/deploy_dsl_spec.rb index 36a33af9..bc53ff20 100644 --- a/spec/deploy_dsl_spec.rb +++ b/spec/deploy_dsl_spec.rb @@ -212,8 +212,13 @@ class DeployDSLTest end describe '#before_stopping_image' do + it 'does not add nil callbacks' do + DeployDSLTest.before_stopping_image + expect(DeployDSLTest.fetch(:before_stopping_image_callbacks, [])).to eq([]) + end + it 'collects before_stopping_image callbacks as procs' do - callback = ->(server) { } + callback = ->(_) {} DeployDSLTest.before_stopping_image callback expect(DeployDSLTest.fetch(:before_stopping_image_callbacks)).to eq([callback]) end @@ -228,6 +233,11 @@ class DeployDSLTest end describe '#after_image_started' do + it 'does not add nil callbacks' do + DeployDSLTest.after_image_started + expect(DeployDSLTest.fetch(:after_image_started_callbacks, [])).to eq([]) + end + it 'collects after_image_started callbacks as procs' do callback = ->(server) { } DeployDSLTest.after_image_started callback From 47f097ca794af8d90186db476d63e7e23a4dd947 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Fri, 5 Jun 2015 22:21:08 -0500 Subject: [PATCH 06/20] add notes in the readme about the callbacks --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 3ddf831d..aff09c9d 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,22 @@ You have to set the following keys: Modify the paths as appropriate for your cert, ca, and key files. +### Callbacks + +You can create callbacks to perform custom actions during a deploy. + +```ruby + task :production => :common do + before_stopping_image do |server| + my_loadbalancer.disable server.hostname + end + + after_image_started do |server| + my_loadbalancer.enable server.hostname + end + end +``` + Deploying --------- From a33712e6cac55edd30e6b717acd9b126ad7a9f8f Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Fri, 5 Jun 2015 22:54:43 -0500 Subject: [PATCH 07/20] refactor callbacks --- lib/centurion/deploy_dsl.rb | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index 60d4ad8c..74fc15ec 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -147,20 +147,35 @@ def defined_restart_policy end def before_stopping_image(callback = nil, &block) - return unless callback || block - callbacks = fetch(:before_stopping_image_callbacks, []) - callbacks << (callback || block) - set(:before_stopping_image_callbacks, callbacks) + collect_callback :before_stopping_image_callbacks, callback, &block end def after_image_started(callback = nil, &block) + collect_callback :after_image_started_callbacks, callback, &block + end + + private + + def collect_callback(name, callback = nil, &block) return unless callback || block - callbacks = fetch(:after_image_started_callbacks, []) + abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call) + callbacks = fetch(name, []) callbacks << (callback || block) - set(:after_image_started_callbacks, callbacks) + set(name, callbacks) + end + + def service_under_construction + service = fetch(:service, + Centurion::Service.from_hash( + fetch(:project), + image: fetch(:image), + hostname: fetch(:container_hostname), + dns: fetch(:custom_dns) + ) + ) + set(:service, service) end - private def build_server_group hosts, docker_path = fetch(:hosts, []), fetch(:docker_path) From fac0cf58eb9c315df1547fdb01f06dc84c3f6b6f Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 13:06:28 -0500 Subject: [PATCH 08/20] collect after_health_check_ok callbacks --- lib/centurion/deploy_dsl.rb | 4 ++++ spec/deploy_dsl_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index 74fc15ec..0944b6c4 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -154,6 +154,10 @@ def after_image_started(callback = nil, &block) collect_callback :after_image_started_callbacks, callback, &block end + def after_health_check_ok(callback = nil, &block) + collect_callback :after_health_check_ok_callbacks, callback, &block + end + private def collect_callback(name, callback = nil, &block) diff --git a/spec/deploy_dsl_spec.rb b/spec/deploy_dsl_spec.rb index bc53ff20..8d35573e 100644 --- a/spec/deploy_dsl_spec.rb +++ b/spec/deploy_dsl_spec.rb @@ -252,4 +252,25 @@ class DeployDSLTest expect(callback.call).to eq('from the block') end end + + describe '#after_health_check_ok' do + it 'does not add nil callbacks' do + DeployDSLTest.after_health_check_ok + expect(DeployDSLTest.fetch(:after_health_check_ok_callbacks, [])).to eq([]) + end + + it 'collects after_health_check_ok callbacks as procs' do + callback = ->(server) { } + DeployDSLTest.after_health_check_ok callback + expect(DeployDSLTest.fetch(:after_health_check_ok_callbacks)).to eq([callback]) + end + + it 'collects after_health_check_ok callbacks as blocks' do + DeployDSLTest.after_health_check_ok do |_| + 'from the block' + end + callback = DeployDSLTest.fetch(:after_health_check_ok_callbacks)[0] + expect(callback.call).to eq('from the block') + end + end end From 6938de75db3bc7d0e292381e849ba16246e4137c Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 13:22:11 -0500 Subject: [PATCH 09/20] add test that it returns a list of all the callbacks --- lib/centurion/deploy_dsl.rb | 10 +++-- spec/deploy_dsl_spec.rb | 80 ++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index 0944b6c4..e6603628 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -161,11 +161,13 @@ def after_health_check_ok(callback = nil, &block) private def collect_callback(name, callback = nil, &block) - return unless callback || block - abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call) callbacks = fetch(name, []) - callbacks << (callback || block) - set(name, callbacks) + if callback || block + abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call) + callbacks << (callback || block) + set(name, callbacks) + end + callbacks end def service_under_construction diff --git a/spec/deploy_dsl_spec.rb b/spec/deploy_dsl_spec.rb index 8d35573e..355030bd 100644 --- a/spec/deploy_dsl_spec.rb +++ b/spec/deploy_dsl_spec.rb @@ -216,61 +216,57 @@ class DeployDSLTest DeployDSLTest.before_stopping_image expect(DeployDSLTest.fetch(:before_stopping_image_callbacks, [])).to eq([]) end + end - it 'collects before_stopping_image callbacks as procs' do - callback = ->(_) {} - DeployDSLTest.before_stopping_image callback - expect(DeployDSLTest.fetch(:before_stopping_image_callbacks)).to eq([callback]) - end + describe 'callbacks' do + shared_examples_for 'a callback for' do |callback_name| + let(:callbacks) { DeployDSLTest.fetch("#{callback_name}_callbacks".to_sym, []) } - it 'collects before_stopping_image callbacks as blocks' do - DeployDSLTest.before_stopping_image do |_| - 'from the block' + it 'does not add nil callbacks' do + DeployDSLTest.send callback_name + expect(callbacks).to eq([]) end - callback = DeployDSLTest.fetch(:before_stopping_image_callbacks)[0] - expect(callback.call).to eq('from the block') - end - end - describe '#after_image_started' do - it 'does not add nil callbacks' do - DeployDSLTest.after_image_started - expect(DeployDSLTest.fetch(:after_image_started_callbacks, [])).to eq([]) - end + it 'collects callbacks as procs' do + callback = ->(_) {} + DeployDSLTest.send callback_name, callback + expect(callbacks).to eq([callback]) + end - it 'collects after_image_started callbacks as procs' do - callback = ->(server) { } - DeployDSLTest.after_image_started callback - expect(DeployDSLTest.fetch(:after_image_started_callbacks)).to eq([callback]) - end + it 'collects callbacks as blocks' do + DeployDSLTest.send callback_name do |_| + 'from the block' + end + callback = callbacks[0] + expect(callback.call).to eq('from the block') + end + + it 'returns a list of all callbacks when adding one' do + callback1 = ->(_) {} + callback2 = ->(_) {} + DeployDSLTest.send callback_name, callback1 + returned_callbacks = DeployDSLTest.send callback_name, callback2 + expect(returned_callbacks).to eq([callback1, callback2]) + end - it 'collects after_image_started callbacks as blocks' do - DeployDSLTest.after_image_started do |_| - 'from the block' + it 'returns a list of all callbacks when adding none' do + callback1 = ->(_) {} + DeployDSLTest.send callback_name, callback1 + returned_callbacks = DeployDSLTest.send callback_name + expect(returned_callbacks).to eq([callback1]) end - callback = DeployDSLTest.fetch(:after_image_started_callbacks)[0] - expect(callback.call).to eq('from the block') end - end - describe '#after_health_check_ok' do - it 'does not add nil callbacks' do - DeployDSLTest.after_health_check_ok - expect(DeployDSLTest.fetch(:after_health_check_ok_callbacks, [])).to eq([]) + describe '#before_stopping_image' do + it_behaves_like 'a callback for', :before_stopping_image end - it 'collects after_health_check_ok callbacks as procs' do - callback = ->(server) { } - DeployDSLTest.after_health_check_ok callback - expect(DeployDSLTest.fetch(:after_health_check_ok_callbacks)).to eq([callback]) + describe '#after_image_started' do + it_behaves_like 'a callback for', :after_image_started end - it 'collects after_health_check_ok callbacks as blocks' do - DeployDSLTest.after_health_check_ok do |_| - 'from the block' - end - callback = DeployDSLTest.fetch(:after_health_check_ok_callbacks)[0] - expect(callback.call).to eq('from the block') + describe '#after_health_check_ok' do + it_behaves_like 'a callback for', :after_health_check_ok end end end From 2e533ba84b4adefe1498b55f4490021d7badc8ca Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 19:51:27 -0500 Subject: [PATCH 10/20] Remove adding the callbacks by default in the deploy module Since prepend is a Ruby 2.0 thing, there is probably a better way to get this functionality without sprinkling all the callbacks into deploy. --- lib/centurion/deploy.rb | 1 - spec/deploy_spec.rb | 2 -- 2 files changed, 3 deletions(-) diff --git a/lib/centurion/deploy.rb b/lib/centurion/deploy.rb index ecf7ab19..6f824fba 100644 --- a/lib/centurion/deploy.rb +++ b/lib/centurion/deploy.rb @@ -6,7 +6,6 @@ module Centurion; end module Centurion::Deploy - prepend Centurion::DeployCallbacks FAILED_CONTAINER_VALIDATION = 100 diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index 0893bcfe..83624f60 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -22,8 +22,6 @@ before do allow(test_deploy).to receive(:fetch).and_return nil allow(test_deploy).to receive(:host_ip).and_return('172.16.0.1') - allow(test_deploy).to receive(:fetch).with(:before_stopping_image_callbacks, []).and_return([]) - allow(test_deploy).to receive(:fetch).with(:after_image_started_callbacks, []).and_return([]) end describe '#http_status_ok?' do From dfb7a24dc1fa23bd4f1b467a687d5e802f7a47f2 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 20:45:33 -0500 Subject: [PATCH 11/20] create dry callback test --- spec/deploy_callbacks_spec.rb | 87 ++++++++++++++++------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb index 49a8f6b5..241761c8 100644 --- a/spec/deploy_callbacks_spec.rb +++ b/spec/deploy_callbacks_spec.rb @@ -2,66 +2,59 @@ require 'centurion' RSpec.describe Centurion::DeployCallbacks do - let(:server) { double :server } - let(:service) { double :service } - let(:callbacks) { [double, double] } + shared_examples_for 'a callback' do |callback| + let(:server) { double :server } + let(:service) { double :service } + let(:callbacks) { [double, double] } + let(:callback_name) { "#{callback}_callbacks".to_sym } - let(:klass) do - Class.new do - prepend Centurion::DeployCallbacks - def stop_containers(server, service, timeout) - stopping_it_now server, service, timeout - end - - def start_new_container(server, service, restart_policy) - starting_it_now server, service, restart_policy + let(:klass) do + Class.new do + include Centurion::DeployCallbacks + def method_missing(method_name, *_args) + doing method_name + end end end - end - describe 'before stopping callback' do let(:object) do klass.new.tap do |o| - allow(o).to receive(:fetch) - .with(:before_stopping_image_callbacks, []) - .and_return callbacks + allow(o).to receive(:fetch).with(callback_name, []).and_return callbacks end end - let(:timeout) { double :timeout } - it 'invokes all the callback before stopping the container' do - callbacks.each do |callback| - expect(callback).to receive(:call) - .with(server) - .ordered - end - expect(object).to receive(:stopping_it_now) - .with(server, service, timeout) - .ordered + end + + shared_examples_for 'a before callback' do |callback, method_name| + include_examples 'a callback', callback - object.stop_containers server, service, timeout + it 'invokes all the callback before the method' do + callbacks.each { |cb| expect(cb).to receive(:call).with(server).ordered } + expect(object).to receive(:doing).with(method_name).ordered + subject end end - describe 'after started callback' do - let(:object) do - klass.new.tap do |o| - allow(o).to receive(:fetch) - .with(:after_image_started_callbacks, []) - .and_return callbacks - end - end - let(:restart_policy) { double } - it 'invokes all the callbacks after the container is started' do - expect(object).to receive(:starting_it_now) - .with(server, service, restart_policy) - .ordered - callbacks.each do |callback| - expect(callback).to receive(:call) - .with(server) - .ordered - end + shared_examples_for 'an after callback' do |callback, method_name| + include_examples 'a callback', callback - object.start_new_container server, service, restart_policy + it 'invokes all the callback before the method' do + expect(object).to receive(:doing).with(method_name).ordered + callbacks.each { |cb| expect(cb).to receive(:call).with(server).ordered } + subject end end + + describe 'before stopping callback' do + subject { object.stop_containers server, service } + it_behaves_like 'a before callback', + :before_stopping_image, + :stop_containers + end + + describe 'after started callback' do + subject { object.start_new_container server, service, double } + it_behaves_like 'an after callback', + :after_image_started, + :start_new_container + end end From 474bf7b6081310d3372b7d30f78f272bfb216d74 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 20:56:44 -0500 Subject: [PATCH 12/20] add after health check ok callback --- lib/centurion/deploy_callbacks.rb | 20 ++++++++++++++++++++ spec/deploy_callbacks_spec.rb | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb index 7c2d64ac..3c6bc7d2 100644 --- a/lib/centurion/deploy_callbacks.rb +++ b/lib/centurion/deploy_callbacks.rb @@ -17,6 +17,22 @@ def start_new_container(server, service, restart_policy) result end + def wait_for_health_check_ok(health_check_method, server, port, endpoint, image_id, tag, sleep_time=5, retries=12) + result = super health_check_method, + server, + port, + endpoint, + image_id, + tag, + sleep_time, + retries + + after_health_check_ok_callbacks.each do |callback| + callback.call server + end + result + end + private def before_stopping_container_callbacks @@ -26,5 +42,9 @@ def before_stopping_container_callbacks def after_new_container_started_callbacks fetch :after_image_started_callbacks, [] end + + def after_health_check_ok_callbacks + fetch :after_health_check_ok_callbacks, [] + end end end diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb index 241761c8..0f8ef2f5 100644 --- a/spec/deploy_callbacks_spec.rb +++ b/spec/deploy_callbacks_spec.rb @@ -57,4 +57,23 @@ def method_missing(method_name, *_args) :after_image_started, :start_new_container end + + describe 'after health check ok callback' do + let(:args) do + [ + double(:health_check_method), + server, + double(:port), + double(:endpoint), + double(:image_id), + double(:tag), + double(:sleep), + double(:retries) + ] + end + subject { object.wait_for_health_check_ok(*args) } + it_behaves_like 'an after callback', + :after_health_check_ok, + :wait_for_health_check_ok + end end From 076e5b99638ee1e46834640da6692e03506e8254 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 21:00:52 -0500 Subject: [PATCH 13/20] dry up the callbacks helpers --- lib/centurion/deploy_callbacks.rb | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb index 3c6bc7d2..6513b539 100644 --- a/lib/centurion/deploy_callbacks.rb +++ b/lib/centurion/deploy_callbacks.rb @@ -3,7 +3,7 @@ module Centurion # be useful to communicate with a loadbalancer, chat room, etc. module DeployCallbacks def stop_containers(server, service, timeout = 30) - before_stopping_container_callbacks.each do |callback| + callbacks(:before_stopping_image).each do |callback| callback.call server end super server, service, timeout @@ -11,7 +11,7 @@ def stop_containers(server, service, timeout = 30) def start_new_container(server, service, restart_policy) result = super server, service, restart_policy - after_new_container_started_callbacks.each do |callback| + callbacks(:after_image_started).each do |callback| callback.call server end result @@ -27,7 +27,7 @@ def wait_for_health_check_ok(health_check_method, server, port, endpoint, image_ sleep_time, retries - after_health_check_ok_callbacks.each do |callback| + callbacks(:after_health_check_ok).each do |callback| callback.call server end result @@ -35,16 +35,8 @@ def wait_for_health_check_ok(health_check_method, server, port, endpoint, image_ private - def before_stopping_container_callbacks - fetch :before_stopping_image_callbacks, [] - end - - def after_new_container_started_callbacks - fetch :after_image_started_callbacks, [] - end - - def after_health_check_ok_callbacks - fetch :after_health_check_ok_callbacks, [] + def callbacks(name) + fetch "#{name}_callbacks".to_sym, [] end end end From 1389705140fec4d7e03bc1cc680c8d0adf3b1151 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Sun, 7 Jun 2015 21:03:16 -0500 Subject: [PATCH 14/20] Mix the callbacks in before the deploy This should let the callbacks have a chance to execute first and call up to the deploy module at the proper time. --- lib/tasks/deploy.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/deploy.rake b/lib/tasks/deploy.rake index 3598dae8..27fce150 100644 --- a/lib/tasks/deploy.rake +++ b/lib/tasks/deploy.rake @@ -47,6 +47,7 @@ end namespace :deploy do include Centurion::Deploy + include Centurion::DeployCallbacks namespace :dogestry do task :validate_pull_image do From bab5e533e7a714092617efe54b33f544d6366aa2 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Mon, 8 Jun 2015 20:32:35 -0500 Subject: [PATCH 15/20] add travis My initial approach used some Ruby 2.0 features. I thought it would be good to ensure backwards compatibility to older Rubies. --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 04bd7cb9..afd4b2e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,9 @@ language: ruby before_install: - gem update - gem install bundler +======= +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.0 + - 2.2.0 From 8b146f48292f1af4ef74c0ec12a2fbfa5645a1bb Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Mon, 8 Jun 2015 20:58:30 -0500 Subject: [PATCH 16/20] add after_health_check_ok to readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index aff09c9d..06c6e1e1 100644 --- a/README.md +++ b/README.md @@ -347,6 +347,10 @@ You can create callbacks to perform custom actions during a deploy. end after_image_started do |server| + my_chat_server.post "#{server.hostname} started my image....waiting for health check" + end + + after_health_check_ok do |server| my_loadbalancer.enable server.hostname end end From 208155b8624dc384ef72498b6025e86ce3bfef24 Mon Sep 17 00:00:00 2001 From: Mark Borcherding Date: Tue, 21 Jul 2015 21:50:00 -0500 Subject: [PATCH 17/20] Emit events in a more generic manner --- lib/centurion/deploy_callbacks.rb | 41 +++++++++++++----------------- lib/centurion/deploy_dsl.rb | 22 ++++++++-------- spec/deploy_callbacks_spec.rb | 20 +++++++-------- spec/deploy_dsl_spec.rb | 42 +++---------------------------- 4 files changed, 42 insertions(+), 83 deletions(-) diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb index 6513b539..c2dc861b 100644 --- a/lib/centurion/deploy_callbacks.rb +++ b/lib/centurion/deploy_callbacks.rb @@ -3,40 +3,35 @@ module Centurion # be useful to communicate with a loadbalancer, chat room, etc. module DeployCallbacks def stop_containers(server, service, timeout = 30) - callbacks(:before_stopping_image).each do |callback| - callback.call server - end + emit :before_stopping_image, server super server, service, timeout end def start_new_container(server, service, restart_policy) - result = super server, service, restart_policy - callbacks(:after_image_started).each do |callback| - callback.call server - end - result + super(server, service, restart_policy).tap { emit :after_image_started, server } end def wait_for_health_check_ok(health_check_method, server, port, endpoint, image_id, tag, sleep_time=5, retries=12) - result = super health_check_method, - server, - port, - endpoint, - image_id, - tag, - sleep_time, - retries - - callbacks(:after_health_check_ok).each do |callback| - callback.call server - end - result + super(health_check_method, + server, + port, + endpoint, + image_id, + tag, + sleep_time, + retries).tap { emit :after_health_check_ok, server } end private - def callbacks(name) - fetch "#{name}_callbacks".to_sym, [] + def emit(name, *args) + callbacks[name].each do |callback| + callback.call(*args) + end + end + + def callbacks + fetch 'callbacks', Hash.new { [] } end end end diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index e6603628..58d671c4 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -147,27 +147,27 @@ def defined_restart_policy end def before_stopping_image(callback = nil, &block) - collect_callback :before_stopping_image_callbacks, callback, &block + on :before_stopping_image, callback, &block end def after_image_started(callback = nil, &block) - collect_callback :after_image_started_callbacks, callback, &block + on :after_image_started, callback, &block end def after_health_check_ok(callback = nil, &block) - collect_callback :after_health_check_ok_callbacks, callback, &block + on :after_health_check_ok, callback, &block + end + + def on(name, callback = nil, &block) + abort('A callback or block is require') unless callback || block + abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call) + callbacks[name] <<= (callback || block) end private - def collect_callback(name, callback = nil, &block) - callbacks = fetch(name, []) - if callback || block - abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call) - callbacks << (callback || block) - set(name, callbacks) - end - callbacks + def callbacks + fetch('callbacks') || set('callbacks', Hash.new { [] }) end def service_under_construction diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb index 0f8ef2f5..56c4e999 100644 --- a/spec/deploy_callbacks_spec.rb +++ b/spec/deploy_callbacks_spec.rb @@ -2,11 +2,9 @@ require 'centurion' RSpec.describe Centurion::DeployCallbacks do - shared_examples_for 'a callback' do |callback| + shared_examples_for 'a callback' do let(:server) { double :server } let(:service) { double :service } - let(:callbacks) { [double, double] } - let(:callback_name) { "#{callback}_callbacks".to_sym } let(:klass) do Class.new do @@ -18,28 +16,30 @@ def method_missing(method_name, *_args) end let(:object) do - klass.new.tap do |o| - allow(o).to receive(:fetch).with(callback_name, []).and_return callbacks - end + klass.new + end + + before do + allow(object).to receive(:emit) end end shared_examples_for 'a before callback' do |callback, method_name| - include_examples 'a callback', callback + include_examples 'a callback' it 'invokes all the callback before the method' do - callbacks.each { |cb| expect(cb).to receive(:call).with(server).ordered } + expect(object).to receive(:emit).with(callback, server).ordered expect(object).to receive(:doing).with(method_name).ordered subject end end shared_examples_for 'an after callback' do |callback, method_name| - include_examples 'a callback', callback + include_examples 'a callback' it 'invokes all the callback before the method' do expect(object).to receive(:doing).with(method_name).ordered - callbacks.each { |cb| expect(cb).to receive(:call).with(server).ordered } + expect(object).to receive(:emit).with(callback, server).ordered subject end end diff --git a/spec/deploy_dsl_spec.rb b/spec/deploy_dsl_spec.rb index 355030bd..d2dc0006 100644 --- a/spec/deploy_dsl_spec.rb +++ b/spec/deploy_dsl_spec.rb @@ -211,49 +211,13 @@ class DeployDSLTest expect(DeployDSLTest.defined_service.image).to eq('charlemagne:roland') end - describe '#before_stopping_image' do - it 'does not add nil callbacks' do - DeployDSLTest.before_stopping_image - expect(DeployDSLTest.fetch(:before_stopping_image_callbacks, [])).to eq([]) - end - end - describe 'callbacks' do shared_examples_for 'a callback for' do |callback_name| - let(:callbacks) { DeployDSLTest.fetch("#{callback_name}_callbacks".to_sym, []) } - - it 'does not add nil callbacks' do - DeployDSLTest.send callback_name - expect(callbacks).to eq([]) - end - - it 'collects callbacks as procs' do + it 'accepts procs' do callback = ->(_) {} + allow(DeployDSLTest).to receive(:on) + expect(DeployDSLTest).to receive(:on).with(callback_name, callback) DeployDSLTest.send callback_name, callback - expect(callbacks).to eq([callback]) - end - - it 'collects callbacks as blocks' do - DeployDSLTest.send callback_name do |_| - 'from the block' - end - callback = callbacks[0] - expect(callback.call).to eq('from the block') - end - - it 'returns a list of all callbacks when adding one' do - callback1 = ->(_) {} - callback2 = ->(_) {} - DeployDSLTest.send callback_name, callback1 - returned_callbacks = DeployDSLTest.send callback_name, callback2 - expect(returned_callbacks).to eq([callback1, callback2]) - end - - it 'returns a list of all callbacks when adding none' do - callback1 = ->(_) {} - DeployDSLTest.send callback_name, callback1 - returned_callbacks = DeployDSLTest.send callback_name - expect(returned_callbacks).to eq([callback1]) end end From 4789be5cbcef622cdab7d73ed217f633dec07d53 Mon Sep 17 00:00:00 2001 From: Jonathan Owens Date: Mon, 23 Jan 2017 15:33:55 -0800 Subject: [PATCH 18/20] Rename callbacks to _container, add :before_starting_container hook. It's containers, not images, that start and stop. Also, between stopping and starting containers it can be useful to muck with the environment on a per-host basis, so add a before_starting_container hook. --- README.md | 12 +++++--- lib/centurion/deploy_callbacks.rb | 8 ++++-- lib/centurion/deploy_dsl.rb | 14 +++++---- lib/tasks/deploy.rake | 2 ++ spec/deploy_callbacks_spec.rb | 47 +++++++++++++++++++++++-------- spec/deploy_dsl_spec.rb | 12 +++++--- 6 files changed, 69 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 06c6e1e1..eb7d9206 100644 --- a/README.md +++ b/README.md @@ -342,15 +342,19 @@ You can create callbacks to perform custom actions during a deploy. ```ruby task :production => :common do - before_stopping_image do |server| + before_stopping_container do |server, service| my_loadbalancer.disable server.hostname end - after_image_started do |server| - my_chat_server.post "#{server.hostname} started my image....waiting for health check" + before_starting_container do |server, service| + my_chat_server.post "#{server.hostname} starting #{service.image}..." end - after_health_check_ok do |server| + after_starting_container do |server, service| + my_chat_server.post "#{server.hostname} started #{service.image}, waiting for health check..." + end + + after_health_check_ok do |server, service| my_loadbalancer.enable server.hostname end end diff --git a/lib/centurion/deploy_callbacks.rb b/lib/centurion/deploy_callbacks.rb index c2dc861b..b82ed7e3 100644 --- a/lib/centurion/deploy_callbacks.rb +++ b/lib/centurion/deploy_callbacks.rb @@ -3,12 +3,16 @@ module Centurion # be useful to communicate with a loadbalancer, chat room, etc. module DeployCallbacks def stop_containers(server, service, timeout = 30) - emit :before_stopping_image, server + emit :before_stopping_container, server, service super server, service, timeout end + def before_starting_container(server, service) + emit :before_starting_container, server, service + end + def start_new_container(server, service, restart_policy) - super(server, service, restart_policy).tap { emit :after_image_started, server } + super(server, service, restart_policy).tap { emit :after_starting_container, server, service } end def wait_for_health_check_ok(health_check_method, server, port, endpoint, image_id, tag, sleep_time=5, retries=12) diff --git a/lib/centurion/deploy_dsl.rb b/lib/centurion/deploy_dsl.rb index 58d671c4..5dd25890 100644 --- a/lib/centurion/deploy_dsl.rb +++ b/lib/centurion/deploy_dsl.rb @@ -146,12 +146,16 @@ def defined_restart_policy Centurion::Service::RestartPolicy.new(fetch(:restart_policy_name, 'on-failure'), fetch(:restart_policy_max_retry_count, 10)) end - def before_stopping_image(callback = nil, &block) - on :before_stopping_image, callback, &block + def before_stopping_container(callback = nil, &block) + on :before_stopping_container, callback, &block end - def after_image_started(callback = nil, &block) - on :after_image_started, callback, &block + def before_starting_container(callback = nil, &block) + on :before_starting_container, callback, &block + end + + def after_container_started(callback = nil, &block) + on :after_container_started, callback, &block end def after_health_check_ok(callback = nil, &block) @@ -159,7 +163,7 @@ def after_health_check_ok(callback = nil, &block) end def on(name, callback = nil, &block) - abort('A callback or block is require') unless callback || block + abort('A callback or block is required') unless callback || block abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call) callbacks[name] <<= (callback || block) end diff --git a/lib/tasks/deploy.rake b/lib/tasks/deploy.rake index 27fce150..0cd3d2e8 100644 --- a/lib/tasks/deploy.rake +++ b/lib/tasks/deploy.rake @@ -140,6 +140,8 @@ namespace :deploy do stop_containers(server, service, fetch(:stop_timeout, 30)) + DeployCallbacks.before_starting_image(server, service) + container = start_new_container(server, service, defined_restart_policy) public_ports = service.public_ports - fetch(:rolling_deploy_skip_ports, []) diff --git a/spec/deploy_callbacks_spec.rb b/spec/deploy_callbacks_spec.rb index 56c4e999..3febfc0d 100644 --- a/spec/deploy_callbacks_spec.rb +++ b/spec/deploy_callbacks_spec.rb @@ -24,37 +24,62 @@ def method_missing(method_name, *_args) end end - shared_examples_for 'a before callback' do |callback, method_name| + shared_examples_for 'the before_stopping_container callbacks' do |callback, method_name| include_examples 'a callback' - it 'invokes all the callback before the method' do - expect(object).to receive(:emit).with(callback, server).ordered + it 'invokes all the callbacks' do + expect(object).to receive(:emit).with(callback, server, service).ordered + expect(object).to receive(:doing).with(method_name).ordered + subject + end + end + + shared_examples_for 'the before_starting_container callbacks' do |callback| + include_examples 'a callback' + + it 'invokes all the callbacks' do + expect(object).to receive(:emit).with(callback, server, service).ordered + subject + end + end + + shared_examples_for 'the after_starting_container callbacks' do |callback, method_name| + include_examples 'a callback' + + it 'invokes all the callbacks' do expect(object).to receive(:doing).with(method_name).ordered + expect(object).to receive(:emit).with(callback, server, service).ordered subject end end - shared_examples_for 'an after callback' do |callback, method_name| + shared_examples_for 'the after_health_check_ok callbacks' do |callback, method_name| include_examples 'a callback' - it 'invokes all the callback before the method' do + it 'invokes all the callbacks' do expect(object).to receive(:doing).with(method_name).ordered expect(object).to receive(:emit).with(callback, server).ordered subject end end - describe 'before stopping callback' do + describe 'the before_stopping_container callback' do subject { object.stop_containers server, service } - it_behaves_like 'a before callback', - :before_stopping_image, + it_behaves_like 'the before_stopping_container callbacks', + :before_stopping_container, :stop_containers end + describe 'before_starting_container callback' do + subject { object.before_starting_container server, service } + it_behaves_like 'the before_starting_container callbacks', + :before_starting_container + end + describe 'after started callback' do subject { object.start_new_container server, service, double } - it_behaves_like 'an after callback', - :after_image_started, + it_behaves_like 'the after_starting_container callbacks', + :after_starting_container, :start_new_container end @@ -72,7 +97,7 @@ def method_missing(method_name, *_args) ] end subject { object.wait_for_health_check_ok(*args) } - it_behaves_like 'an after callback', + it_behaves_like 'the after_health_check_ok callbacks', :after_health_check_ok, :wait_for_health_check_ok end diff --git a/spec/deploy_dsl_spec.rb b/spec/deploy_dsl_spec.rb index d2dc0006..338492eb 100644 --- a/spec/deploy_dsl_spec.rb +++ b/spec/deploy_dsl_spec.rb @@ -221,12 +221,16 @@ class DeployDSLTest end end - describe '#before_stopping_image' do - it_behaves_like 'a callback for', :before_stopping_image + describe '#before_stopping_container' do + it_behaves_like 'a callback for', :before_stopping_container end - describe '#after_image_started' do - it_behaves_like 'a callback for', :after_image_started + describe '#before_starting_container' do + it_behaves_like 'a callback for', :before_starting_container + end + + describe '#after_container_started' do + it_behaves_like 'a callback for', :after_container_started end describe '#after_health_check_ok' do From b2514a4a70dc48592a61da1daff6069e982b0b5d Mon Sep 17 00:00:00 2001 From: Jonathan Owens Date: Wed, 22 Mar 2017 11:38:01 -0700 Subject: [PATCH 19/20] Fixing merge issue in .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index afd4b2e3..5500f4e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: ruby before_install: - gem update - gem install bundler -======= rvm: - 1.9.3 - 2.0.0 From f34ae8eb67cafb180ff9bc4f14a4dabd1c84df2b Mon Sep 17 00:00:00 2001 From: Jonathan Owens Date: Wed, 22 Mar 2017 12:09:17 -0700 Subject: [PATCH 20/20] Fix outdated reference to before_starting_image --- lib/tasks/deploy.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/deploy.rake b/lib/tasks/deploy.rake index 0cd3d2e8..dde84e18 100644 --- a/lib/tasks/deploy.rake +++ b/lib/tasks/deploy.rake @@ -140,7 +140,7 @@ namespace :deploy do stop_containers(server, service, fetch(:stop_timeout, 30)) - DeployCallbacks.before_starting_image(server, service) + Centurion::DeployCallbacks.before_starting_container(server, service) container = start_new_container(server, service, defined_restart_policy)