Guest User

Untitled

a guest
Feb 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. ## Capistrano "push strategy", take 2
  2. #
  3. # It's based on "remote_cache", but doesn't rely on a central git repository.
  4. # It assumes that the code is already pushed to its "cached-copy".
  5. #
  6. # Usage:
  7. #
  8. # git remote add origin example.com:/path/to/my-app/shared/cached-copy/.git
  9. # cap deploy
  10. #
  11. # (If you want to call the remote something other than "origin", remember to
  12. # tweak the "remote" setting in the recipe below.)
  13.  
  14.  
  15. # set up these:
  16. set :application, "my-app"
  17. set :use_sudo, false
  18.  
  19. # tweak the following if you wish:
  20. set :remote, 'origin'
  21. set :branch, 'master'
  22. set :git_enable_submodules, true
  23.  
  24. # deduces the deploy host and directory from your push target
  25. remote_host, remote_path = `git config remote.#{remote}.url`.chomp.split(':', 2)
  26.  
  27. set :deploy_to, remote_path.split('/shared/cached-copy/').first
  28. server remote_host, :app, :web, :db, :primary => true
  29.  
  30. # DON'T change these:
  31. set :repository, ".git"
  32. set :scm, :git
  33. set :deploy_via, :remote_cache
  34. set(:source) { GitLocal.new(self) }
  35.  
  36. # hook to automatically push code before every deploy
  37. before 'deploy:update_code' do
  38. puts "Pushing #{branch} code to git repository ..."
  39. system "git push #{remote} #{branch}"
  40. abort unless $?.success?
  41. end
  42.  
  43. #===============================#
  44. # Rest of your recipe goes here #
  45. #===============================#
  46.  
  47.  
  48. # at the end, a little magic to make it all happen
  49. require 'capistrano/recipes/deploy/scm/git'
  50.  
  51. class GitLocal < ::Capistrano::Deploy::SCM::Git
  52. default_command "git"
  53.  
  54. def checkout(revision, destination)
  55. %(echo 'ABORTED: you must first initialize the git repository in "#{destination}"' && exit 1)
  56. end
  57.  
  58. def sync(revision, destination)
  59. git = command
  60. execute = ["cd #{destination}"]
  61.  
  62. # since we're in a local branch already, just reset to specified revision rather than merge
  63. execute << "#{git} reset --hard #{revision}"
  64.  
  65. if configuration[:git_enable_submodules]
  66. execute << "#{git} submodule #{verbose} init"
  67. execute << "#{git} submodule #{verbose} update"
  68. end
  69.  
  70. execute.join(" && ")
  71. end
  72. end
Add Comment
Please, Sign In to add comment