diff --git a/README.markdown b/README.markdown index 6c98969..e55cea2 100644 --- a/README.markdown +++ b/README.markdown @@ -150,6 +150,7 @@ Known config file settings (if you're familiar with capistrano and vlad these sh post_deploy_script: path to a shell script to run after deployment post_setup_script: path to a shell script to run after setup rake_env: hash of environment variables to set when running post_setup and post_deploy rake tasks + rake_command: command to invoke rake with (default: rake) A simple config/deploy.yml might look like: diff --git a/lib/whiskey_disk.rb b/lib/whiskey_disk.rb index 5d13e1a..92abd2e 100644 --- a/lib/whiskey_disk.rb +++ b/lib/whiskey_disk.rb @@ -131,6 +131,10 @@ def encode_roles(roles) def build_command(domain, cmd) "#{'set -x; ' if debugging?}" + encode_roles(domain['roles']) + cmd end + + def rake_command + (setting(:rake_command) and setting(:rake_command) != '') ? setting(:rake_command) : 'rake' + end def run(domain, cmd) ssh(domain, cmd) @@ -202,7 +206,7 @@ def if_file_present(path, cmd) end def if_task_defined(task, cmd) - %Q(rakep=`#{env_vars} rake -P` && if [[ `echo "${rakep}" | grep #{task}` != "" ]]; then #{cmd}; fi ) + %Q(rakep=`#{env_vars} #{rake_command} -P` && if [[ `echo "${rakep}" | grep #{task}` != "" ]]; then #{cmd}; fi ) end def safe_branch_checkout(path, my_branch) @@ -226,7 +230,7 @@ def run_rake_task(path, task_name) enqueue "echo Running rake #{task_name}..." enqueue "cd #{path}" enqueue(if_file_present("#{setting(:deploy_to)}/Rakefile", - if_task_defined(task_name, "#{env_vars} rake #{'--trace' if debugging?} #{task_name} to=#{setting(:environment)}"))) + if_task_defined(task_name, "#{env_vars} #{rake_command} #{'--trace' if debugging?} #{task_name} to=#{setting(:environment)}"))) end def build_path(path) diff --git a/spec/whiskey_disk_spec.rb b/spec/whiskey_disk_spec.rb index 38d1621..f044f6c 100644 --- a/spec/whiskey_disk_spec.rb +++ b/spec/whiskey_disk_spec.rb @@ -585,6 +585,20 @@ def system(*args) @whiskey_disk.buffer.join(' ').should.match(%r{rake.*deploy:post_setup}) end + it 'runs the post setup tasks with given rake command' do + @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_command' => 'bundle exec rake' } + @whiskey_disk.configuration = @parameters + @whiskey_disk.run_post_setup_hooks + @whiskey_disk.buffer.join(' ').should.match(%r{bundle exec rake.*deploy:post_setup}) + end + + it 'runs the post setup tasks with default rake command if the rake command is empty' do + @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_command' => '' } + @whiskey_disk.configuration = @parameters + @whiskey_disk.run_post_setup_hooks + @whiskey_disk.buffer.join(' ').should.match(%r{rake.*deploy:post_setup}) + end + it 'uses the same environment when running the rake tasks' do @whiskey_disk.run_post_setup_hooks @whiskey_disk.buffer.join(' ').should.match(%r{to=#{@env}}) @@ -600,6 +614,13 @@ def system(*args) @whiskey_disk.buffer.join(' ').should.match(%r{rakep=\`.*rake -P\` && if \[\[ \`echo "\$\{rakep\}" | grep deploy:post_setup\` != "" \]\];}) end + it 'uses the given rake command when checking the existance of the deploy:post_setup task' do + @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_command' => 'bundle exec rake' } + @whiskey_disk.configuration = @parameters + @whiskey_disk.run_post_setup_hooks + @whiskey_disk.buffer.join(' ').should.match(%r{rakep=\`.*bundle exec rake -P\`}) + end + it 'ensures that any rake ENV variable are set when checking for deploy:post_setup tasks' do @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_env' => { 'RAILS_ENV' => 'production', 'FOO' => 'bar' } } @whiskey_disk.configuration = @parameters @@ -707,6 +728,20 @@ def system(*args) @whiskey_disk.run_post_deploy_hooks @whiskey_disk.buffer.join(' ').should.match(%r{rake.*deploy:post_deploy}) end + + it 'runs the post deployment tasks with given rake command' do + @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_command' => 'bundle exec rake' } + @whiskey_disk.configuration = @parameters + @whiskey_disk.run_post_deploy_hooks + @whiskey_disk.buffer.join(' ').should.match(%r{bundle exec rake.*deploy:post_deploy}) + end + + it 'runs the post deployment tasks with default rake command if the rake command is empty' do + @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_command' => '' } + @whiskey_disk.configuration = @parameters + @whiskey_disk.run_post_deploy_hooks + @whiskey_disk.buffer.join(' ').should.match(%r{rake.*deploy:post_deploy}) + end it 'uses the same environment when running the rake tasks' do @whiskey_disk.run_post_deploy_hooks @@ -723,6 +758,13 @@ def system(*args) @whiskey_disk.buffer.join(' ').should.match(%r{rakep=\`.*rake -P\` && if \[\[ \`echo "\$\{rakep\}" | grep deploy:post_deploy\` != "" \]\];}) end + it 'uses the given rake command when checking the existance of the deploy:post_deploy task' do + @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_command' => 'bundle exec rake' } + @whiskey_disk.configuration = @parameters + @whiskey_disk.run_post_deploy_hooks + @whiskey_disk.buffer.join(' ').should.match(%r{rakep=\`.*bundle exec rake -P\`}) + end + it 'ensures that any rake ENV variable are set when checking for deploy:post_setup tasks' do @parameters = { 'deploy_to' => '/path/to/main/repo', 'rake_env' => { 'RAILS_ENV' => 'production', 'FOO' => 'bar' } } @whiskey_disk.configuration = @parameters