Skip to content

Commit

Permalink
Use sh instead of custom system_with_echo.
Browse files Browse the repository at this point in the history
sh will fail rake when it fails.
  • Loading branch information
Peter Jaros committed Nov 4, 2010
1 parent d8787c7 commit b351bbf
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions lib/heroku_san/tasks.rb
Expand Up @@ -24,7 +24,7 @@
desc "Creates the Heroku app"
task :create do
each_heroku_app do |name, app, repo|
system_with_echo "heroku create #{app}"
sh "heroku create #{app}"
end
end

Expand Down Expand Up @@ -58,7 +58,7 @@
$stdout.flush
email = $stdin.gets
each_heroku_app do |name, app, repo|
system_with_echo "heroku sharing:add --app #{app} #{email}"
sh "heroku sharing:add --app #{app} #{email}"
end
end

Expand All @@ -68,7 +68,7 @@
$stdout.flush
email = $stdin.gets
each_heroku_app do |name, app, repo|
system_with_echo "heroku sharing:remove --app #{app} #{email}"
sh "heroku sharing:remove --app #{app} #{email}"
end
end

Expand All @@ -88,7 +88,7 @@
puts command
config = Hash[`#{command}`.scan(/^(.+?)\s*=>\s*(.+)$/)]
if config['RACK_ENV'] != name
system_with_echo "heroku config:add --app #{app} RACK_ENV=#{name}"
sh "heroku config:add --app #{app} RACK_ENV=#{name}"
end
end
end
Expand All @@ -101,27 +101,29 @@
else
puts "Copied example config to config/heroku.yml"
FileUtils.cp(example, HEROKU_CONFIG_FILE)
system_with_echo("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
sh("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
end
end

desc 'Runs a rake task remotely'
task :rake, :task do |t, args|
each_heroku_app do |name, app, repo|
system_with_echo "heroku rake --app #{app} #{args[:task]}"
sh "heroku rake --app #{app} #{args[:task]}"
end
end
end

desc "Deploys the given commit, migrates and restarts (default: HEAD)"
task :deploy, :commit, :needs => :before_deploy do |t, args|
args.with_defaults(:commit => "HEAD")
system_with_echo "git update-ref refs/heroku_san/deploy #{args[:commit]}"
sh "git update-ref refs/heroku_san/deploy #{args[:commit]}"
each_heroku_app do |name, app, repo|
@git_push_arguments ||= []
system_with_echo "git push #{repo} #{@git_push_arguments.join(' ')} refs/heroku_san/deploy:master && heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
sh "git push #{repo} #{@git_push_arguments.join(' ')} refs/heroku_san/deploy:master"
sh "heroku rake --app #{app} db:migrate"
sh "heroku restart --app #{app}"
end
system_with_echo "git update-ref -d refs/heroku_san/deploy"
sh "git update-ref -d refs/heroku_san/deploy"
Rake::Task[:after_deploy].execute
end

Expand Down Expand Up @@ -150,52 +152,48 @@
desc "Captures a bundle on Heroku"
task :capture do
each_heroku_app do |name, app, repo|
system_with_echo "heroku bundles:capture --app #{app}"
sh "heroku bundles:capture --app #{app}"
end
end

desc "Opens a remote console"
task :console do
each_heroku_app do |name, app, repo|
system_with_echo "heroku console --app #{app}"
sh "heroku console --app #{app}"
end
end

desc "Restarts remote servers"
task :restart do
each_heroku_app do |name, app, repo|
system_with_echo "heroku restart --app #{app}"
sh "heroku restart --app #{app}"
end
end

desc "Migrates and restarts remote servers"
task :migrate do
each_heroku_app do |name, app, repo|
system_with_echo "heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
sh "heroku rake --app #{app} db:migrate"
sh "heroku restart --app #{app}"
end
end

namespace :db do
task :pull do
each_heroku_app do |name, app, repo|
system_with_echo "heroku pgdumps:capture --app #{app}"
sh "heroku pgdumps:capture --app #{app}"
dump = `heroku pgdumps --app #{app}`.split("\n").last.split(" ").first
system_with_echo "mkdir -p #{Rails.root}/db/dumps"
sh "mkdir -p #{Rails.root}/db/dumps"
file = "#{Rails.root}/db/dumps/#{dump}.sql.gz"
url = `heroku pgdumps:url --app #{app} #{dump}`.chomp
system_with_echo "wget", url, "-O", file
system_with_echo "rake db:drop db:create"
system_with_echo "gunzip -c #{file} | #{Rails.root}/script/dbconsole"
system_with_echo "rake jobs:clear"
sh "wget", url, "-O", file
sh "rake db:drop db:create"
sh "gunzip -c #{file} | #{Rails.root}/script/dbconsole"
sh "rake jobs:clear"
end
end
end

def system_with_echo(*args)
puts args.join(' ')
system(*args)
end

def each_heroku_app
if @heroku_apps.blank? && HEROKU_SETTINGS['apps'].size == 1
app = HEROKU_SETTINGS['apps'].keys.first
Expand Down

0 comments on commit b351bbf

Please sign in to comment.