bigrig 0.0.0 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +20 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.md +19 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +84 -0
  9. data/LICENSE +28 -0
  10. data/README.md +191 -0
  11. data/Rakefile +10 -0
  12. data/bigrig.gemspec +29 -0
  13. data/bin/bigrig +113 -0
  14. data/lib/bigrig/actions/destroy_action.rb +21 -0
  15. data/lib/bigrig/actions/dev_action.rb +19 -0
  16. data/lib/bigrig/actions/log_action.rb +45 -0
  17. data/lib/bigrig/actions/run_action.rb +14 -0
  18. data/lib/bigrig/actions/ship_action.rb +51 -0
  19. data/lib/bigrig/actions.rb +5 -0
  20. data/lib/bigrig/dependency_graph.rb +21 -0
  21. data/lib/bigrig/descriptor.rb +43 -0
  22. data/lib/bigrig/docker_adapter.rb +129 -0
  23. data/lib/bigrig/models/application.rb +22 -0
  24. data/lib/bigrig/models/base_model.rb +7 -0
  25. data/lib/bigrig/models/container.rb +40 -0
  26. data/lib/bigrig/models.rb +3 -0
  27. data/lib/bigrig/output_parser.rb +52 -0
  28. data/lib/bigrig/runner.rb +94 -0
  29. data/lib/bigrig/version.rb +3 -0
  30. data/lib/bigrig.rb +8 -0
  31. data/spec/bigrig/actions/destroy_action_spec.rb +55 -0
  32. data/spec/bigrig/actions/dev_action_spec.rb +17 -0
  33. data/spec/bigrig/actions/log_action_spec.rb +33 -0
  34. data/spec/bigrig/actions/run_action_spec.rb +270 -0
  35. data/spec/bigrig/actions/ship_action_spec.rb +82 -0
  36. data/spec/bigrig/dependency_graph_spec.rb +19 -0
  37. data/spec/bigrig/descriptor_spec.rb +56 -0
  38. data/spec/bigrig/docker_adapter_spec.rb +409 -0
  39. data/spec/bigrig/models/application_spec.rb +32 -0
  40. data/spec/bigrig/models/container_spec.rb +115 -0
  41. data/spec/bigrig/output_parser_spec.rb +71 -0
  42. data/spec/bigrig_spec.rb +249 -0
  43. data/spec/data/addscontainer.json +24 -0
  44. data/spec/data/build/Dockerfile +2 -0
  45. data/spec/data/build/test +0 -0
  46. data/spec/data/dev.json +26 -0
  47. data/spec/data/duplicate.json +13 -0
  48. data/spec/data/env.json +12 -0
  49. data/spec/data/hosts_ip.json +12 -0
  50. data/spec/data/hosts_name.json +11 -0
  51. data/spec/data/links.json +13 -0
  52. data/spec/data/log.json +8 -0
  53. data/spec/data/multiple.json +13 -0
  54. data/spec/data/path.json +5 -0
  55. data/spec/data/ports.json +9 -0
  56. data/spec/data/profiles.json +24 -0
  57. data/spec/data/ship.json +5 -0
  58. data/spec/data/single.json +8 -0
  59. data/spec/data/tagandpath.json +24 -0
  60. data/spec/data/tiny-image.tar +0 -0
  61. data/spec/data/volumes.json +13 -0
  62. data/spec/spec_helper.rb +104 -0
  63. data/spec/support/bigrig_vcr +8 -0
  64. data/spec/support/vcr.rb +15 -0
  65. data/spec/vcr/Bigrig_DestroyAction/_perform/given_json_with_a_single_container/and_the_container_has_exited/should_remove_the_container.yml +392 -0
  66. data/spec/vcr/Bigrig_DestroyAction/_perform/given_json_with_a_single_container/and_the_container_is_running/kills_and_removes_the_container.yml +418 -0
  67. data/spec/vcr/Bigrig_DockerAdapter/_build/builds_the_given_directory.yml +63 -0
  68. data/spec/vcr/Bigrig_DockerAdapter/_build/passes_build_input_to_a_block.yml +35 -0
  69. data/spec/vcr/Bigrig_DockerAdapter/_container_exists_/when_the_container_does_not_exist/is_false.yml +115 -0
  70. data/spec/vcr/Bigrig_DockerAdapter/_container_exists_/when_the_container_exists/is_true.yml +82 -0
  71. data/spec/vcr/Bigrig_DockerAdapter/_image_id_by_tag/when_the_image_does_not_exist/raise_a_ImageNotFoundError.yml +172 -0
  72. data/spec/vcr/Bigrig_DockerAdapter/_image_id_by_tag/when_the_image_exists/returns_the_image_id.yml +148 -0
  73. data/spec/vcr/Bigrig_DockerAdapter/_kill/given_the_container_does_not_exist/should_raise_an_error.yml +115 -0
  74. data/spec/vcr/Bigrig_DockerAdapter/_kill/given_the_container_is_running/should_kill_the_container.yml +200 -0
  75. data/spec/vcr/Bigrig_DockerAdapter/_logs/streams_logs_to_a_block.yml +163 -0
  76. data/spec/vcr/Bigrig_DockerAdapter/_pull/given_a_block_to_capture_output/should_capture_output.yml +64 -0
  77. data/spec/vcr/Bigrig_DockerAdapter/_pull/given_the_repo_does_not_exist/raises_a_RepoNotFoundError.yml +30 -0
  78. data/spec/vcr/Bigrig_DockerAdapter/_pull/given_the_repo_exists/returns_the_image_id.yml +92 -0
  79. data/spec/vcr/Bigrig_DockerAdapter/_push/given_credentials/will_pass_login_and_password.yml +254 -0
  80. data/spec/vcr/Bigrig_DockerAdapter/_push/should_push_the_image.yml +482 -0
  81. data/spec/vcr/Bigrig_DockerAdapter/_remove_container/when_the_container_does_not_exist/raises_a_ContainerNotFoundError.yml +227 -0
  82. data/spec/vcr/Bigrig_DockerAdapter/_remove_container/when_the_container_exists/should_remove_the_container.yml +222 -0
  83. data/spec/vcr/Bigrig_DockerAdapter/_remove_container/when_the_container_is_running/raises_a_ContainerRunningError.yml +80 -0
  84. data/spec/vcr/Bigrig_DockerAdapter/_remove_image/when_the_image_doesnt_exist/raises_an_error.yml +115 -0
  85. data/spec/vcr/Bigrig_DockerAdapter/_remove_image/when_the_image_exists/removes_the_image.yml +199 -0
  86. data/spec/vcr/Bigrig_DockerAdapter/_run/given_an_image_id_that_exists/and_a_name/starts_the_container_with_the_right_name.yml +204 -0
  87. 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 +204 -0
  88. data/spec/vcr/Bigrig_DockerAdapter/_run/given_an_image_id_that_exists/and_a_name_and_ports/starts_the_container_with_ports_exposed.yml +230 -0
  89. data/spec/vcr/Bigrig_DockerAdapter/_running_/when_the_container_does_not_exist/returns_false.yml +115 -0
  90. data/spec/vcr/Bigrig_DockerAdapter/_running_/when_the_container_is_not_running/returns_false.yml +82 -0
  91. data/spec/vcr/Bigrig_DockerAdapter/_running_/when_the_container_is_running/returns_true.yml +103 -0
  92. data/spec/vcr/Bigrig_DockerAdapter/_tag/should_tag_the_image.yml +290 -0
  93. data/spec/vcr/Bigrig_LogAction/_perform/follows_the_log.yml +163 -0
  94. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_a_path/builds_the_image_before_starting_it.yml +310 -0
  95. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_hosts_by_ip/should_pass_hosts_to_container.yml +430 -0
  96. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_hosts_by_name/should_lookup_ips_for_hosts_with_a_hostname.yml +430 -0
  97. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_links/should_pass_links_to_the_right_container.yml +805 -0
  98. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_multiple_containers/launches_both_containers_in_parallel.yml +731 -0
  99. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_multiple_containers/spins_up_multiple_containers.yml +805 -0
  100. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_one_container/should_spin_up_a_single_container.yml +404 -0
  101. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_one_container/when_a_dead_container_exists/should_remove_existing_containers.yml +329 -0
  102. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_volumes_from/should_pass_volumes_from_to_the_right_container.yml +805 -0
  103. data/spec/vcr/Bigrig_RunAction/_perform/given_a_file_with_volumes_from/starts_the_dependant_container_last.yml +731 -0
  104. data/spec/vcr/Bigrig_RunAction/_perform/when_activating_profiles_that_do_not_exist/ignores_the_missing_profile.yml +409 -0
  105. data/spec/vcr/Bigrig_RunAction/_perform/with_a_file_with_active_profiles/uses_the_overridden_image.yml +432 -0
  106. data/spec/vcr/bigrig/destroy/spec/data/single_json/kills_the_container.yml +166 -0
  107. data/spec/vcr/bigrig/dev/spec/data/dev_json/activates_the_dev_profile.yml +37 -0
  108. data/spec/vcr/bigrig/dev/spec/data/dev_json/destroys_containers_on_exit.yml +227 -0
  109. data/spec/vcr/bigrig/dev/spec/data/dev_json/starts_the_containers.yml +107 -0
  110. data/spec/vcr/bigrig/logs/spec/data/log_json/tails_the_logs.yml +163 -0
  111. data/spec/vcr/bigrig/run/spec/data/profiles_json_-p_qa/leaves_existing_env_values_alone.yml +110 -0
  112. data/spec/vcr/bigrig/run/spec/data/profiles_json_-p_qa/overrides_the_env.yml +110 -0
  113. data/spec/vcr/bigrig/run/spec/data/profiles_json_-p_qa/overrides_the_tag.yml +103 -0
  114. data/spec/vcr/bigrig/run/spec/data/single_json/sends_the_name_of_the_container_to_stdout.yml +75 -0
  115. data/spec/vcr/bigrig/run/spec/data/single_json/starts_the_container.yml +101 -0
  116. data/spec/vcr/bigrig/ship/spec/data/ship_json/with_a_version/-c/cleans_the_image_when_its_done.yml +212 -0
  117. data/spec/vcr/bigrig/ship/spec/data/ship_json/with_a_version/builds_and_pushes_the_image.yml +128 -0
  118. data/spec/vcr/bigrig_bin_bigrig_destroy_spec/data/single_json_kills_the_container.yml +179 -0
  119. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_activates_the_dev_profile.yml +1068 -0
  120. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_destroys_containers_on_exit.yml +1070 -0
  121. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_starts_the_containers.yml +1068 -0
  122. data/spec/vcr/bigrig_bin_bigrig_dev_spec/data/dev_json_tails_the_logs.yml +1075 -0
  123. data/spec/vcr/bigrig_bin_bigrig_logs_spec/data/log_json_tails_the_logs.yml +69 -0
  124. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/profiles_json_-p_qa_leaves_existing_env_values_alone.yml +306 -0
  125. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/profiles_json_-p_qa_overrides_the_env.yml +306 -0
  126. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/profiles_json_-p_qa_overrides_the_tag.yml +306 -0
  127. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/single_json_sends_the_name_of_the_container_to_stdout.yml +306 -0
  128. data/spec/vcr/bigrig_bin_bigrig_run_spec/data/single_json_starts_the_container.yml +306 -0
  129. data/spec/vcr/bigrig_bin_bigrig_ship_spec/data/ship_json_with_a_version_-c_cleans_the_image_when_its_done.yml +335 -0
  130. data/spec/vcr/bigrig_bin_bigrig_ship_spec/data/ship_json_with_a_version_builds_and_pushes_the_image.yml +285 -0
  131. data/test/dev/shipper.json +24 -0
  132. data/test/logs/bigrig.json +6 -0
  133. data/test/logs/container1/Dockerfile +4 -0
  134. data/test/logs/container1/run.sh +7 -0
  135. data/test/logs/container2/Dockerfile +4 -0
  136. data/test/logs/container2/run.sh +7 -0
  137. data/test/ship/bigrig-1.2.3.json +1 -0
  138. data/test/ship/bigrig.json +5 -0
  139. data/test/ship/registry.json +11 -0
  140. data/test/ship/ship/Dockerfile +4 -0
  141. data/test/ship/ship/run.sh +6 -0
  142. data/test/volumes_from/exports_volumes/Dockerfile +8 -0
  143. data/test/volumes_from/exports_volumes/index.html +8 -0
  144. data/test/volumes_from/exports_volumes/run.sh +7 -0
  145. data/test/volumes_from/shipper.json +14 -0
  146. metadata +278 -8
@@ -0,0 +1,270 @@
1
+ module Bigrig
2
+ describe RunAction do
3
+ describe '::perform' do
4
+ subject { described_class.new(descriptor.as_json).perform }
5
+ let(:descriptor) { Descriptor.read test_file(file), active_profiles }
6
+ let(:active_profiles) { [] }
7
+
8
+ context 'given a file with one container' do
9
+ let(:file) { 'single.json' }
10
+ let(:running?) { DockerAdapter.running? 'single-test' }
11
+
12
+ after do
13
+ begin
14
+ container = Docker::Container.get 'single-test'
15
+ container.kill.delete
16
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
17
+ end
18
+ end
19
+
20
+ it 'should spin up a single container', :vcr do
21
+ subject
22
+ expect(running?).to be true
23
+ end
24
+
25
+ context 'when a dead container exists' do
26
+ before do
27
+ container = Docker::Container.create 'Image' => 'hawknewton/show-env',
28
+ 'name' => 'single-test'
29
+ container.start.kill
30
+ end
31
+
32
+ it 'should remove existing containers', :vcr do
33
+ subject
34
+ expect(running?).to be true
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'given a file with multiple containers' do
40
+ let(:file) { 'multiple.json' }
41
+ let(:running?) do
42
+ DockerAdapter.running?('multiple-test1') && DockerAdapter.running?('multiple-test2')
43
+ end
44
+ let(:perform) { subject }
45
+
46
+ after do
47
+ begin
48
+ c1 = Docker::Container.get 'multiple-test1'
49
+ c1.kill.delete
50
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
51
+ end
52
+ begin
53
+ c1 = Docker::Container.get 'multiple-test2'
54
+ c1.kill.delete
55
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
56
+ end
57
+ end
58
+
59
+ it 'spins up multiple containers', :vcr do
60
+ perform
61
+ expect(running?).to be true
62
+ end
63
+
64
+ it 'launches both containers in parallel', :vcr do
65
+ running = 0
66
+ expect(DockerAdapter).to receive(:run).with hash_including(name: 'multiple-test1') do
67
+ running += 1
68
+ sleep 1
69
+ running -= 1
70
+ end
71
+
72
+ expect(DockerAdapter).to receive(:run).with hash_including(name: 'multiple-test2') do
73
+ sleep 0.5
74
+ expect(running).to eq 1
75
+ end
76
+ perform
77
+ end
78
+ end
79
+
80
+ context 'given a file with links' do
81
+ let(:file) { 'links.json' }
82
+ let(:container) { Docker::Container.get 'uses_service' }
83
+ let(:links) { container.json['HostConfig']['Links'] }
84
+ let(:perform) { subject }
85
+
86
+ after do
87
+ begin
88
+ c1 = Docker::Container.get 'provides_service'
89
+ c1.kill.delete
90
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
91
+ end
92
+ begin
93
+ c1 = Docker::Container.get 'uses_service'
94
+ c1.kill.delete
95
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
96
+ end
97
+ end
98
+
99
+ it 'should pass links to the right container', :vcr do
100
+ perform
101
+ expect(links).to eq ['/provides_service:/uses_service/service']
102
+ end
103
+ end
104
+
105
+ context 'given a file with hosts by ip' do
106
+ let(:file) { 'hosts_ip.json' }
107
+ let(:container) { Docker::Container.get 'uses_host' }
108
+ let(:hosts) { container.json['HostConfig']['ExtraHosts'] }
109
+ let(:perform) { subject }
110
+
111
+ after do
112
+ begin
113
+ c1 = Docker::Container.get 'uses_host'
114
+ c1.kill.delete
115
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
116
+ end
117
+ end
118
+
119
+ it 'should pass hosts to container', :vcr do
120
+ perform
121
+ expect(hosts).to include '1.2.3.4:host1'
122
+ expect(hosts).to include '5.6.7.8:host2'
123
+ end
124
+ end
125
+
126
+ context 'given a file with hosts by name' do
127
+ let(:file) { 'hosts_name.json' }
128
+ let(:container) { Docker::Container.get 'uses_host' }
129
+ let(:hosts) { container.json['HostConfig']['ExtraHosts'] }
130
+ let(:perform) { subject }
131
+
132
+ after do
133
+ begin
134
+ c1 = Docker::Container.get 'uses_host'
135
+ c1.kill.delete
136
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
137
+ end
138
+ end
139
+
140
+ it 'should lookup ips for hosts with a hostname', :vcr do
141
+ perform
142
+ expect(hosts[0]).to match(/^[0-9\.]+:host1$/)
143
+ end
144
+ end
145
+
146
+ context 'given a file with volumes_from' do
147
+ let(:file) { 'volumes.json' }
148
+ let(:container) { Docker::Container.get 'mounts_volumes' }
149
+ let(:volumes_from) { container.json['HostConfig']['VolumesFrom'] }
150
+ let(:perform) { subject }
151
+
152
+ after do
153
+ begin
154
+ c1 = Docker::Container.get 'mounts_volumes'
155
+ c1.kill.delete
156
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
157
+ end
158
+ begin
159
+ c1 = Docker::Container.get 'exports_volumes'
160
+ c1.kill.delete
161
+ rescue Docker::Error::NotFoundError # rubocop:disable Lint/HandleExceptions
162
+ end
163
+ end
164
+
165
+ it 'should pass volumes_from to the right container', :vcr do
166
+ perform
167
+ expect(volumes_from).to eq ['exports_volumes']
168
+ end
169
+
170
+ it 'starts the dependant container last', :vcr do
171
+ running = 0
172
+ allow(DockerAdapter).to receive(:run).with hash_including(name: 'exports_volumes') do
173
+ running += 1
174
+ sleep 1
175
+ running -= 1
176
+ end
177
+
178
+ expect(DockerAdapter).to receive(:run).with hash_including(name: 'mounts_volumes') do
179
+ sleep 0.5
180
+ expect(running).to eq 0
181
+ end
182
+ perform
183
+ end
184
+ end
185
+
186
+ context 'given a file with a path' do
187
+ let(:file) { 'path.json' }
188
+ let(:container) { Docker::Container.get subject }
189
+
190
+ after do
191
+ container.kill.delete
192
+ end
193
+
194
+ it 'builds the image before starting it', :vcr do
195
+ skip 'VCR freaks out'
196
+ expect(DockerAdapter).to receive(:build).
197
+ with('spec/data/build').and_call_original
198
+
199
+ subject
200
+ end
201
+ end
202
+
203
+ context 'given a file with env variables' do
204
+ let(:file) { 'env.json' }
205
+
206
+ it 'passes the environemnt variables to docker' do
207
+ allow(DockerAdapter).to receive(:remove_container)
208
+ allow(DockerAdapter).to receive(:image_id_by_tag).with('hawknewton/show-env:0.0.1').
209
+ and_return 'env-testid'
210
+ expect(DockerAdapter).to receive(:run).with hash_including(
211
+ image_id: 'env-testid',
212
+ env: { 'NAME1' => 'VALUE1', 'NAME2' => 'VALUE2' }
213
+ )
214
+
215
+ subject
216
+ end
217
+ end
218
+
219
+ context 'given a file with ports' do
220
+ let(:file) { 'ports.json' }
221
+
222
+ it 'passes ports to docker' do
223
+ allow(DockerAdapter).to receive(:remove_container)
224
+ allow(DockerAdapter).to receive(:image_id_by_tag).with('hawknewton/show-env:0.0.1').
225
+ and_return 'env-testid'
226
+ expect(DockerAdapter).to receive(:run).with hash_including(
227
+ image_id: 'env-testid',
228
+ ports: ['80:8080', '12345']
229
+ )
230
+
231
+ subject
232
+ end
233
+ end
234
+
235
+ context 'with a file with active profiles' do
236
+ let(:file) { 'profiles.json' }
237
+ let(:active_profiles) { ['qa'] }
238
+
239
+ after do
240
+ container = Docker::Container.get 'profiles'
241
+ container.kill.delete
242
+ end
243
+
244
+ it 'uses the overridden image', :vcr do
245
+ subject
246
+ container = Docker::Container.get 'profiles'
247
+ image = Docker::Image.get 'hawknewton/show-env'
248
+ expect(container.info['Image']).to eq image.id
249
+ end
250
+ end
251
+
252
+ context 'when activating profiles that do not exist' do
253
+ let(:file) { 'profiles.json' }
254
+ let(:active_profiles) { ['notreallyathing'] }
255
+
256
+ after do
257
+ container = Docker::Container.get 'profiles'
258
+ container.delete force: true
259
+ end
260
+
261
+ it 'ignores the missing profile', :vcr do
262
+ subject
263
+ container = Docker::Container.get 'profiles'
264
+ image = Docker::Image.get 'hawknewton/true'
265
+ expect(container.info['Image']).to eq image.id
266
+ end
267
+ end
268
+ end
269
+ end
270
+ end
@@ -0,0 +1,82 @@
1
+ module Bigrig
2
+ describe ShipAction do
3
+ subject { described_class.new(file_name, version, false, credentials).perform }
4
+ let(:dir) { Dir.mktmpdir }
5
+ let(:version) { '1.2.3' }
6
+ let(:file) { 'ship.json' }
7
+
8
+ before do
9
+ allow(DockerAdapter).to receive :tag
10
+ allow(DockerAdapter).to receive :push
11
+ allow(DockerAdapter).to receive :build
12
+ end
13
+
14
+ around do |example|
15
+ FileUtils.copy_file test_file(file), File.join(dir, file_name)
16
+ FileUtils.cp_r "#{test_file('.')}/build", dir
17
+ Dir.chdir dir do
18
+ example.run
19
+ end
20
+ end
21
+
22
+ context 'using defaults' do
23
+ let(:opts) { {} }
24
+ let(:json) { JSON.parse File.read File.join(dir, 'bigrig-1.2.3.json') }
25
+ let(:tag) { json['containers']['ship-me']['tag'] }
26
+ let(:path) { json['containers']['ship-me']['path'] }
27
+ let(:file_name) { 'bigrig.json' }
28
+ let(:exists?) { File.exist? File.join(dir, "bigrig-#{version}.json") }
29
+ let(:credentials) { nil }
30
+
31
+ it 'creates a bigrig.json with a version' do
32
+ subject
33
+ expect(exists?).to be true
34
+ end
35
+
36
+ it 'adds a tag' do
37
+ subject
38
+ expect(tag).to eq '1.2.3'
39
+ end
40
+
41
+ it 'removes the path' do
42
+ subject
43
+ expect(path).to be_nil
44
+ end
45
+ end
46
+
47
+ context 'with a different file name' do
48
+ let(:opts) { {} }
49
+ let(:credentials) { nil }
50
+ let(:file_name) { 'custom.json' }
51
+ let(:exists?) { File.exist? File.join(dir, "custom-#{version}.json") }
52
+
53
+ it 'creates a file with that name' do
54
+ subject
55
+ expect(exists?).to be true
56
+ end
57
+ end
58
+
59
+ context 'with credentials' do
60
+ let(:opts) { {} }
61
+ let(:credentials) do
62
+ {
63
+ username: 'user',
64
+ password: 'pass',
65
+ email: 'email@email.com'
66
+ }
67
+ end
68
+ let(:file_name) { 'bigrig.json' }
69
+
70
+ it 'hands the token to DockerAdapter' do
71
+ expected = {
72
+ 'username' => 'user',
73
+ 'password' => 'pass',
74
+ 'email' => 'email@email.com',
75
+ 'serveraddress' => 'https://index.docker.io/v1'
76
+ }
77
+ expect(DockerAdapter).to receive(:push).with(':1.2.3', expected)
78
+ subject
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,19 @@
1
+ module Bigrig
2
+ describe DependencyGraph do
3
+ describe '#resolve' do
4
+ subject { described_class.new(containers).resolve }
5
+ context 'given two containers, one depending on the other' do
6
+ let(:containers) do
7
+ [
8
+ Container.new(name: 'test2', volumes_from: ['test1']),
9
+ Container.new(name: 'test1')
10
+ ]
11
+ end
12
+
13
+ it 'resolves in the correct order' do
14
+ expect(subject.map(&:name)).to match_array %w(test1 test2)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ module Bigrig
2
+ describe Descriptor do
3
+ subject { described_class.read test_file(file), profiles }
4
+
5
+ context 'given a simple descriptor' do
6
+ let(:file) { 'single.json' }
7
+ let(:tag) { subject.as_json['single-test']['tag'] }
8
+ let(:repo) { subject.as_json['single-test']['repo'] }
9
+ let(:profiles) { [] }
10
+
11
+ it 'returns JSON' do
12
+ expect(repo).to eq 'hawknewton/show-env'
13
+ expect(tag).to eq '0.0.1'
14
+ end
15
+ end
16
+
17
+ context 'given a descriptor and an active but missing profile' do
18
+ let(:file) { 'single.json' }
19
+ let(:repo) { subject.as_json['single-test']['repo'] }
20
+ let(:profiles) { ['dev'] }
21
+
22
+ it 'returns JSON' do
23
+ expect(repo).to eq 'hawknewton/show-env'
24
+ end
25
+ end
26
+
27
+ context 'given a descriptor with active profiles ' do
28
+ let(:file) { 'profiles.json' }
29
+ let(:profiles) { ['qa'] }
30
+ let(:env_vars) { subject.as_json['profiles']['env'] }
31
+ let(:repo) { subject.as_json['profiles']['repo'] }
32
+
33
+ it 'overrides present ENV values' do
34
+ expect(env_vars).to include 'NAME1' => 'VALUE1A'
35
+ end
36
+
37
+ it 'leaves existing ENV values alone' do
38
+ expect(env_vars).to include 'NAME2' => 'VALUE2'
39
+ end
40
+
41
+ it 'also overrides the repo' do
42
+ expect(repo).to eq 'hawknewton/show-env'
43
+ end
44
+ end
45
+
46
+ context 'given a descriptor that adds a container' do
47
+ let(:file) { 'addscontainer.json' }
48
+ let(:profiles) { ['new'] }
49
+ let(:container) { subject.as_json['new'] }
50
+
51
+ it 'adds the container' do
52
+ expect(container).to_not be_nil
53
+ end
54
+ end
55
+ end
56
+ end