Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to deploy when bundled version of Rake does not match installed version #31

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions lib/whiskey_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions spec/whiskey_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down