Skip to content

Instantly share code, notes, and snippets.

@Sutto
Created January 16, 2010 08:40
Show Gist options
  • Save Sutto/278739 to your computer and use it in GitHub Desktop.
Save Sutto/278739 to your computer and use it in GitHub Desktop.
Super Simple Git, Bundler and Unicorn deploys
namespace :deploy do
def config(key)
(@config ||= YAML.load_file("config/deploy.yml").symbolize_keys)[key.to_sym]
end
# Hooks as needed
task :local_before do
end
task :local_after do
end
task :remote_before do
end
task :remote_after do
end
# Actual deploy
desc "Runs a local deploy"
task :local do
Rake::Task["deploy:local_before"].invoke
system "gem bundle"
if File.exist?("tmp/pids/unicorn.pid")
begin
pid = File.read("tmp/pids/unicorn.pid").to_i
Process.kill(:USR2, pid)
rescue Errno::ENOENT, Errno::ESRCH
end
puts "Found pid, attempted to restart."
else
puts "Couldn't find a pid."
end
Rake::Task["deploy:local_after"].invoke
end
desc "Runs a remote deploy"
task :remote do
Rake::Task["deploy:remote_before"].invoke
system "ssh #{config(:user)}@#{config(:host)} 'cd #{config(:app)} && git pull && rake deploy:local RAILS_ENV=production'"
Rake::Task["deploy:remote_after"].invoke
end
end
task :deploy => "deploy:remote"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment