Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/ssh'
- @ssh_user = "your_username"
- @ssh_pass = "your_password"
- @ssh_port = your_port
- @stage_ssh = "dev.server.com"
- @stage_path = "/path/to/staging/root/"
- @prod_ssh = "server.com"
- @prod_path = "/path/to/prod/server/root/"
- namespace :deploy do
- desc "Deploy to stage."
- task :stage do
- puts "Deploying to stage via git pull on #{@stage_ssh}."
- puts "Creating SSH connection..."
- Net::SSH.start( @stage_ssh,
- @ssh_user,
- {:port => @ssh_port,
- :password => @ssh_pass}
- ) do |ssh|
- puts "SSH Connected, fetching git head"
- output = ssh.exec!("cd #{@stage_path} && git pull origin master")
- puts output
- end
- end
- desc "Deploy to production."
- task :prod do
- puts "Deploying to stage via git pull on #{@prod_ssh}."
- Net::SSH.start( @prod_ssh,
- @ssh_user,
- {:port => @ssh_port,
- :password => @ssh_pass}
- ) do |ssh|
- puts "SSH Connected, fetching git head"
- output = ssh.exec!("cd #{@prod_path} && git pull origin master")
- puts output
- end
- end
- end
- namespace :rollback do
- desc "Roll back staging."
- task :stage do
- puts "Rolling back on staging."
- puts "Creating SSH connection..."
- Net::SSH.start( @stage_ssh,
- @ssh_user,
- {:port => 8022,
- :password => @ssh_pass}
- ) do |ssh|
- puts "SSH Connected, fetching git head"
- output = ssh.exec!("cd #{@stage_path} && git revert HEAD")
- puts output
- end
- end
- desc "Roll back production."
- task :prod do
- puts "Rolling back on production."
- Net::SSH.start( @prod_ssh,
- @ssh_user,
- {:port => 8022,
- :password => @ssh_pass}
- ) do |ssh|
- puts "SSH Connected, fetching git head"
- output = ssh.exec!("cd #{@prod_path} && git revert HEAD")
- puts output
- end
- end
- end
- # Set default task
- desc "Deploy to stage."
- task :deploy => "deploy:stage"
Add Comment
Please, Sign In to add comment