Guest User

Untitled

a guest
Sep 21st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. require 'net/ssh'
  2.  
  3. @ssh_user = "your_username"
  4. @ssh_pass = "your_password"
  5. @ssh_port = your_port
  6.  
  7. @stage_ssh = "dev.server.com"
  8. @stage_path = "/path/to/staging/root/"
  9.  
  10. @prod_ssh = "server.com"
  11. @prod_path = "/path/to/prod/server/root/"
  12.  
  13. namespace :deploy do
  14. desc "Deploy to stage."
  15. task :stage do
  16. puts "Deploying to stage via git pull on #{@stage_ssh}."
  17. puts "Creating SSH connection..."
  18. Net::SSH.start( @stage_ssh,
  19. @ssh_user,
  20. {:port => @ssh_port,
  21. :password => @ssh_pass}
  22. ) do |ssh|
  23. puts "SSH Connected, fetching git head"
  24. output = ssh.exec!("cd #{@stage_path} && git pull origin master")
  25. puts output
  26. end
  27. end
  28. desc "Deploy to production."
  29. task :prod do
  30. puts "Deploying to stage via git pull on #{@prod_ssh}."
  31. Net::SSH.start( @prod_ssh,
  32. @ssh_user,
  33. {:port => @ssh_port,
  34. :password => @ssh_pass}
  35. ) do |ssh|
  36. puts "SSH Connected, fetching git head"
  37. output = ssh.exec!("cd #{@prod_path} && git pull origin master")
  38. puts output
  39. end
  40. end
  41. end
  42.  
  43.  
  44. namespace :rollback do
  45. desc "Roll back staging."
  46. task :stage do
  47. puts "Rolling back on staging."
  48. puts "Creating SSH connection..."
  49. Net::SSH.start( @stage_ssh,
  50. @ssh_user,
  51. {:port => 8022,
  52. :password => @ssh_pass}
  53. ) do |ssh|
  54. puts "SSH Connected, fetching git head"
  55. output = ssh.exec!("cd #{@stage_path} && git revert HEAD")
  56. puts output
  57. end
  58. end
  59. desc "Roll back production."
  60. task :prod do
  61. puts "Rolling back on production."
  62. Net::SSH.start( @prod_ssh,
  63. @ssh_user,
  64. {:port => 8022,
  65. :password => @ssh_pass}
  66. ) do |ssh|
  67. puts "SSH Connected, fetching git head"
  68. output = ssh.exec!("cd #{@prod_path} && git revert HEAD")
  69. puts output
  70. end
  71. end
  72. end
  73.  
  74. # Set default task
  75. desc "Deploy to stage."
  76. task :deploy => "deploy:stage"
Add Comment
Please, Sign In to add comment