Hack: Deploying with git and rake-remote_task

This is an update to my previous post: Hack: Deploying with git, replacing the use of pure rake, for rake-remote_task.

Add the following to your Rakefile

require 'rake/remote_task'

set :domain,      ENV.fetch(PRODUCTION_HOST, "www.yourhost.com")
set :environment, ENV.fetch(RACK_ENV,        "production")

set :app_path,    "/path/to/app/install"

remote_task :deploy do
  run "set -x; cd #{app_path} && git pull && bundle"
end

remote_task :restart do
  run "set -x; cd #{app_path} && RACK_ENV=#{environment} bundle exec rake unicorn:restart --trace"
end

Then run

$ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy restart

or just

$ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy

Note -- This assumes the following:

  • You've checked out your repo on your remote host.
  • You've setup your app and it's running on your remote server.
  • You're using using Unicorn.
  • You're using Bundler.