thoughtbot/suspenders — Issue #67: Heroku deploy script
Author: croaky
Created: 2011-12-04 21:09:36+00:00
State: open

I expect this in the README of all our latest Heroku apps:

Deploying
---------

To deploy to staging:

bake deploy:staging

Staging deploys are aliased for convenience:

bake deploy

To deploy to production:

bake deploy:production

Using these commands are important because they will compile the asset pipeline.

To make that functional out of the box, we could include Kumade or this script:

require 'rake'

task :deploy => "deploy:staging"

namespace :deploy do
desc "Deploy to Heroku staging"
task :staging do
Deployer.new("staging").deploy
end

desc "Deploy to Heroku production"
task :production do
Deployer.new("production").deploy
end
end

class Deployer
attr_reader :branch

def initialize(environment)
@environment = environment
end

def deploy
push_heroku
migrate
notify_airbrake
if production?
notify_copycopter
end
restart
end

private

def push_heroku
run "git push #{@environment} master -f"
end

def migrate
run "bundle exec heroku run rake db:migrate --remote #{@environment}"
end

def notify_copycopter
run "bundle exec rake copycopter:deploy"
end

def notify_airbrake
run "bundle exec rake airbrake:deploy TO=#{@environment}"
end

def restart
run "bundle exec heroku restart --remote #{@environment}"
end

def production?
@environment == "production"
end

def run(command)
puts " #{command}"
%x{#{command}}
end
end