Guest User

Untitled

a guest
Jul 17th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. require 'lib/ssh_recipes'
  2.  
  3. class DeployApplication < SSHRecipes::Recipe
  4.  
  5. private
  6.  
  7. def execute!
  8. release = Time.now.utc.strftime("%Y%m%d%H%M%S")
  9. puts "Release is: #{release}"
  10.  
  11. ## create the structure if it doesn't exist yet
  12. #remove_directory(self.options[:path])
  13. unless file_exist?(self.options[:path])
  14.  
  15. ## create directories
  16. %w{ releases shared shared/log shared/configs shared/tmp }.each do |dir|
  17. make_directory(File.join(self.options[:path], dir))
  18. end
  19.  
  20. ## add a known host for the codebase server
  21. puts "Adding known host for the Codebase server (if appropriate)..."
  22. add_known_host "gitbase.com", "94.76.230.38", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqafgFtYVquYfReJa3MGIyGz0RZoc1kfnXHFDjprY4Uy0lwia+35rRa9Aycrf4eySa55JXsg7rOosqpNOi2hSFWHQ/FfKzMH077Vu1X6d5gNBzxR3aJq/zaAJSiRbrUM20NgEHzBiT8x+32zM71E4qjKnGG8AdEqV9AmROXHWddLSs3e5Tsr2+Dkc/lu+Ko4eVjFjW3ZUgTRE3VTd+PDSRGOfmimgBpcuhkBbEyK4+dq7NJKxLbUl9zC7jKPddkWpbonR9CYWj+c8R8MimKLhhSilNRUKuQBNYydol3eX8VNi+PTzAYtB/w8/jl3+BWzj6xAyfMRdeJDyhhTYX+/s+w=="
  23.  
  24. ## clone the repository
  25. puts "Cloning remote repository for the first time..."
  26. git_clone File.join(self.options[:path], 'repository'), self.options[:repository]
  27. else
  28. puts "Fetching latest repository to remote cached copy..."
  29. git_fetch File.join(self.options[:path], 'repository')
  30. end
  31.  
  32. ## checkout a copy...
  33. puts "Cloning from remote cache..."
  34. git_clone File.join(self.options[:path], 'releases', release), File.join(self.options[:path], 'repository')
  35. puts "Checking out..."
  36. git_checkout File.join(self.options[:path], 'releases', release), 'deploy', '3d9d9c2e0f3f31082aecc9594debedc5cf567655'
  37.  
  38. ## symlink
  39. current_path = File.join(self.options[:path], 'current')
  40. remove(current_path, true)
  41. puts "Symlinking to #{current_path}..."
  42. symlink(File.join(self.options[:path], 'releases', release), current_path)
  43.  
  44. ## TODO: cleanup after itself...
  45. end
  46.  
  47. end
  48.  
  49. server = SSHRecipes::Server.new('router.atechmedia.lan', 'adam')
  50. deployment = DeployApplication.new(server, :path => "/home/adam/deploytest", :repository => "git@gitbase.com:atech/ssh-recipes/lib")
  51.  
  52.  
  53. begin
  54. deployment.perform!
  55. puts deployment.full_output
  56. rescue SSHRecipes::Error => e
  57. puts e.inspect
  58. end
Add Comment
Please, Sign In to add comment