Skip to content

Instantly share code, notes, and snippets.

@michaeldwan
Created July 4, 2010 02:08
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save michaeldwan/463024 to your computer and use it in GitHub Desktop.
Save michaeldwan/463024 to your computer and use it in GitHub Desktop.
Simple Rake task for customizing deployment to Heroku
# List of environments and their heroku git remotes
ENVIRONMENTS = {
:staging => 'myapp-staging',
:production => 'myapp-production'
}
namespace :deploy do
ENVIRONMENTS.keys.each do |env|
desc "Deploy to #{env}"
task env do
current_branch = `git branch | grep ^* | awk '{ print $2 }'`.strip
Rake::Task['deploy:before_deploy'].invoke(env, current_branch)
Rake::Task['deploy:update_code'].invoke(env, current_branch)
Rake::Task['deploy:after_deploy'].invoke(env, current_branch)
end
end
task :before_deploy, :env, :branch do |t, args|
puts "Deploying #{args[:branch]} to #{args[:env]}"
# Ensure the user wants to deploy a non-master branch to production
if args[:env] == :production && args[:branch] != 'master'
print "Are you sure you want to deploy '#{args[:branch]}' to production? (y/n) " and STDOUT.flush
char = $stdin.getc
if char != ?y && char != ?Y
puts "Deploy aborted"
exit
end
end
end
task :after_deploy, :env, :branch do |t, args|
puts "Deployment Complete"
end
task :update_code, :env, :branch do |t, args|
FileUtils.cd Rails.root do
puts "Updating #{ENVIRONMENTS[args[:env]]} with branch #{args[:branch]}"
`git push #{ENVIRONMENTS[args[:env]]} +#{args[:branch]}:master`
end
end
end
@knightq
Copy link

knightq commented May 25, 2016

It no longer works :,-(

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