bigrig 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile.lock +3 -1
  4. data/bigrig.gemspec +1 -0
  5. data/lib/bigrig/dependency_graph.rb +3 -1
  6. data/lib/bigrig/version.rb +1 -1
  7. data/spec/bigrig/dependency_graph_spec.rb +10 -4
  8. data/spec/bigrig_spec.rb +44 -34
  9. data/spec/data/scan.json +2 -1
  10. data/spec/spec_helper.rb +1 -13
  11. data/spec/support/wait_for.rb +35 -0
  12. data/spec/vcr/Bigrig_DestroyAction/_perform/given_json_with_a_single_container/and_the_container_has_exited/should_remove_the_container.yml +46 -46
  13. data/spec/vcr/Bigrig_DestroyAction/_perform/given_json_with_a_single_container/and_the_container_is_running/kills_and_removes_the_container.yml +49 -49
  14. data/spec/vcr/Bigrig_DockerAdapter/_build/builds_the_given_directory.yml +8 -8
  15. data/spec/vcr/Bigrig_DockerAdapter/_build/passes_build_input_to_a_block.yml +4 -4
  16. data/spec/vcr/Bigrig_DockerAdapter/_container_exists_/when_the_container_does_not_exist/is_false.yml +8 -8
  17. data/spec/vcr/Bigrig_DockerAdapter/_container_exists_/when_the_container_exists/is_true.yml +9 -9
  18. data/spec/vcr/Bigrig_DockerAdapter/_image_id_by_tag/when_the_image_does_not_exist/raise_a_ImageNotFoundError.yml +12 -12
  19. data/spec/vcr/Bigrig_DockerAdapter/_image_id_by_tag/when_the_image_exists/returns_the_image_id.yml +12 -12
  20. data/spec/vcr/Bigrig_DockerAdapter/_kill/given_the_container_does_not_exist/should_raise_an_error.yml +8 -8
  21. data/spec/vcr/Bigrig_DockerAdapter/_kill/given_the_container_is_running/should_kill_the_container.yml +22 -22
  22. data/spec/vcr/Bigrig_DockerAdapter/_logs/streams_logs_to_a_block.yml +17 -17
  23. data/spec/vcr/Bigrig_DockerAdapter/_pull/given_a_block_to_capture_output/should_capture_output.yml +4 -4
  24. data/spec/vcr/Bigrig_DockerAdapter/_pull/given_the_repo_does_not_exist/raises_a_RepoNotFoundError.yml +2 -2
  25. data/spec/vcr/Bigrig_DockerAdapter/_pull/given_the_repo_exists/returns_the_image_id.yml +6 -6
  26. data/spec/vcr/Bigrig_DockerAdapter/_push/given_credentials/will_pass_login_and_password.yml +36 -36
  27. data/spec/vcr/Bigrig_DockerAdapter/_push/should_push_the_image.yml +453 -77
  28. data/spec/vcr/Bigrig_DockerAdapter/_remove_container/when_the_container_does_not_exist/raises_a_ContainerNotFoundError.yml +16 -16
  29. data/spec/vcr/Bigrig_DockerAdapter/_remove_container/when_the_container_exists/should_remove_the_container.yml +32 -32
  30. data/spec/vcr/Bigrig_DockerAdapter/_remove_container/when_the_container_is_running/raises_a_ContainerRunningError.yml +10 -10
  31. data/spec/vcr/Bigrig_DockerAdapter/_remove_image/when_the_image_doesnt_exist/raises_an_error.yml +8 -8
  32. data/spec/vcr/Bigrig_DockerAdapter/_remove_image/when_the_image_exists/removes_the_image.yml +28 -28
  33. data/spec/vcr/Bigrig_DockerAdapter/_run/given_an_image_id_that_exists/and_a_name/starts_the_container_with_the_right_name.yml +27 -27
  34. data/spec/vcr/Bigrig_DockerAdapter/_run/given_an_image_id_that_exists/and_a_name_and_env_variables/starts_the_container_with_env_set.yml +27 -27
  35. data/spec/vcr/Bigrig_DockerAdapter/_run/given_an_image_id_that_exists/and_a_name_and_ports/starts_the_container_with_ports_exposed.yml +32 -32
  36. data/spec/vcr/Bigrig_DockerAdapter/_running_/when_the_container_does_not_exist/returns_false.yml +8 -8
  37. data/spec/vcr/Bigrig_DockerAdapter/_running_/when_the_container_is_not_running/returns_false.yml +11 -11
  38. data/spec/vcr/Bigrig_DockerAdapter/_running_/when_the_container_is_running/returns_true.yml +13 -13
  39. data/spec/vcr/Bigrig_DockerAdapter/_tag/should_tag_the_image.yml +16 -16
  40. data/spec/vcr/Bigrig_LogAction/_perform/follows_the_log.yml +25 -25
  41. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_a_path/builds_the_image_before_starting_it.yml +20 -20
  42. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_hosts_by_ip/should_pass_hosts_to_container.yml +40 -40
  43. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_hosts_by_name/should_lookup_ips_for_hosts_with_a_hostname.yml +41 -41
  44. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_links/should_pass_links_to_the_right_container.yml +73 -73
  45. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_multiple_containers/launches_both_containers_in_parallel.yml +52 -52
  46. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_multiple_containers/spins_up_multiple_containers.yml +74 -74
  47. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_one_container/should_spin_up_a_single_container.yml +36 -36
  48. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_one_container/when_a_dead_container_exists/should_remove_existing_containers.yml +38 -38
  49. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_volumes/should_pass_volumes_to_the_right_container.yml +40 -40
  50. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_volumes_from/should_pass_volumes_from_to_the_right_container.yml +73 -73
  51. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_volumes_from/starts_the_dependant_container_last.yml +52 -52
  52. data/spec/vcr/Bigrig_RunAction/_perform/when_activating_profiles_that_do_not_exist/ignores_the_missing_profile.yml +35 -35
  53. data/spec/vcr/Bigrig_RunAction/_perform/with_a_file_with_active_profiles/uses_the_overridden_image.yml +38 -38
  54. data/spec/vcr/bigrig/destroy/spec/data/single_json/kills_the_container.yml +14 -14
  55. data/spec/vcr/bigrig/dev/spec/data/dev_json/activates_the_dev_profile.yml +427 -37
  56. data/spec/vcr/bigrig/dev/spec/data/dev_json/destroys_containers_on_exit.yml +32 -32
  57. data/spec/vcr/bigrig/dev/spec/data/dev_json/starts_the_containers.yml +472 -76
  58. data/spec/vcr/bigrig/dev/spec/data/dev_json/tails_the_logs.yml +16 -16
  59. data/spec/vcr/bigrig/dev/spec/data/scan_json/leaves_unaffected_containers_alone_when_the_scanned_file_changes.yml +1544 -86
  60. data/spec/vcr/bigrig/dev/spec/data/scan_json/restarts_dependant_containers_when_the_scanned_file_changes.yml +1725 -69
  61. data/spec/vcr/bigrig/dev/spec/data/scan_json/restarts_the_container_when_the_scanned_file_changes.yml +1536 -96
  62. data/spec/vcr/bigrig/logs/spec/data/log_json/tails_the_logs.yml +17 -17
  63. data/spec/vcr/bigrig/run/spec/data/profiles_json_-p_qa/leaves_existing_env_values_alone.yml +11 -11
  64. data/spec/vcr/bigrig/run/spec/data/profiles_json_-p_qa/overrides_the_env.yml +11 -11
  65. data/spec/vcr/bigrig/run/spec/data/profiles_json_-p_qa/overrides_the_tag.yml +11 -11
  66. data/spec/vcr/bigrig/run/spec/data/single_json/sends_the_name_of_the_container_to_stdout.yml +9 -9
  67. data/spec/vcr/bigrig/run/spec/data/single_json/starts_the_container.yml +13 -13
  68. data/spec/vcr/bigrig/ship/spec/data/ship_json/with_a_version/-c/cleans_the_image_when_its_done.yml +20 -20
  69. data/spec/vcr/bigrig/ship/spec/data/ship_json/with_a_version/builds_and_pushes_the_image.yml +15 -15
  70. data/spec/vcr/bigrig_bin_bigrig_destroy_spec/data/single_json_kills_the_container.yml +21 -21
  71. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_activates_the_dev_profile.yml +105 -305
  72. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_starts_the_containers.yml +109 -307
  73. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_tails_the_logs.yml +116 -116
  74. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/scan_json_leaves_unaffected_containers_alone_when_the_scanned_file_changes.yml +385 -382
  75. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/scan_json_restarts_dependant_containers_when_the_scanned_file_changes.yml +357 -354
  76. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/scan_json_restarts_the_container_when_the_scanned_file_changes.yml +358 -1091
  77. data/spec/vcr/bigrig_bin_bigrig_logs_spec/data/log_json_tails_the_logs.yml +21 -21
  78. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/profiles_json_-p_qa_leaves_existing_env_values_alone.yml +24 -24
  79. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/profiles_json_-p_qa_overrides_the_env.yml +24 -24
  80. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/profiles_json_-p_qa_overrides_the_tag.yml +17 -17
  81. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/single_json_sends_the_name_of_the_container_to_stdout.yml +24 -24
  82. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/single_json_starts_the_container.yml +24 -24
  83. data/spec/vcr/bigrig_bin_bigrig_ship_spec/data/ship_json_with_a_version_-c_cleans_the_image_when_its_done.yml +439 -63
  84. data/spec/vcr/bigrig_bin_bigrig_ship_spec/data/ship_json_with_a_version_builds_and_pushes_the_image.yml +430 -54
  85. data/spec/waitfor_spec.rb +10 -0
  86. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b45105f59905374c0229e4ae83c1bdd37614242f
4
- data.tar.gz: 152ce1cc2b69fcbb0965086d17d6cba1cdd5d661
3
+ metadata.gz: d20693edd19fd3772463838bf41ac7a525541e83
4
+ data.tar.gz: 86f2dacffa8ff0ad6cba5170f6b7f5e73605dfdc
5
5
  SHA512:
6
- metadata.gz: d373c76d6031b6c61ce612b32131c40b572d89a7f3dc4ea64be110a288af7091a57c9d64af9672fb1bd84a326cfc93b16e5c3e53a2c243d20aaf70b669e2024e
7
- data.tar.gz: e480b7fdfff35ddad6edab2bce175e27ec59ed4176edc632c0689c6fd5b01c76ce80ddaad2fcbc55c34335524dfdc9470694d1c4b2b05a0e45692711e8869a69
6
+ metadata.gz: 65cfa236bf4374f8b9522aa852246a701125378f6653ad1692e508facc3f8485314ba00d5ceea63125c2714f3a3177ae2f5be85b4bc08743a15990bd150d79e9
7
+ data.tar.gz: e7b721bd63a21e55d62bc6fe9c2df8cc1e7ffad0617cc891db53cfc0edd754e871a75bfeb840557656ce69577d1bdfb17e67cb02bf2e0098ff8cf2ee55455747
data/CHANGELOG.md CHANGED
@@ -39,3 +39,7 @@ Add `volumes` attriute
39
39
  0.2.0
40
40
  =====
41
41
  * Added `scan` functionality
42
+
43
+ 0.2.2
44
+ =====
45
+ * scanned containers no longer restart their dependencies
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bigrig (0.2.1)
4
+ bigrig (0.2.2)
5
5
  colorize (= 0.7.5)
6
6
  docker-api (= 1.20.0)
7
7
  filewatcher (= 0.4.0)
@@ -49,6 +49,7 @@ GEM
49
49
  rspec-mocks (~> 3.1.0)
50
50
  rspec-core (3.1.7)
51
51
  rspec-support (~> 3.1.0)
52
+ rspec-eventually (0.0.1)
52
53
  rspec-expectations (3.1.2)
53
54
  diff-lcs (>= 1.2.0, < 2.0)
54
55
  rspec-support (~> 3.1.0)
@@ -82,6 +83,7 @@ DEPENDENCIES
82
83
  pry
83
84
  rake
84
85
  rspec
86
+ rspec-eventually
85
87
  rspec-its
86
88
  rubocop
87
89
  vcr (~> 2.9.3)
data/bigrig.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency('vcr', '~> 2.9.3')
23
23
  s.add_development_dependency('webmock', '~> 1.20.4')
24
24
  s.add_development_dependency('popen4')
25
+ s.add_development_dependency('rspec-eventually')
25
26
 
26
27
  s.add_runtime_dependency('gli', '2.12.2')
27
28
  s.add_runtime_dependency('colorize', '0.7.5')
@@ -10,7 +10,8 @@ module Bigrig
10
10
  end
11
11
 
12
12
  def resolve_subtree(container)
13
- startup_order @containers.select { |c| resolve_deps(c, []).include? container.name }
13
+ subtree = @containers.select { |c| resolve_deps(c, []).include? container.name }
14
+ startup_order(subtree) & subtree
14
15
  end
15
16
 
16
17
  private
@@ -26,6 +27,7 @@ module Bigrig
26
27
  end
27
28
 
28
29
  def resolve_deps(container, resolved)
30
+ container || return
29
31
  container.dependencies.each do |dep_name|
30
32
  resolve_deps @map[dep_name], resolved unless resolved.include? dep_name
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module Bigrig
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -20,19 +20,25 @@ module Bigrig
20
20
  subject { described_class.new(containers).resolve_subtree target }
21
21
  context 'given three containers, two of which have a relationship' do
22
22
  let(:target) do
23
- Container.new(name: 'target')
23
+ containers[2]
24
24
  end
25
25
 
26
+ let(:subtree) { subject }
27
+
26
28
  let(:containers) do
27
29
  [
28
- target,
29
30
  Container.new(name: 'test1', volumes_from: ['target']),
30
- Container.new(name: 'test2')
31
+ Container.new(name: 'test2'),
32
+ Container.new(name: 'target', volumes_from: ['test2'])
31
33
  ]
32
34
  end
33
35
 
34
36
  it 'resolves only related containers' do
35
- expect(subject.map(&:name)).to eq %w(target test1)
37
+ expect(subtree.map(&:name)).to match_array %w(target test1)
38
+ end
39
+
40
+ it 'orders containers in restart order' do
41
+ expect(subtree.map(&:name)).to eq %w(target test1)
36
42
  end
37
43
  end
38
44
  end
data/spec/bigrig_spec.rb CHANGED
@@ -18,18 +18,26 @@ describe 'bigrig' do
18
18
  before do
19
19
  FileUtils.mkdir_p '/tmp/scan'
20
20
  FileUtils.touch '/tmp/scan/scan.me'
21
+
22
+ %w(scanning uses_scanning some_ahole).each do |name|
23
+ begin
24
+ Docker::Container.get(name).kill.delete
25
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
26
+ end
27
+ end
21
28
  end
22
29
 
23
30
  it 'restarts the container when the scanned file changes', :vcr do
24
31
  pid, _stdin, stdout, _stderr = Open4.popen4(command)
25
32
  drain_io stdout
26
33
 
27
- wait_for %w(scanning uses_scanning some_ahole)
28
- before_image = Docker::Container.get 'scanning'
34
+ scanning = wait_for_containers(%w(scanning uses_scanning some_ahole)).first
35
+
29
36
  FileUtils.touch '/tmp/scan/scan.me'
30
- sleep 3
31
- wait_for 'scanning'
32
- expect(before_image.id).to_not eq Docker::Container.get('scanning').id
37
+ expect { Docker::Container.get('scanning').id }.to eventually_not(eq scanning.id).
38
+ by_suppressing_errors
39
+ wait_for { Docker::Container.get('uses_scanning').info['State']['Running'] }.to eq true
40
+
33
41
  Process.kill :SIGINT, pid
34
42
  Process.wait pid
35
43
  end
@@ -37,13 +45,14 @@ describe 'bigrig' do
37
45
  it 'restarts dependant containers when the scanned file changes', :vcr do
38
46
  pid, _stdin, stdout, _stderr = Open4.popen4(command)
39
47
  drain_io stdout
40
- wait_for %w(scanning uses_scanning some_ahole)
41
- before_image = Docker::Container.get 'uses_scanning'
48
+
49
+ before_image = wait_for_containers(%w(uses_scanning scanning some_ahole)).first
42
50
 
43
51
  FileUtils.touch '/tmp/scan/scan.me'
44
- sleep 3
45
- wait_for 'uses_scanning'
46
- expect(before_image.id).to_not eq Docker::Container.get('uses_scanning').id
52
+ expect { Docker::Container.get('uses_scanning').id }.to eventually_not(eq before_image.id).
53
+ by_suppressing_errors
54
+ wait_for { Docker::Container.get('uses_scanning').info['State']['Running'] }.to eq true
55
+
47
56
  Process.kill :SIGINT, pid
48
57
  Process.wait pid
49
58
  end
@@ -51,13 +60,14 @@ describe 'bigrig' do
51
60
  it 'leaves unaffected containers alone when the scanned file changes', :vcr do
52
61
  pid, _stdin, stdout, _stderr = Open4.popen4(command)
53
62
  drain_io stdout
54
- wait_for %w(scanning uses_scanning some_ahole)
55
- before_image = Docker::Container.get 'some_ahole'
63
+ containers = wait_for_containers(%w(some_ahole uses_scanning scanning ))
56
64
 
57
65
  FileUtils.touch '/tmp/scan/scan.me'
58
- sleep 3
59
- wait_for %w(scanning uses_scanning)
60
- expect(before_image.id).to eq Docker::Container.get('some_ahole').id
66
+
67
+ wait_for { Docker::Container.get('uses_scanning').id }.to_not eq containers[1].id
68
+ wait_for { Docker::Container.get('scanning').id }.to_not eq containers[2].id
69
+
70
+ expect(Docker::Container.get('some_ahole').id).to eq containers.first.id
61
71
  Process.kill :SIGINT, pid
62
72
  Process.wait pid
63
73
  end
@@ -67,9 +77,11 @@ describe 'bigrig' do
67
77
  let(:args) { ['-f', 'spec/data/dev.json', 'dev'] }
68
78
  let(:command) { %(spec/support/bigrig_vcr "#{casette_name}" #{args.join ' '}) }
69
79
  let(:env) do
70
- url = URI.parse Docker.connection.url
71
- text = Net::HTTP.get URI.parse("http://#{url.host}:4568")
72
- text.split("\n").each_with_object({}) { |e, o| o.store(*e.split('=')) }
80
+ lambda do
81
+ url = URI.parse Docker.connection.url
82
+ text = Net::HTTP.get URI.parse("http://#{url.host}:4568")
83
+ text.split("\n").each_with_object({}) { |e, o| o.store(*e.split('=')) }
84
+ end
73
85
  end
74
86
 
75
87
  before do
@@ -83,13 +95,12 @@ describe 'bigrig' do
83
95
 
84
96
  it 'starts the containers', :vcr do
85
97
  pid = Open4.popen4(command).first
86
- wait_for %w(dev-test dev-logs)
87
- sleep 2
88
- dev_test = Docker::Container.get('dev-test')
89
- dev_logs = Docker::Container.get('dev-logs')
90
98
  begin
91
- expect(dev_test.json['State']['Running']).to be true
92
- expect(dev_logs.json['State']['Running']).to be true
99
+ expect { Docker::Container.get('dev-test').json['State']['Running'] }.
100
+ to eventually(be true).by_suppressing_errors
101
+
102
+ expect { Docker::Container.get('dev-logs').json['State']['Running'] }.
103
+ to eventually(be true).by_suppressing_errors
93
104
  ensure
94
105
  Process.kill :SIGINT, pid
95
106
  Process.wait pid
@@ -114,10 +125,9 @@ describe 'bigrig' do
114
125
 
115
126
  it 'activates the dev profile', :vcr do
116
127
  pid = Open4.popen4(command).first
117
- wait_for 'dev-test'
118
- sleep 2
119
128
  begin
120
- expect(env).to include 'PROFILE' => 'dev'
129
+ wait_for { Docker::Container.get('dev-test').info['State']['Running'] }.to eq true
130
+ expect { env.call }.to eventually(include 'PROFILE' => 'dev').by_suppressing_errors
121
131
  ensure
122
132
  Process.kill :SIGINT, pid
123
133
  Process.wait pid
@@ -183,9 +193,11 @@ describe 'bigrig' do
183
193
  let(:image) { Docker::Image.get 'hawknewton/show-env' }
184
194
  let(:file) { 'spec/data/profiles.json' }
185
195
  let(:env) do
186
- url = URI.parse Docker.connection.url
187
- text = Net::HTTP.get URI.parse("http://#{url.host}:4567")
188
- text.split("\n").each_with_object({}) { |e, o| o.store(*e.split('=')) }
196
+ lambda do
197
+ url = URI.parse Docker.connection.url
198
+ text = Net::HTTP.get URI.parse("http://#{url.host}:4567")
199
+ text.split("\n").each_with_object({}) { |e, o| o.store(*e.split('=')) }
200
+ end
189
201
  end
190
202
 
191
203
  after { container.kill.delete }
@@ -197,14 +209,12 @@ describe 'bigrig' do
197
209
 
198
210
  it 'overrides the env', :vcr do
199
211
  subject
200
- sleep 1
201
- expect(env).to include 'NAME1' => 'VALUE1A'
212
+ expect { env.call }.to eventually(include 'NAME1' => 'VALUE1A').by_suppressing_errors
202
213
  end
203
214
 
204
215
  it 'leaves existing env values alone', :vcr do
205
216
  subject
206
- sleep 1
207
- expect(env).to include 'NAME2' => 'VALUE2'
217
+ expect { env.call }.to eventually(include 'NAME2' => 'VALUE2').by_suppressing_errors
208
218
  end
209
219
  end
210
220
  end
data/spec/data/scan.json CHANGED
@@ -3,7 +3,8 @@
3
3
  "scanning": {
4
4
  "repo": "hawknewton/log-test",
5
5
  "tag": "0.0.1",
6
- "scan": "/tmp/scan/**"
6
+ "scan": "/tmp/scan/**",
7
+ "links": "some_ahole:some_ahole"
7
8
  },
8
9
  "uses_scanning": {
9
10
  "repo": "hawknewton/log-test",
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bigrig'
2
2
  require 'rspec/its'
3
+ require 'rspec/eventually'
3
4
 
4
5
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
5
6
 
@@ -114,16 +115,3 @@ def read_stdout(stdout)
114
115
  end
115
116
  output
116
117
  end
117
-
118
- def wait_for(containers)
119
- [containers].flatten.each do |container|
120
- Timeout.timeout(5) do
121
- begin
122
- Docker::Container.get container
123
- rescue Docker::Error::NotFoundError
124
- sleep 0.5
125
- retry
126
- end
127
- end
128
- end
129
- end
@@ -0,0 +1,35 @@
1
+ require 'rspec/eventually'
2
+
3
+ class WaitFor
4
+ def initialize(&block)
5
+ @block = block
6
+ end
7
+
8
+ [:to, :to_not].each do |method|
9
+ define_method method do |matcher|
10
+ waiter = eventually(matcher)
11
+ method == :to_not && waiter.not
12
+ waiter.matches?(@block) || fail('wait_for never came true')
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def eventually(matcher)
19
+ Rspec::Eventually::Eventually.new(matcher).by_suppressing_errors
20
+ end
21
+ end
22
+
23
+ def wait_for(&block)
24
+ WaitFor.new(&block)
25
+ end
26
+
27
+ def wait_for_container(name)
28
+ c = nil
29
+ wait_for { (c = Docker::Container.get(name)).info['State']['Running'] }.to eq true
30
+ c
31
+ end
32
+
33
+ def wait_for_containers(containers)
34
+ containers.map { |n| wait_for_container n }
35
+ end