Class: Capistrano::GitCopy::SCM
- Inherits:
-
SCM::Plugin
- Object
- SCM::Plugin
- Capistrano::GitCopy::SCM
- Defined in:
- lib/capistrano/git_copy/scm.rb
Overview
SCM plugin for capistrano uses a local clone and uploads a tar archive to the server
Instance Method Summary collapse
-
#archive_path ⇒ String
Path to archive.
-
#check ⇒ Object
Check if repository is accessible.
-
#cleanup ⇒ Object
Cleanup repo cache.
-
#clone ⇒ Object
Clone repo to cache.
-
#define_tasks ⇒ Object
define plugin tasks.
-
#fetch_revision ⇒ Object
Set deployed revision.
-
#prepare_release ⇒ Object
Create tar archive.
-
#register_hooks ⇒ Object
register capistrano hooks.
-
#release ⇒ Object
Upload and extract release.
-
#repo_cache_path ⇒ String
Path to repository cache.
-
#set_defaults ⇒ Object
set default values.
-
#test ⇒ Boolean
Check if repository cache exists and is valid.
-
#tmp_path ⇒ String
Temporary path for all git-copy operations.
-
#update ⇒ Object
Update repo and submodules to branch.
Instance Method Details
#archive_path ⇒ String
Path to archive
151 152 153 |
# File 'lib/capistrano/git_copy/scm.rb', line 151 def archive_path @_archive_path ||= File.join(tmp_path, 'archive.tar.gz') end |
#check ⇒ Object
Check if repository is accessible
32 33 34 |
# File 'lib/capistrano/git_copy/scm.rb', line 32 def check git(:'ls-remote --heads', repo_url) end |
#cleanup ⇒ Object
Cleanup repo cache
128 129 130 131 132 |
# File 'lib/capistrano/git_copy/scm.rb', line 128 def cleanup backend.execute(:rm, '-rf', tmp_path) backend.info('Local repo cache was removed') end |
#clone ⇒ Object
Clone repo to cache
58 59 60 61 62 |
# File 'lib/capistrano/git_copy/scm.rb', line 58 def clone backend.execute(:mkdir, '-p', tmp_path) git(:clone, fetch(:repo_url), repo_cache_path) end |
#define_tasks ⇒ Object
define plugin tasks
18 19 20 |
# File 'lib/capistrano/git_copy/scm.rb', line 18 def define_tasks eval_rakefile File.('../tasks/git_copy.rake', __FILE__) end |
#fetch_revision ⇒ Object
Set deployed revision
121 122 123 |
# File 'lib/capistrano/git_copy/scm.rb', line 121 def fetch_revision backend.capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', commit_hash).strip end |
#prepare_release ⇒ Object
Create tar archive
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/capistrano/git_copy/scm.rb', line 91 def prepare_release if fetch(:upload_path) != '.' backend.execute(:tar, '-czf', archive_path, '-C', fetch(:upload_path), '.') elsif fetch(:with_submodules) backend.execute(git_archive_all_bin, "--prefix=''", archive_path) else git(:archive, '--format=tar', 'HEAD', '|', 'gzip', "> #{archive_path}") end exclude_files_from_archive if fetch(:git_excludes, []).count > 0 end |
#register_hooks ⇒ Object
register capistrano hooks
23 24 25 26 27 |
# File 'lib/capistrano/git_copy/scm.rb', line 23 def register_hooks after 'deploy:new_release_path', 'git_copy:create_release' before 'deploy:check', 'git_copy:check' before 'deploy:set_current_revision', 'git_copy:set_current_revision' end |
#release ⇒ Object
Upload and extract release
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/capistrano/git_copy/scm.rb', line 106 def release backend.execute :mkdir, '-p', release_path remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path)) backend.upload!(archive_path, remote_archive_path) backend.execute(:mkdir, '-p', release_path) backend.execute(:tar, '-f', remote_archive_path, '-x', '-C', release_path) backend.execute(:rm, '-f', remote_archive_path) end |
#repo_cache_path ⇒ String
Path to repository cache
144 145 146 |
# File 'lib/capistrano/git_copy/scm.rb', line 144 def repo_cache_path @_repo_cache_path ||= fetch(:git_repo_cach_path, File.join(tmp_path, 'repo')) end |
#set_defaults ⇒ Object
set default values
10 11 12 13 14 15 |
# File 'lib/capistrano/git_copy/scm.rb', line 10 def set_defaults set_if_empty :with_clean, true set_if_empty :with_submodules, true set_if_empty :git_excludes, [] set_if_empty :upload_path, '.' end |
#test ⇒ Boolean
Check if repository cache exists and is valid
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/capistrano/git_copy/scm.rb', line 39 def test if backend.test("[ -d #{repo_cache_path} ]") backend.within(repo_cache_path) do if backend.test(:git, :status, '>/dev/null 2>/dev/null') true else backend.execute(:rm, '-rf', repo_cache_path) false end end else false end end |
#tmp_path ⇒ String
Temporary path for all git-copy operations
137 138 139 |
# File 'lib/capistrano/git_copy/scm.rb', line 137 def tmp_path @_tmp_path ||= File.join(Dir.tmpdir, deploy_id) end |
#update ⇒ Object
Update repo and submodules to branch
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/capistrano/git_copy/scm.rb', line 67 def update git(:remote, :update) git(:reset, '--hard', commit_hash) # submodules if fetch(:with_submodules) git(:submodule, :init) git(:submodule, :update) git(:submodule, :foreach, '--recursive', :git, :submodule, :update, '--init') end # cleanup if fetch(:with_clean) git(:clean, '-d', '-f') end if fetch(:with_submodules) git(:submodule, :foreach, '--recursive', :git, :clean, '-d', '-f') end end |