Skip to content

Instantly share code, notes, and snippets.

@bradly
Created July 27, 2011 03:58
Show Gist options
  • Save bradly/1108644 to your computer and use it in GitHub Desktop.
Save bradly/1108644 to your computer and use it in GitHub Desktop.
Simple Rails Deployments with Net/SSH
require 'net/ssh'
desc "Deploy site to production"
task :deploy => :environment do
host = 'yourhost.com'
user = 'username'
options = {:keys => '~/.ssh/keys/yourserver.pem'}
remote_path = '/path/to/rails_app'
commands = [
"cd #{remote_path} && sudo git fetch",
"cd #{remote_path} && sudo git reset --hard origin/master",
"cd #{remote_path} && sudo bundle install",
"cd #{remote_path} && sudo touch tmp/restart.txt"
]
Net::SSH.start(host, user, options) do |ssh|
commands.each { |c| puts ssh.exec!(c) }
ssh.loop
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment