Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Heroku rake tasks for deploy and system commands. #heroku, #deploy
# Usage: rake name:task app_name
task PROD = "appname" # "task" here stubs to prevent rake errors with commandline
task STAGING = "appname-staging"
APP = ARGV[1] || PROD # default app
puts "=== APP #{APP} ==="
namespace :deploy do
task :migrations => [:push, :off, :migrate, :restart, :on]
# setup to be used with github or another repo (heroku repo is just used to deploy the code)
# must setup remote tracking to work. git push -u origin branch
task :push do
git_status = `git branch -v`
abort("local branch is out of sync with github origin. please push there first") if git_status.match(/\*[^\]]+?\[ahead|behind/s) != nil
current_branch = `git rev-parse --abbrev-ref HEAD`.chomp
current_branch += ":master" if current_branch != "master"
puts "Deploying #{current_branch} to #{APP} ..."
system("git push -f git@heroku.com:#{APP}.git #{current_branch}")
end
task :restart do
puts 'Restarting app servers ...'
system("heroku restart --app #{APP}")
end
task :migrate do
puts 'Running database migrations ...'
system("heroku run rake db:migrate --app #{APP}")
end
task :off do
puts 'Putting the app into maintenance mode ...'
system("heroku maintenance:on --app #{APP}")
end
task :on do
puts 'Taking the app out of maintenance mode ...'
system("heroku maintenance:off --app #{APP}")
end
task :rollback do
puts 'rolling back to last version'
system("heroku rollback --app #{APP}")
end
end
namespace :app do
task :logs do
puts "tailing logs..."
system("heroku logs --tail --app #{APP}")
end
task :config do
puts "config..."
system("heroku config --app #{APP}")
end
task :ps do
puts "running processes..."
system("heroku ps --app #{APP}")
end
task :releases do
puts "releases..."
system("heroku releases --app #{APP}")
end
end
@scottccoates

This comment has been minimized.

Copy link

@scottccoates scottccoates commented Feb 9, 2013

Can you explain lines 3 and 4. I don't understand what this means:

"task" here stubs to prevent rake errors with commandline

Can you provide an example on how to invoke this?

@aurelianonava

This comment has been minimized.

Copy link

@aurelianonava aurelianonava commented May 17, 2013

I'm with you scoarescoare. How you use the damn thing? :)

Sorry, but I just pushed my first heroku app a few days ago. I changed the model of the app and now when I push to heroku it doesn't work. Mierda!

Even as I do a "heroku run rake db:migrate"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment