whiskey_disk 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,387 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper.rb'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'whiskey_disk'))
3
+ require 'rake'
4
+
5
+ describe 'requiring the main library' do
6
+ before do
7
+ Rake.application = @rake = Rake::Application.new
8
+ load File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'tasks', 'deploy.rb'))
9
+ end
10
+
11
+ after do
12
+ Rake.application = nil
13
+ end
14
+
15
+ it 'should make the deploy:setup rake task available' do
16
+ Rake::Task.task_defined?('deploy:setup').should.be.true
17
+ end
18
+
19
+ it 'should make the deploy:now rake task available' do
20
+ Rake::Task.task_defined?('deploy:now').should.be.true
21
+ end
22
+ end
23
+
24
+ describe 'WhiskeyDisk' do
25
+ describe 'ensuring that the parent path for the main repository checkout is present' do
26
+ before do
27
+ @parameters = { 'deploy_to' => '/path/to/main/repo' }
28
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
29
+ WhiskeyDisk.reset
30
+ end
31
+
32
+ it 'should fail if the deployment path is not specified' do
33
+ WhiskeyDisk::Config.stub!(:fetch).and_return({})
34
+ WhiskeyDisk.reset
35
+ lambda { WhiskeyDisk.ensure_main_parent_path_is_present }.should.raise
36
+ end
37
+
38
+ it 'should attempt to create the parent path for the repository' do
39
+ WhiskeyDisk.ensure_main_parent_path_is_present
40
+ WhiskeyDisk.buffer.last.should.match(%r{mkdir -p /path/to/main})
41
+ WhiskeyDisk.buffer.last.should.not.match(%r{/path/to/main/repo})
42
+ end
43
+ end
44
+
45
+ describe 'ensuring that the parent path for the configuration repository checkout is present' do
46
+ before do
47
+ @parameters = { 'deploy_config_to' => '/path/to/config/repo' }
48
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
49
+ WhiskeyDisk.reset
50
+ end
51
+
52
+ it 'should fail if the configuration deployment path is not specified' do
53
+ WhiskeyDisk::Config.stub!(:fetch).and_return({})
54
+ WhiskeyDisk.reset
55
+ lambda { WhiskeyDisk.ensure_config_parent_path_is_present }.should.raise
56
+ end
57
+
58
+ it 'should attempt to create the parent path for the repository' do
59
+ WhiskeyDisk.ensure_config_parent_path_is_present
60
+ WhiskeyDisk.buffer.last.should.match(%r{mkdir -p /path/to/config})
61
+ WhiskeyDisk.buffer.last.should.not.match(%r{/path/to/config/repo})
62
+ end
63
+ end
64
+
65
+ describe 'checking out the main repository' do
66
+ before do
67
+ @parameters = { 'deploy_to' => '/path/to/main/repo', 'repository' => 'git@ogtastic.com:whiskey_disk.git' }
68
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
69
+ WhiskeyDisk.reset
70
+ end
71
+
72
+ it 'should fail if the deployment path is not specified' do
73
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_to' => nil))
74
+ WhiskeyDisk.reset
75
+ lambda { WhiskeyDisk.checkout_main_repository }.should.raise
76
+ end
77
+
78
+ it 'should fail if the repository is not specified' do
79
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('repository' => nil))
80
+ WhiskeyDisk.reset
81
+ lambda { WhiskeyDisk.checkout_main_repository }.should.raise
82
+ end
83
+
84
+ it 'should work from the main repository checkout parent path' do
85
+ WhiskeyDisk.checkout_main_repository
86
+ WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/main})
87
+ WhiskeyDisk.buffer.join(' ').should.not.match(%r{cd /path/to/main/repo})
88
+ end
89
+
90
+ it 'should attempt to clone the main repository to the repository checkout path' do
91
+ WhiskeyDisk.checkout_main_repository
92
+ WhiskeyDisk.buffer.join(' ').should.match(%r{clone #{@parameters['repository']} repo})
93
+ end
94
+
95
+ it 'should ignore errors from failing to clone an existing repository' do
96
+ WhiskeyDisk.checkout_main_repository
97
+ WhiskeyDisk.buffer.join(' ').should.match(%r{\|\| true})
98
+ end
99
+ end
100
+
101
+ describe 'installing a post-receive hook on the checked out main repository' do
102
+ before do
103
+ @parameters = { 'deploy_to' => '/path/to/main/repo' }
104
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
105
+ WhiskeyDisk.reset
106
+ end
107
+
108
+ it 'should fail if the deployment path is not specified' do
109
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_to' => nil))
110
+ WhiskeyDisk.reset
111
+ lambda { WhiskeyDisk.install_hooks }.should.raise
112
+ end
113
+
114
+ # FIXME -- TODO: MORE HERE
115
+ end
116
+
117
+ describe 'checking out the configuration repository' do
118
+ before do
119
+ @parameters = { 'deploy_config_to' => '/path/to/config/repo', 'config_repository' => 'git@ogtastic.com:config.git' }
120
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
121
+ WhiskeyDisk.reset
122
+ end
123
+
124
+ it 'should fail if the configuration deployment path is not specified' do
125
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_config_to' => nil))
126
+ WhiskeyDisk.reset
127
+ lambda { WhiskeyDisk.checkout_configuration_repository }.should.raise
128
+ end
129
+
130
+ it 'should fail if the configuration repository is not specified' do
131
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('config_repository' => nil))
132
+ WhiskeyDisk.reset
133
+ lambda { WhiskeyDisk.checkout_configuration_repository }.should.raise
134
+ end
135
+
136
+ it 'should work from the configuration repository checkout parent path' do
137
+ WhiskeyDisk.checkout_configuration_repository
138
+ WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/config})
139
+ WhiskeyDisk.buffer.join(' ').should.not.match(%r{cd /path/to/config/repo})
140
+ end
141
+
142
+ it 'should attempt to clone the configuration repository to the repository checkout path' do
143
+ WhiskeyDisk.checkout_configuration_repository
144
+ WhiskeyDisk.buffer.join(' ').should.match(%r{clone #{@parameters['config_repository']} repo})
145
+ end
146
+
147
+ it 'should ignore errors from failing to clone an existing repository' do
148
+ WhiskeyDisk.checkout_configuration_repository
149
+ WhiskeyDisk.buffer.join(' ').should.match(%r{\|\| true})
150
+ end
151
+ end
152
+
153
+ describe 'updating the main repository checkout' do
154
+ before do
155
+ @parameters = { 'deploy_to' => '/path/to/main/repo' }
156
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
157
+ WhiskeyDisk.reset
158
+ end
159
+
160
+ it 'should fail if the deployment path is not specified' do
161
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_to' => nil))
162
+ WhiskeyDisk.reset
163
+ lambda { WhiskeyDisk.update_main_repository_checkout }.should.raise
164
+ end
165
+
166
+ it 'should work from the main repository checkout path' do
167
+ WhiskeyDisk.update_main_repository_checkout
168
+ WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/main/repo})
169
+ end
170
+
171
+ it 'should attempt to fetch only the master branch from the origin if no branch is specified' do
172
+ WhiskeyDisk.update_main_repository_checkout
173
+ WhiskeyDisk.buffer.join(' ').should.match(%r{git fetch origin \+refs/heads/master:refs/remotes/origin/master})
174
+ end
175
+
176
+ it 'should attempt to fetch the specified branch from the origin if a branch is specified' do
177
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge({'branch' => 'production'}))
178
+ WhiskeyDisk.reset
179
+ WhiskeyDisk.update_main_repository_checkout
180
+ WhiskeyDisk.buffer.join(' ').should.match(%r{git fetch origin \+refs/heads/production:refs/remotes/origin/production})
181
+ end
182
+
183
+ it 'should attempt to reset the master branch from the origin if no branch is specified' do
184
+ WhiskeyDisk.update_main_repository_checkout
185
+ WhiskeyDisk.buffer.join(' ').should.match(%r{git reset --hard origin/master})
186
+ end
187
+
188
+ it 'should attempt to reset the specified branch from the origin if a branch is specified' do
189
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge({'branch' => 'production'}))
190
+ WhiskeyDisk.reset
191
+ WhiskeyDisk.update_main_repository_checkout
192
+ WhiskeyDisk.buffer.join(' ').should.match(%r{git reset --hard origin/production})
193
+ end
194
+ end
195
+
196
+ describe 'updating the configuration repository checkout' do
197
+ before do
198
+ @parameters = { 'deploy_config_to' => '/path/to/config/repo' }
199
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
200
+ WhiskeyDisk.reset
201
+ end
202
+
203
+ it 'should fail if the configuration deployment path is not specified' do
204
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_config_to' => nil))
205
+ WhiskeyDisk.reset
206
+ lambda { WhiskeyDisk.update_configuration_repository_checkout }.should.raise
207
+ end
208
+
209
+ it 'should work from the main repository checkout path' do
210
+ WhiskeyDisk.update_configuration_repository_checkout
211
+ WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/config/repo})
212
+ end
213
+
214
+ it 'should attempt to fetch only the master branch from the origin' do
215
+ WhiskeyDisk.update_configuration_repository_checkout
216
+ WhiskeyDisk.buffer.join(' ').should.match(%r{git fetch origin \+refs/heads/master:refs/remotes/origin/master})
217
+ end
218
+
219
+ it 'should attempt to reset the master branch from the origin' do
220
+ WhiskeyDisk.update_configuration_repository_checkout
221
+ WhiskeyDisk.buffer.join(' ').should.match(%r{git reset --hard origin/master})
222
+ end
223
+ end
224
+
225
+ describe 'refreshing the configuration' do
226
+ before do
227
+ @parameters = { 'deploy_to' => '/path/to/main/repo',
228
+ 'deploy_config_to' => '/path/to/config/repo',
229
+ 'environment' => 'production',
230
+ 'project' => 'whiskey_disk' }
231
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
232
+ WhiskeyDisk.reset
233
+ end
234
+
235
+ it 'should fail if the main deployment path is not specified' do
236
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_to' => nil))
237
+ WhiskeyDisk.reset
238
+ lambda { WhiskeyDisk.refresh_configuration }.should.raise
239
+ end
240
+
241
+ it 'should fail if the configuration deployment path is not specified' do
242
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters.merge('deploy_config_to' => nil))
243
+ WhiskeyDisk.reset
244
+ lambda { WhiskeyDisk.refresh_configuration }.should.raise
245
+ end
246
+
247
+ it 'should use rsync to overlay the configuration checkout for the project in the configured environment onto the main checkout' do
248
+ WhiskeyDisk.refresh_configuration
249
+ WhiskeyDisk.buffer.last.should.match(%r{rsync.* /path/to/config/repo/whiskey_disk/production/ /path/to/main/repo/})
250
+ end
251
+ end
252
+
253
+ describe 'running post setup hooks' do
254
+ before do
255
+ @parameters = { 'deploy_to' => '/path/to/main/repo' }
256
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
257
+ WhiskeyDisk.reset
258
+ end
259
+
260
+ it 'should fail if the deployment path is not specified' do
261
+ WhiskeyDisk::Config.stub!(:fetch).and_return({})
262
+ WhiskeyDisk.reset
263
+ lambda { WhiskeyDisk.run_post_setup_hooks }.should.raise
264
+ end
265
+
266
+ it 'should work from the main checkout directory' do
267
+ WhiskeyDisk.run_post_setup_hooks
268
+ WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/main/repo})
269
+ end
270
+
271
+ it 'should attempt to run the post setup rake tasks' do
272
+ WhiskeyDisk.run_post_setup_hooks
273
+ WhiskeyDisk.buffer.join(' ').should.match(%r{rake.*deploy:post_setup})
274
+ end
275
+ end
276
+
277
+ describe 'running post deployment hooks' do
278
+ before do
279
+ @parameters = { 'deploy_to' => '/path/to/main/repo' }
280
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
281
+ WhiskeyDisk.reset
282
+ end
283
+
284
+ it 'should fail if the deployment path is not specified' do
285
+ WhiskeyDisk::Config.stub!(:fetch).and_return({})
286
+ WhiskeyDisk.reset
287
+ lambda { WhiskeyDisk.run_post_deploy_hooks }.should.raise
288
+ end
289
+
290
+ it 'should work from the main checkout directory' do
291
+ WhiskeyDisk.run_post_deploy_hooks
292
+ WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/main/repo})
293
+ end
294
+
295
+ it 'should attempt to run the post deployment rake tasks' do
296
+ WhiskeyDisk.run_post_deploy_hooks
297
+ WhiskeyDisk.buffer.join(' ').should.match(%r{rake.*deploy:post_deploy})
298
+ end
299
+ end
300
+
301
+ describe 'flushing changes' do
302
+ describe 'when running remotely' do
303
+ before do
304
+ @parameters = { 'domain' => 'www.domain.com', 'deploy_to' => '/path/to/main/repo' }
305
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
306
+ WhiskeyDisk.reset
307
+ WhiskeyDisk.stub!(:bundle).and_return('command string')
308
+ WhiskeyDisk.stub!(:register_configuration)
309
+ WhiskeyDisk.stub!(:run)
310
+ end
311
+
312
+ it 'should register our configuration with vlad' do
313
+ WhiskeyDisk.should.receive(:register_configuration)
314
+ WhiskeyDisk.flush
315
+ end
316
+
317
+ it 'should bundle the buffer of commands' do
318
+ WhiskeyDisk.enqueue('x')
319
+ WhiskeyDisk.enqueue('y')
320
+ WhiskeyDisk.should.receive(:bundle).and_return('command string')
321
+ WhiskeyDisk.flush
322
+ end
323
+
324
+ it 'should use "run" to run all the bundled commands at once' do
325
+ WhiskeyDisk.should.receive(:run).with('command string')
326
+ WhiskeyDisk.flush
327
+ end
328
+ end
329
+
330
+ describe 'when running locally' do
331
+ before do
332
+ @parameters = { 'deploy_to' => '/path/to/main/repo' }
333
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
334
+ WhiskeyDisk.reset
335
+ WhiskeyDisk.stub!(:bundle).and_return('command string')
336
+ WhiskeyDisk.stub!(:system)
337
+ end
338
+
339
+ it 'should NOT register our configuration with vlad' do
340
+ WhiskeyDisk.should.not.receive(:register_configuration)
341
+ WhiskeyDisk.flush
342
+ end
343
+
344
+ it 'should bundle the buffer of commands' do
345
+ WhiskeyDisk.enqueue('x')
346
+ WhiskeyDisk.enqueue('y')
347
+ WhiskeyDisk.should.receive(:bundle).and_return('command string')
348
+ WhiskeyDisk.flush
349
+ end
350
+
351
+ it 'should use "system" to run all the bundled commands at once' do
352
+ WhiskeyDisk.should.receive(:system).with('command string')
353
+ WhiskeyDisk.flush
354
+ end
355
+ end
356
+ end
357
+
358
+ describe 'bundling up buffered commands for execution' do
359
+ before do
360
+ WhiskeyDisk.reset
361
+ end
362
+
363
+ it 'should return an empty string if there are no commands' do
364
+ WhiskeyDisk.bundle.should == ''
365
+ end
366
+
367
+ it 'should wrap each command as a subshell () and join with &&s' do
368
+ WhiskeyDisk.enqueue("cd foo/bar/baz || true")
369
+ WhiskeyDisk.enqueue("rsync -avz --progress /yer/mom /yo/")
370
+ WhiskeyDisk.bundle.should == "(cd foo/bar/baz || true) && (rsync -avz --progress /yer/mom /yo/)"
371
+ end
372
+ end
373
+
374
+ describe 'registering the configuration with vlad' do
375
+ before do
376
+ @parameters = { 'deploy_to' => '/path/to/main/repo', 'foo' => 'bar', 'domain' => 'name' }
377
+ WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
378
+ WhiskeyDisk.reset
379
+ end
380
+
381
+ it "should call vlad's 'set' for each configuration parameters" do
382
+ @parameters.each_pair {|k,v| WhiskeyDisk.should.receive(:set).with(k, v) }
383
+ WhiskeyDisk.register_configuration
384
+ end
385
+ end
386
+ end
387
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whiskey_disk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rick Bradley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-30 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: vlad
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.2
24
+ version:
25
+ description: Opinionated gem for doing fast git-based server deployments.
26
+ email: rick@rickbradley.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - .gitignore
35
+ - README
36
+ - Rakefile
37
+ - TODO.txt
38
+ - VERSION
39
+ - examples/deploy-staging.yml
40
+ - examples/deploy.rake
41
+ - examples/deploy.yml
42
+ - init.rb
43
+ - install.rb
44
+ - lib/tasks/deploy.rb
45
+ - lib/whiskey_disk.rb
46
+ - lib/whiskey_disk/config.rb
47
+ - spec/.bacon
48
+ - spec/init_spec.rb
49
+ - spec/install_spec.rb
50
+ - spec/spec_helper.rb
51
+ - spec/tasks/deploy_spec.rb
52
+ - spec/whiskey_disk/config_spec.rb
53
+ - spec/whiskey_disk_spec.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/flogic/whiskey_disk
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: embarrassingly fast deployments.
82
+ test_files:
83
+ - spec/init_spec.rb
84
+ - spec/install_spec.rb
85
+ - spec/spec_helper.rb
86
+ - spec/tasks/deploy_spec.rb
87
+ - spec/whiskey_disk/config_spec.rb
88
+ - spec/whiskey_disk_spec.rb