whiskey_disk 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +45 -10
- data/Rakefile +3 -4
- data/TODO.txt +16 -13
- data/VERSION +1 -1
- data/lib/whiskey_disk.rb +14 -1
- data/spec/whiskey_disk_spec.rb +130 -30
- data/whiskey_disk.gemspec +2 -2
- metadata +4 -4
data/README.markdown
CHANGED
@@ -84,15 +84,17 @@ As a rails plugin:
|
|
84
84
|
|
85
85
|
Known config file settings (if you're familiar with capistrano and vlad these should seem eerily familiar):
|
86
86
|
|
87
|
-
domain:
|
88
|
-
deploy_to:
|
89
|
-
repository:
|
90
|
-
branch:
|
91
|
-
deploy_config_to:
|
92
|
-
config_repository:
|
93
|
-
config_branch:
|
94
|
-
project:
|
95
|
-
|
87
|
+
domain: host on which to deploy (this is an ssh connect string)
|
88
|
+
deploy_to: path to which to deploy main application
|
89
|
+
repository: git repo path for main application
|
90
|
+
branch: git branch to deploy from main application git repo (default: master)
|
91
|
+
deploy_config_to: where to deploy the configuration repository
|
92
|
+
config_repository: git repository for configuration files
|
93
|
+
config_branch: git branch to deploy from configuration git repo (default: master)
|
94
|
+
project: project name (used to compute path in configuration checkout)
|
95
|
+
post_deploy_script: path to a shell script to run after deployment
|
96
|
+
post_setup_script: path to a shell script to run after setup
|
97
|
+
rake_env: hash of environment variables to set when running post_setup and post_deploy rake tasks
|
96
98
|
|
97
99
|
|
98
100
|
A simple config/deploy.yml might look like:
|
@@ -114,6 +116,39 @@ of deploy:setup
|
|
114
116
|
at the end of deploy:now
|
115
117
|
|
116
118
|
|
119
|
+
#### post\_deploy\_script and post\_setup\_script ###
|
120
|
+
|
121
|
+
Whiskey\_disk provides rake task hooks (deploy:post\_setup and deploy:post\_deploy) to allow running custom
|
122
|
+
code after setup or deployment. There are situations where it is desirable to run some commands prior to
|
123
|
+
running those rake tasks (e.g., if using bundler and needing to do a 'bundle install' before running rake).
|
124
|
+
It may also be the case that the target system doesn't have rake (and/or ruby) installed, but some post-setup
|
125
|
+
or post-deploy operations need to happen. For these reasons, whiskey\_disk allows specifying a (bash-compatible)
|
126
|
+
shell script to run after setup and/or deployment via the post\_deploy\_script and post\_setup\_script settings
|
127
|
+
in the configuration file. These scripts, when specified, are run immediately before running the deploy:post\_setup
|
128
|
+
or deploy:post\_deploy rake tasks, if they are present.
|
129
|
+
|
130
|
+
The paths provided to post\_deploy\_script and post\_setup\_script can be either absolute or relative. A path
|
131
|
+
starting with a '/' is an absolute path, and the script specified should be at that exact location on the
|
132
|
+
target filesystem. A path which does not start with a '/' is a relative path, and the script specified should
|
133
|
+
be located at the specified path under the deployed application path. This implies that it's possible to
|
134
|
+
manage post\_setup and post\_deploy scripts out of a configuration repository.
|
135
|
+
|
136
|
+
A config/deploy.yml using post\_deploy\_script and post\_setup\_script might look like this:
|
137
|
+
|
138
|
+
production:
|
139
|
+
domain: "ogc@www.ogtastic.com"
|
140
|
+
deploy_to: "/var/www/www.ogtastic.com"
|
141
|
+
repository: "git@ogtastic.com:www.ogtastic.com.git"
|
142
|
+
branch: "stable"
|
143
|
+
post_setup_script: "/home/ogc/horrible_place_for_this/prod-setup.sh"
|
144
|
+
post_deploy_script: "bin/post-deploy.sh"
|
145
|
+
rake_env:
|
146
|
+
RAILS_ENV: 'production'
|
147
|
+
|
148
|
+
The post\_deploy\_script will be run from /var/www/www.ogtastic.com/bin/post-deploy.sh on the
|
149
|
+
target system.
|
150
|
+
|
151
|
+
|
117
152
|
|
118
153
|
### Running via rake ###
|
119
154
|
|
@@ -150,7 +185,7 @@ The --path argument can take either a file or a directory. When given a file it
|
|
150
185
|
All this means you can manage a large number of project deployments (local or remote) and have a single scripted deployment manager that keeps them up to date. Configurations can live in a centralized location, and developers don't have to be actively involved in ensuring code gets shipped up to a server. Win.
|
151
186
|
|
152
187
|
|
153
|
-
### A note about post\
|
188
|
+
### A note about post\_{setup,deploy} Rake tasks
|
154
189
|
|
155
190
|
If you want actions to run on the deployment target after you do a whiskey\_disk setup or whiskey\_disk deploy,
|
156
191
|
you will need to make sure that whiskey\_disk is available on the target system (either by gem installation,
|
data/Rakefile
CHANGED
@@ -5,10 +5,9 @@ desc 'Default: run unit tests.'
|
|
5
5
|
task :default => :test
|
6
6
|
|
7
7
|
desc 'Test RubyCloud'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
t.verbose = true
|
8
|
+
task :test do
|
9
|
+
files = Dir['spec/**/*_spec.rb'].join(" ")
|
10
|
+
system("bacon #{files}")
|
12
11
|
end
|
13
12
|
|
14
13
|
begin
|
data/TODO.txt
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
- make sure that deployments don't require ruby or rake on the target machine
|
2
|
+
- we should probably do --depth 1 on setup, for even fastertude
|
3
|
+
- support 'check=yes' as a wd --check flag
|
4
|
+
- if someone specifies :project in a config repo block in a localized config (say a RAILS app), then use that for determining which project to use when loading the config repo
|
5
|
+
|
6
|
+
- batch deployments (--batch=/etc/deploy/hourly.yml)
|
7
|
+
- could have this simply pointing to a single yaml file with project name, target name, check value (default = true) (business value: only need one command, or one cron, to manage all of these)
|
8
|
+
- could be a directory of individual yaml files with that information in each of them (representing one project, one target) (business value: puppet/chef could more easily manage directories of files)
|
9
|
+
- trying to avoid re-using the deploy.yml because we may want to not auto-deploy all things that we have configurations for, or we may want to auto-deploy them at different frequencies
|
10
|
+
- do we want the config path to be in the meta file, or do we want that to come as part of the arguments to the deployment?
|
11
|
+
|
12
|
+
wd deploy --batch=/etc/deploy/hourly.yml --path=/etc/deploy/projects/
|
13
|
+
wd deploy --batch=/etc/deploy/hourly/ --path=/etc/deploy/projects/
|
14
|
+
wd deploy --batch=/etc/deploy/hourly.yml --path=/etc/deploy/deploy.yml
|
15
|
+
wd deploy --batch=/etc/deploy/hourly --path=/etc/deploy/projects/deploy.yml
|
16
|
+
|
1
17
|
- allow whiskey_disk to pull configuration file from an url (which would be based on project, environment)
|
2
18
|
|
3
19
|
- do git-deploy style change detection:
|
@@ -16,19 +32,6 @@
|
|
16
32
|
end
|
17
33
|
end
|
18
34
|
|
19
|
-
---
|
20
|
-
|
21
|
-
- [Q] how to specify readily which projects need to be deployed? Metaconfig?:
|
22
|
-
|
23
|
-
---
|
24
|
-
- config: /path/to/config
|
25
|
-
project: larry
|
26
|
-
target: staging
|
27
|
-
- config: /path/to/config
|
28
|
-
project: larry
|
29
|
-
target: production
|
30
|
-
cache: no
|
31
|
-
|
32
35
|
- [Q] what about maintenance pages(?) (i.e., do we need a pre-deploy hook?; also are these per-target config stuffs?; fun managing changes to a maintenance page ;-)
|
33
36
|
- [Q] do we want a mechanism to manage the config repo? (add a repo, add a project, add an environment, put a file into the config repo for an environment?)
|
34
37
|
- [Q] what about per-target rake tasks, do we just store these in the config repo? does this work?
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/whiskey_disk.rb
CHANGED
@@ -140,6 +140,17 @@ class WhiskeyDisk
|
|
140
140
|
if_task_defined(task_name, "#{env_vars} rake --trace #{task_name} to=#{self[:environment]}")))
|
141
141
|
end
|
142
142
|
|
143
|
+
def build_path(path)
|
144
|
+
return path if path =~ %r{^/}
|
145
|
+
File.join(self[:deploy_to], path)
|
146
|
+
end
|
147
|
+
|
148
|
+
def run_script(script)
|
149
|
+
return unless script
|
150
|
+
path = build_path(script)
|
151
|
+
enqueue("if [ -e #{path} ]; then sh -x #{path}; fi ")
|
152
|
+
end
|
153
|
+
|
143
154
|
def ensure_main_parent_path_is_present
|
144
155
|
needs(:deploy_to)
|
145
156
|
enqueue "mkdir -p #{parent_path(self[:deploy_to])}"
|
@@ -178,11 +189,13 @@ class WhiskeyDisk
|
|
178
189
|
|
179
190
|
def run_post_setup_hooks
|
180
191
|
needs(:deploy_to)
|
192
|
+
run_script(self[:post_setup_script])
|
181
193
|
run_rake_task(self[:deploy_to], "deploy:post_setup")
|
182
194
|
end
|
183
|
-
|
195
|
+
|
184
196
|
def run_post_deploy_hooks
|
185
197
|
needs(:deploy_to)
|
198
|
+
run_script(self[:post_deploy_script])
|
186
199
|
run_rake_task(self[:deploy_to], "deploy:post_deploy")
|
187
200
|
end
|
188
201
|
end
|
data/spec/whiskey_disk_spec.rb
CHANGED
@@ -357,11 +357,76 @@ describe 'WhiskeyDisk' do
|
|
357
357
|
WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/main/repo})
|
358
358
|
end
|
359
359
|
|
360
|
+
describe 'when a post setup script is specified' do
|
361
|
+
describe 'and the script path does not start with a "/"' do
|
362
|
+
before do
|
363
|
+
@parameters = { 'deploy_to' => '/path/to/main/repo',
|
364
|
+
'post_setup_script' => '/path/to/setup/script' }
|
365
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
366
|
+
WhiskeyDisk.reset
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'should attempt to run the post setup script' do
|
370
|
+
WhiskeyDisk.run_post_setup_hooks
|
371
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x .*/path/to/setup/script})
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'should use an absolute path to run the post setup script when the script path starts with a "/"' do
|
375
|
+
WhiskeyDisk.run_post_setup_hooks
|
376
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x /path/to/setup/script})
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'should make the post setup script run conditional on the presence of the script' do
|
380
|
+
WhiskeyDisk.run_post_setup_hooks
|
381
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[ -e /path/to/setup/script \]; then .*; fi})
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
describe 'and the script path does not start with a "/"' do
|
386
|
+
before do
|
387
|
+
@parameters = { 'deploy_to' => '/path/to/main/repo',
|
388
|
+
'post_setup_script' => 'path/to/setup/script' }
|
389
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
390
|
+
WhiskeyDisk.reset
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'should attempt to run the post setup script' do
|
394
|
+
WhiskeyDisk.run_post_setup_hooks
|
395
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x .*/path/to/setup/script})
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should use a path relative to the setupment path to run the post setup script' do
|
399
|
+
WhiskeyDisk.run_post_setup_hooks
|
400
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x /path/to/main/repo/path/to/setup/script})
|
401
|
+
end
|
402
|
+
|
403
|
+
it 'should make the post setup script run conditional on the presence of the script' do
|
404
|
+
WhiskeyDisk.run_post_setup_hooks
|
405
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[ -e /path/to/main/repo/path/to/setup/script \]; then .*; fi})
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
it 'should attempt to run the post setup rake tasks' do
|
411
|
+
WhiskeyDisk.run_post_setup_hooks
|
412
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{rake.*deploy:post_setup})
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'should use the same environment when running the rake tasks' do
|
416
|
+
WhiskeyDisk.run_post_setup_hooks
|
417
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{to=#{@env}})
|
418
|
+
end
|
419
|
+
|
360
420
|
it 'should make the post setup rake tasks conditional on the presence of a Rakefile in the deployment path' do
|
361
421
|
WhiskeyDisk.run_post_setup_hooks
|
362
422
|
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[ -e /path/to/main/repo/Rakefile \]; then .*; fi})
|
363
423
|
end
|
364
424
|
|
425
|
+
it 'should make the post setup rake tasks conditional on the deploy:post_setup rake task being defined' do
|
426
|
+
WhiskeyDisk.run_post_setup_hooks
|
427
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[\[ \`rake -P | grep deploy:post_setup\` != "" \]\]; })
|
428
|
+
end
|
429
|
+
|
365
430
|
it 'should ensure that any rake ENV variable are set when checking for deploy:post_setup tasks' do
|
366
431
|
@parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_env' => { 'RAILS_ENV' => 'production', 'FOO' => 'bar' } }
|
367
432
|
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
@@ -372,21 +437,6 @@ describe 'WhiskeyDisk' do
|
|
372
437
|
end
|
373
438
|
end
|
374
439
|
|
375
|
-
it 'should make the post setup rake tasks conditional on the deploy:post_setup rake task being defined' do
|
376
|
-
WhiskeyDisk.run_post_setup_hooks
|
377
|
-
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[\[ \`rake -P | grep deploy:post_setup\` != "" \]\]; })
|
378
|
-
end
|
379
|
-
|
380
|
-
it 'should attempt to run the post setup rake tasks' do
|
381
|
-
WhiskeyDisk.run_post_setup_hooks
|
382
|
-
WhiskeyDisk.buffer.join(' ').should.match(%r{rake.*deploy:post_setup})
|
383
|
-
end
|
384
|
-
|
385
|
-
it 'should use the same environment when running the rake tasks' do
|
386
|
-
WhiskeyDisk.run_post_setup_hooks
|
387
|
-
WhiskeyDisk.buffer.join(' ').should.match(%r{to=#{@env}})
|
388
|
-
end
|
389
|
-
|
390
440
|
it 'should set any rake_env variables when running the rake tasks' do
|
391
441
|
@parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_env' => { 'RAILS_ENV' => 'production', 'FOO' => 'bar' } }
|
392
442
|
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
@@ -416,16 +466,66 @@ describe 'WhiskeyDisk' do
|
|
416
466
|
WhiskeyDisk.buffer.join(' ').should.match(%r{cd /path/to/main/repo})
|
417
467
|
end
|
418
468
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
469
|
+
describe 'when a post deployment script is specified' do
|
470
|
+
describe 'and the script path does not start with a "/"' do
|
471
|
+
before do
|
472
|
+
@parameters = { 'deploy_to' => '/path/to/main/repo',
|
473
|
+
'post_deploy_script' => '/path/to/deployment/script' }
|
474
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
475
|
+
WhiskeyDisk.reset
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'should attempt to run the post deployment script' do
|
479
|
+
WhiskeyDisk.run_post_deploy_hooks
|
480
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x .*/path/to/deployment/script})
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'should use an absolute path to run the post deployment script when the script path starts with a "/"' do
|
484
|
+
WhiskeyDisk.run_post_deploy_hooks
|
485
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x /path/to/deployment/script})
|
486
|
+
end
|
487
|
+
|
488
|
+
it 'should make the post deployment script run conditional on the presence of the script' do
|
489
|
+
WhiskeyDisk.run_post_deploy_hooks
|
490
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[ -e /path/to/deployment/script \]; then .*; fi})
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
describe 'and the script path does not start with a "/"' do
|
495
|
+
before do
|
496
|
+
@parameters = { 'deploy_to' => '/path/to/main/repo',
|
497
|
+
'post_deploy_script' => 'path/to/deployment/script' }
|
498
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
499
|
+
WhiskeyDisk.reset
|
500
|
+
end
|
501
|
+
|
502
|
+
it 'should attempt to run the post deployment script' do
|
503
|
+
WhiskeyDisk.run_post_deploy_hooks
|
504
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x .*/path/to/deployment/script})
|
505
|
+
end
|
506
|
+
|
507
|
+
it 'should use a path relative to the deployment path to run the post deployment script' do
|
508
|
+
WhiskeyDisk.run_post_deploy_hooks
|
509
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{sh -x /path/to/main/repo/path/to/deployment/script})
|
510
|
+
end
|
511
|
+
|
512
|
+
it 'should make the post deployment script run conditional on the presence of the script' do
|
513
|
+
WhiskeyDisk.run_post_deploy_hooks
|
514
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[ -e /path/to/main/repo/path/to/deployment/script \]; then .*; fi})
|
515
|
+
end
|
426
516
|
end
|
427
517
|
end
|
518
|
+
|
519
|
+
it 'should attempt to run the post deployment rake tasks' do
|
520
|
+
WhiskeyDisk.run_post_deploy_hooks
|
521
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{rake.*deploy:post_deploy})
|
522
|
+
end
|
428
523
|
|
524
|
+
it 'should use the same environment when running the rake tasks' do
|
525
|
+
WhiskeyDisk.run_post_deploy_hooks
|
526
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{to=#{@env}})
|
527
|
+
end
|
528
|
+
|
429
529
|
it 'should make the post deployment rake tasks conditional on the presence of a Rakefile in the deployment path' do
|
430
530
|
WhiskeyDisk.run_post_deploy_hooks
|
431
531
|
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[ -e /path/to/main/repo/Rakefile \]; then .*; fi})
|
@@ -435,15 +535,15 @@ describe 'WhiskeyDisk' do
|
|
435
535
|
WhiskeyDisk.run_post_deploy_hooks
|
436
536
|
WhiskeyDisk.buffer.join(' ').should.match(%r{if \[\[ \`rake -P | grep deploy:post_deploy\` != "" \]\]; })
|
437
537
|
end
|
438
|
-
|
439
|
-
it 'should
|
440
|
-
|
441
|
-
WhiskeyDisk.
|
442
|
-
|
443
|
-
|
444
|
-
it 'should use the same environment when running the rake tasks' do
|
538
|
+
|
539
|
+
it 'should ensure that any rake ENV variable are set when checking for deploy:post_setup tasks' do
|
540
|
+
@parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_env' => { 'RAILS_ENV' => 'production', 'FOO' => 'bar' } }
|
541
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@parameters)
|
542
|
+
WhiskeyDisk.reset
|
445
543
|
WhiskeyDisk.run_post_deploy_hooks
|
446
|
-
|
544
|
+
@parameters['rake_env'].each_pair do |k,v|
|
545
|
+
WhiskeyDisk.buffer.join(' ').should.match(%r{#{k}='#{v}' .*rake -P})
|
546
|
+
end
|
447
547
|
end
|
448
548
|
|
449
549
|
it 'should set any rake_env variables when running the rake tasks' do
|
data/whiskey_disk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{whiskey_disk}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rick Bradley"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-06}
|
13
13
|
s.default_executable = %q{wd}
|
14
14
|
s.description = %q{Opinionated gem for doing fast git-based server deployments.}
|
15
15
|
s.email = %q{rick@rickbradley.com}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whiskey_disk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 4
|
9
8
|
- 5
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rick Bradley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-06 00:00:00 -05:00
|
19
19
|
default_executable: wd
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|