whiskey_disk 0.0.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/README +152 -108
- data/TODO.txt +32 -12
- data/VERSION +1 -1
- data/bin/wd +36 -0
- data/lib/whiskey_disk/config.rb +79 -38
- data/lib/whiskey_disk/rake.rb +36 -0
- data/lib/whiskey_disk.rb +24 -11
- data/spec/wd_command_spec.rb +421 -0
- data/spec/whiskey_disk/config_spec.rb +356 -221
- data/spec/whiskey_disk/rake_spec.rb +255 -0
- data/spec/whiskey_disk_spec.rb +85 -19
- data/tasks/deploy.rake +1 -1
- data/whiskey_disk.gemspec +76 -0
- metadata +35 -15
- data/lib/tasks/deploy.rb +0 -37
- data/spec/tasks/deploy_spec.rb +0 -295
data/lib/whiskey_disk.rb
CHANGED
@@ -27,6 +27,26 @@ class WhiskeyDisk
|
|
27
27
|
! (self[:domain].nil? or self[:domain] == '')
|
28
28
|
end
|
29
29
|
|
30
|
+
def has_config_repo?
|
31
|
+
! (self[:config_repository].nil? or self[:config_repository] == '')
|
32
|
+
end
|
33
|
+
|
34
|
+
def branch
|
35
|
+
(self[:branch] and self[:branch] != '') ? self[:branch] : 'master'
|
36
|
+
end
|
37
|
+
|
38
|
+
def config_branch
|
39
|
+
(self[:config_branch] and self[:config_branch] != '') ? self[:config_branch] : 'master'
|
40
|
+
end
|
41
|
+
|
42
|
+
def env_vars
|
43
|
+
return '' unless self[:rake_env]
|
44
|
+
self[:rake_env].keys.inject('') do |buffer,k|
|
45
|
+
buffer += "#{k}='#{self[:rake_env][k]}' "
|
46
|
+
buffer
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
30
50
|
def parent_path(path)
|
31
51
|
File.split(path).first
|
32
52
|
end
|
@@ -37,7 +57,7 @@ class WhiskeyDisk
|
|
37
57
|
|
38
58
|
def needs(*keys)
|
39
59
|
keys.each do |key|
|
40
|
-
raise "No value for '#{key}' declared in configuration files [#{WhiskeyDisk::Config.
|
60
|
+
raise "No value for '#{key}' declared in configuration files [#{WhiskeyDisk::Config.configuration_file}]" unless self[key]
|
41
61
|
end
|
42
62
|
end
|
43
63
|
|
@@ -71,11 +91,6 @@ class WhiskeyDisk
|
|
71
91
|
enqueue "git clone #{self[:repository]} #{tail_path(self[:deploy_to])} ; true"
|
72
92
|
end
|
73
93
|
|
74
|
-
def install_hooks
|
75
|
-
needs(:deploy_to)
|
76
|
-
# FIXME - TODO: MORE HERE
|
77
|
-
end
|
78
|
-
|
79
94
|
def checkout_configuration_repository
|
80
95
|
needs(:deploy_config_to, :config_repository)
|
81
96
|
enqueue "cd #{parent_path(self[:deploy_config_to])}"
|
@@ -84,7 +99,6 @@ class WhiskeyDisk
|
|
84
99
|
|
85
100
|
def update_main_repository_checkout
|
86
101
|
needs(:deploy_to)
|
87
|
-
branch = (self[:branch] and self[:branch] != '') ? self[:branch] : 'master'
|
88
102
|
enqueue "cd #{self[:deploy_to]}"
|
89
103
|
enqueue "git fetch origin +refs/heads/#{branch}:refs/remotes/origin/#{branch}"
|
90
104
|
enqueue "git reset --hard origin/#{branch}"
|
@@ -93,25 +107,24 @@ class WhiskeyDisk
|
|
93
107
|
def update_configuration_repository_checkout
|
94
108
|
needs(:deploy_config_to)
|
95
109
|
enqueue "cd #{self[:deploy_config_to]}"
|
96
|
-
enqueue "git fetch origin +refs/heads
|
97
|
-
enqueue "git reset --hard origin
|
110
|
+
enqueue "git fetch origin +refs/heads/#{config_branch}:refs/remotes/origin/#{config_branch}"
|
111
|
+
enqueue "git reset --hard origin/#{config_branch}"
|
98
112
|
end
|
99
113
|
|
100
114
|
def refresh_configuration
|
101
115
|
needs(:deploy_to, :deploy_config_to)
|
116
|
+
raise "Must specify project name when using a configuration repository." if self[:project] == 'unnamed_project'
|
102
117
|
enqueue "rsync -av --progress #{self[:deploy_config_to]}/#{self[:project]}/#{self[:environment]}/ #{self[:deploy_to]}/"
|
103
118
|
end
|
104
119
|
|
105
120
|
def run_post_setup_hooks
|
106
121
|
needs(:deploy_to)
|
107
|
-
env_vars = self[:rake_env] ? self[:rake_env].keys.inject('') {|b,k| b += "#{k}='#{self[:rake_env][k]}' "; b } : ''
|
108
122
|
enqueue "cd #{self[:deploy_to]}"
|
109
123
|
enqueue "#{env_vars} rake --trace deploy:post_setup to=#{self[:environment]}"
|
110
124
|
end
|
111
125
|
|
112
126
|
def run_post_deploy_hooks
|
113
127
|
needs(:deploy_to)
|
114
|
-
env_vars = self[:rake_env] ? self[:rake_env].keys.inject('') {|b,k| b += "#{k}='#{self[:rake_env][k]}' "; b } : ''
|
115
128
|
enqueue "cd #{self[:deploy_to]}"
|
116
129
|
enqueue "#{env_vars} rake --trace deploy:post_deploy to=#{self[:environment]}"
|
117
130
|
end
|
@@ -0,0 +1,421 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
def run_command
|
5
|
+
eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin wd]))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'wd command' do
|
9
|
+
before do
|
10
|
+
ENV['to'] = ENV['path'] = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'when no command-line arguments are specified' do
|
14
|
+
before do
|
15
|
+
Object.send(:remove_const, :ARGV)
|
16
|
+
ARGV = []
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not run rake tasks' do
|
20
|
+
Rake::Application.should.receive(:new).never
|
21
|
+
lambda { run_command }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should fail' do
|
25
|
+
lambda { run_command }.should.raise
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "when the 'setup' command is specified" do
|
30
|
+
before do
|
31
|
+
Object.send(:remove_const, :ARGV)
|
32
|
+
ARGV = ['setup']
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'and no target is specified' do
|
36
|
+
it 'should not run rake tasks' do
|
37
|
+
Rake::Application.should.receive(:new).never
|
38
|
+
lambda { run_command }
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should fail' do
|
42
|
+
lambda { run_command }.should.raise
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'and a --to argument is specified' do
|
47
|
+
before do
|
48
|
+
ARGV.push '--to=foo'
|
49
|
+
@rake = Rake::Task['deploy:setup']
|
50
|
+
@rake.stub!(:invoke)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not fail' do
|
54
|
+
lambda { run_command }.should.not.raise
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should run the deploy:setup rake task' do
|
58
|
+
@rake.should.receive(:invoke)
|
59
|
+
run_command
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should make the specified target available as a "to" argument to the rake task' do
|
63
|
+
run_command
|
64
|
+
ENV['to'].should == 'foo'
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'and a --path argument is specified' do
|
68
|
+
before do
|
69
|
+
ARGV.push '--path=/path/to/foo'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
73
|
+
run_command
|
74
|
+
ENV['path'].should == '/path/to/foo'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should fail if the rake task fails' do
|
78
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
79
|
+
lambda { run_command }.should.raise
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not fail if the rake task succeeds' do
|
83
|
+
@rake.stub!(:invoke).and_return(true)
|
84
|
+
lambda { run_command }.should.not.raise
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'and a -p argument is specified' do
|
89
|
+
before do
|
90
|
+
ARGV.push '-p'
|
91
|
+
ARGV.push '/path/to/foo'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
95
|
+
run_command
|
96
|
+
ENV['path'].should == '/path/to/foo'
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should fail if the rake task fails' do
|
100
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
101
|
+
lambda { run_command }.should.raise
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should not fail if the rake task succeeds' do
|
105
|
+
@rake.stub!(:invoke).and_return(true)
|
106
|
+
lambda { run_command }.should.not.raise
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'and no --path or -p argument is specified' do
|
111
|
+
it 'should not make a "path" argument available to the rake task' do
|
112
|
+
ENV['path'].should.be.nil
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should fail if the rake task fails' do
|
116
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
117
|
+
lambda { run_command }.should.raise
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should not fail if the rake task succeeds' do
|
121
|
+
@rake.stub!(:invoke).and_return(true)
|
122
|
+
lambda { run_command }.should.not.raise
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'and a -t argument is specified' do
|
128
|
+
before do
|
129
|
+
ARGV.push '-t'
|
130
|
+
ARGV.push 'foo'
|
131
|
+
@rake = Rake::Task['deploy:setup']
|
132
|
+
@rake.stub!(:invoke)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should not fail' do
|
136
|
+
lambda { run_command }.should.not.raise
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should run the deploy:setup rake task' do
|
140
|
+
@rake.should.receive(:invoke)
|
141
|
+
run_command
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should make the specified target available as a "to" argument to the rake task' do
|
145
|
+
run_command
|
146
|
+
ENV['to'].should == 'foo'
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'and a --path argument is specified' do
|
150
|
+
before do
|
151
|
+
ARGV.push '--path=/path/to/foo'
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
155
|
+
run_command
|
156
|
+
ENV['path'].should == '/path/to/foo'
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should fail if the rake task fails' do
|
160
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
161
|
+
lambda { run_command }.should.raise
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should not fail if the rake task succeeds' do
|
165
|
+
@rake.stub!(:invoke).and_return(true)
|
166
|
+
lambda { run_command }.should.not.raise
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'and a -p argument is specified' do
|
171
|
+
before do
|
172
|
+
ARGV.push '-p'
|
173
|
+
ARGV.push '/path/to/foo'
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
177
|
+
run_command
|
178
|
+
ENV['path'].should == '/path/to/foo'
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should fail if the rake task fails' do
|
182
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
183
|
+
lambda { run_command }.should.raise
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should not fail if the rake task succeeds' do
|
187
|
+
@rake.stub!(:invoke).and_return(true)
|
188
|
+
lambda { run_command }.should.not.raise
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe 'and no --path or -p argument is specified' do
|
193
|
+
it 'should not make a "path" argument available to the rake task' do
|
194
|
+
ENV['path'].should.be.nil
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should fail if the rake task fails' do
|
198
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
199
|
+
lambda { run_command }.should.raise
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should not fail if the rake task succeeds' do
|
203
|
+
@rake.stub!(:invoke).and_return(true)
|
204
|
+
lambda { run_command }.should.not.raise
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "when the 'deploy' command is specified" do
|
211
|
+
describe 'but no target is specified' do
|
212
|
+
before do
|
213
|
+
Object.send(:remove_const, :ARGV)
|
214
|
+
ARGV = ['deploy']
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should not run rake tasks' do
|
218
|
+
Rake::Application.should.receive(:new).never
|
219
|
+
lambda { run_command }
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should fail' do
|
223
|
+
lambda { run_command }.should.raise
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe 'and a --to argument is specified' do
|
228
|
+
before do
|
229
|
+
ARGV.push '--to=foo'
|
230
|
+
@rake = Rake::Task['deploy:now']
|
231
|
+
@rake.stub!(:invoke)
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should not fail' do
|
235
|
+
lambda { run_command }.should.not.raise
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'should run the deploy:now rake task' do
|
239
|
+
@rake.should.receive(:invoke)
|
240
|
+
run_command
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should make the specified target available as a "to" argument to the rake task' do
|
244
|
+
run_command
|
245
|
+
ENV['to'].should == 'foo'
|
246
|
+
end
|
247
|
+
describe 'and a --path argument is specified' do
|
248
|
+
before do
|
249
|
+
ARGV.push '--path=/path/to/foo'
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
253
|
+
run_command
|
254
|
+
ENV['path'].should == '/path/to/foo'
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'should fail if the rake task fails' do
|
258
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
259
|
+
lambda { run_command }.should.raise
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should not fail if the rake task succeeds' do
|
263
|
+
@rake.stub!(:invoke).and_return(true)
|
264
|
+
lambda { run_command }.should.not.raise
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe 'and a -p argument is specified' do
|
269
|
+
before do
|
270
|
+
ARGV.push '-p'
|
271
|
+
ARGV.push '/path/to/foo'
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
275
|
+
run_command
|
276
|
+
ENV['path'].should == '/path/to/foo'
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'should fail if the rake task fails' do
|
280
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
281
|
+
lambda { run_command }.should.raise
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'should not fail if the rake task succeeds' do
|
285
|
+
@rake.stub!(:invoke).and_return(true)
|
286
|
+
lambda { run_command }.should.not.raise
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe 'and no --path or -p argument is specified' do
|
291
|
+
it 'should not make a "path" argument available to the rake task' do
|
292
|
+
ENV['path'].should.be.nil
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'should fail if the rake task fails' do
|
296
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
297
|
+
lambda { run_command }.should.raise
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should not fail if the rake task succeeds' do
|
301
|
+
@rake.stub!(:invoke).and_return(true)
|
302
|
+
lambda { run_command }.should.not.raise
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
describe 'and a -t argument is specified' do
|
308
|
+
before do
|
309
|
+
ARGV.push '-t'
|
310
|
+
ARGV.push 'foo'
|
311
|
+
@rake = Rake::Task['deploy:now']
|
312
|
+
@rake.stub!(:invoke)
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'should not fail' do
|
316
|
+
lambda { run_command }.should.not.raise
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'should run the deploy:now rake task' do
|
320
|
+
@rake.should.receive(:invoke)
|
321
|
+
run_command
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'should make the specified target available as a "to" argument to the rake task' do
|
325
|
+
run_command
|
326
|
+
ENV['to'].should == 'foo'
|
327
|
+
end
|
328
|
+
|
329
|
+
describe 'and a --path argument is specified' do
|
330
|
+
before do
|
331
|
+
ARGV.push '--path=/path/to/foo'
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
335
|
+
run_command
|
336
|
+
ENV['path'].should == '/path/to/foo'
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'should fail if the rake task fails' do
|
340
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
341
|
+
lambda { run_command }.should.raise
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'should not fail if the rake task succeeds' do
|
345
|
+
@rake.stub!(:invoke).and_return(true)
|
346
|
+
lambda { run_command }.should.not.raise
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
describe 'and a -p argument is specified' do
|
351
|
+
before do
|
352
|
+
ARGV.push '-p'
|
353
|
+
ARGV.push '/path/to/foo'
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'should make the specified path available as a "path" argument to the rake task' do
|
357
|
+
run_command
|
358
|
+
ENV['path'].should == '/path/to/foo'
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'should fail if the rake task fails' do
|
362
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
363
|
+
lambda { run_command }.should.raise
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'should not fail if the rake task succeeds' do
|
367
|
+
@rake.stub!(:invoke).and_return(true)
|
368
|
+
lambda { run_command }.should.not.raise
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
describe 'and no --path or -p argument is specified' do
|
373
|
+
it 'should not make a "path" argument available to the rake task' do
|
374
|
+
ENV['path'].should.be.nil
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'should fail if the rake task fails' do
|
378
|
+
@rake.stub!(:invoke).and_raise(RuntimeError)
|
379
|
+
lambda { run_command }.should.raise
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'should not fail if the rake task succeeds' do
|
383
|
+
@rake.stub!(:invoke).and_return(true)
|
384
|
+
lambda { run_command }.should.not.raise
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe 'and more than one command is specified' do
|
391
|
+
before do
|
392
|
+
Object.send(:remove_const, :ARGV)
|
393
|
+
ARGV = ['frazzlebazzle', 'shizzlebizzle']
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'should fail if no target is specified' do
|
397
|
+
lambda { run_command }.should.raise
|
398
|
+
end
|
399
|
+
|
400
|
+
it 'should fail even if a target is specified' do
|
401
|
+
ARGV.push('--to=foo')
|
402
|
+
lambda { run_command }.should.raise
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
describe 'and an unknown command is specified' do
|
407
|
+
before do
|
408
|
+
Object.send(:remove_const, :ARGV)
|
409
|
+
ARGV = ['frazzlebazzle']
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'should fail when no target is specified' do
|
413
|
+
lambda { run_command }.should.raise
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'should fail when a target is specified' do
|
417
|
+
ARGV.push('--to=foo')
|
418
|
+
lambda { run_command }.should.raise
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|