Class: Capistrano::GitCopy::SCM
- Inherits:
-
SCM::Plugin
- Object
- SCM::Plugin
- Capistrano::GitCopy::SCM
- Includes:
- SCMHelpers
- 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
136 137 138 |
# File 'lib/capistrano/git_copy/scm.rb', line 136 def archive_path @archive_path ||= File.join(tmp_path, 'archive.tar.gz') end |
#check ⇒ Object
Check if repository is accessible
37 38 39 |
# File 'lib/capistrano/git_copy/scm.rb', line 37 def check git(:'ls-remote --heads', repo_url) end |
#cleanup ⇒ Object
Cleanup repo cache
113 114 115 116 117 |
# File 'lib/capistrano/git_copy/scm.rb', line 113 def cleanup backend.execute(:rm, '-rf', tmp_path) backend.info('Local repo cache was removed') end |
#clone ⇒ Object
Clone repo to cache
55 56 57 58 59 |
# File 'lib/capistrano/git_copy/scm.rb', line 55 def clone backend.execute(:mkdir, '-p', tmp_path) git(:clone, fetch(:repo_url), repo_cache_path) end |
#define_tasks ⇒ Object
define plugin tasks
23 24 25 |
# File 'lib/capistrano/git_copy/scm.rb', line 23 def define_tasks eval_rakefile File.('tasks/git_copy.rake', __dir__) end |
#fetch_revision ⇒ Object
Set deployed revision
106 107 108 |
# File 'lib/capistrano/git_copy/scm.rb', line 106 def fetch_revision backend.capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', commit_hash).strip end |
#prepare_release ⇒ Object
Create tar archive
84 85 86 87 88 |
# File 'lib/capistrano/git_copy/scm.rb', line 84 def prepare_release package_release_archive exclude_files_from_archive if fetch(:git_excludes, []).length.positive? end |
#register_hooks ⇒ Object
register capistrano hooks
28 29 30 31 32 |
# File 'lib/capistrano/git_copy/scm.rb', line 28 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
93 94 95 96 97 98 99 100 101 |
# File 'lib/capistrano/git_copy/scm.rb', line 93 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) extract_archive_on_remote(remote_archive_path) end |
#repo_cache_path ⇒ String
Path to repository cache
129 130 131 |
# File 'lib/capistrano/git_copy/scm.rb', line 129 def repo_cache_path @repo_cache_path ||= fetch(:git_repo_cach_path, File.join(tmp_path, 'repo')) end |
#set_defaults ⇒ Object
set default values
15 16 17 18 19 20 |
# File 'lib/capistrano/git_copy/scm.rb', line 15 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
44 45 46 47 48 49 50 |
# File 'lib/capistrano/git_copy/scm.rb', line 44 def test if backend.test("[ -d #{repo_cache_path} ]") check_repo_cache_path else false end end |
#tmp_path ⇒ String
Temporary path for all git-copy operations
122 123 124 |
# File 'lib/capistrano/git_copy/scm.rb', line 122 def tmp_path @tmp_path ||= File.join(Dir.tmpdir, deploy_id) end |
#update ⇒ Object
Update repo and submodules to branch
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/capistrano/git_copy/scm.rb', line 64 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 git(:clean, '-d', '-f') if fetch(:with_clean) git(:submodule, :foreach, '--recursive', :git, :clean, '-d', '-f') if fetch(:with_submodules) end |