Skip to content

Instantly share code, notes, and snippets.

@djburdick
Created December 30, 2012 01:27
Show Gist options
  • Save djburdick/4410411 to your computer and use it in GitHub Desktop.
Save djburdick/4410411 to your computer and use it in GitHub Desktop.
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 [email protected]:#{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
@scott-coates
Copy link

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
Copy link

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