Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Capistrano "push strategy", take 2
- #
- # It's based on "remote_cache", but doesn't rely on a central git repository.
- # It assumes that the code is already pushed to its "cached-copy".
- #
- # Usage:
- #
- # git remote add origin example.com:/path/to/my-app/shared/cached-copy/.git
- # cap deploy
- #
- # (If you want to call the remote something other than "origin", remember to
- # tweak the "remote" setting in the recipe below.)
- # set up these:
- set :application, "my-app"
- set :use_sudo, false
- # tweak the following if you wish:
- set :remote, 'origin'
- set :branch, 'master'
- set :git_enable_submodules, true
- # deduces the deploy host and directory from your push target
- remote_host, remote_path = `git config remote.#{remote}.url`.chomp.split(':', 2)
- set :deploy_to, remote_path.split('/shared/cached-copy/').first
- server remote_host, :app, :web, :db, :primary => true
- # DON'T change these:
- set :repository, ".git"
- set :scm, :git
- set :deploy_via, :remote_cache
- set(:source) { GitLocal.new(self) }
- # hook to automatically push code before every deploy
- before 'deploy:update_code' do
- puts "Pushing #{branch} code to git repository ..."
- system "git push #{remote} #{branch}"
- abort unless $?.success?
- end
- #===============================#
- # Rest of your recipe goes here #
- #===============================#
- # at the end, a little magic to make it all happen
- require 'capistrano/recipes/deploy/scm/git'
- class GitLocal < ::Capistrano::Deploy::SCM::Git
- default_command "git"
- def checkout(revision, destination)
- %(echo 'ABORTED: you must first initialize the git repository in "#{destination}"' && exit 1)
- end
- def sync(revision, destination)
- git = command
- execute = ["cd #{destination}"]
- # since we're in a local branch already, just reset to specified revision rather than merge
- execute << "#{git} reset --hard #{revision}"
- if configuration[:git_enable_submodules]
- execute << "#{git} submodule #{verbose} init"
- execute << "#{git} submodule #{verbose} update"
- end
- execute.join(" && ")
- end
- end
Add Comment
Please, Sign In to add comment