Skip to content

Instantly share code, notes, and snippets.

@idyll
Forked from alloy/heroku.rake
Created February 17, 2012 21:08
Show Gist options
  • Save idyll/1855453 to your computer and use it in GitHub Desktop.
Save idyll/1855453 to your computer and use it in GitHub Desktop.
Some simple Heroku deploy rake tasks.
namespace :heroku do
namespace :deploy do
task :tag do
rev = `git rev-parse HEAD`.strip
if `git describe --contains #{rev} 2>&1`.include?('cannot describe')
version = Time.new.strftime("%Y%m%d%H%M%S")
sh "git tag -a heroku-#{version} -m 'Deploy version to Heroku: #{version}'"
sh "git push origin master"
sh "git push origin master --tags"
else
puts "[!] The current revision is already tagged, skipping tag creation."
end
end
task :no_migrations => 'heroku:deploy:tag' do
sh "git push heroku master"
sh "git push heroku master --tags"
end
desc 'Deploys *and* runs migrations (this will turn maintenance mode on)'
task :migrate => 'heroku:deploy:tag' do
Bundler.with_clean_env do
sh "heroku maintenance:on"
sh "git push heroku master"
sh "git push heroku master --tags"
sh "heroku rake db:migrate"
sh "heroku restart"
sh "heroku maintenance:off"
end
end
end
desc 'Deploys *without* running migrations'
task :deploy => 'heroku:deploy:no_migrations'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment