Class: Capistrano::GitCopy::Utility
- Inherits:
-
Object
- Object
- Capistrano::GitCopy::Utility
- Defined in:
- lib/capistrano/git_copy/utility.rb
Overview
Utility stuff to avoid cluttering of deploy.cap
Instance Method Summary collapse
-
#archive_path ⇒ String
Path to archive.
-
#check ⇒ Object
Check if repo is accessible.
-
#cleanup ⇒ Object
Cleanup repo cache.
-
#clone ⇒ Object
Clone repo to cache.
-
#fetch_revision ⇒ Object
Set deployed revision.
-
#initialize(context) ⇒ Utility
constructor
A new instance of Utility.
-
#prepare_release ⇒ Object
Create tar archive.
-
#release ⇒ Object
Upload and extract release.
-
#repo_path ⇒ String
Path to repo cache.
-
#test ⇒ Boolean
Check if repo cache exists.
-
#tmp_path ⇒ String
Temporary path for all git-copy operations.
-
#update ⇒ Object
Update repo and submodules to branch.
Constructor Details
#initialize(context) ⇒ Utility
Returns a new instance of Utility.
8 9 10 |
# File 'lib/capistrano/git_copy/utility.rb', line 8 def initialize(context) @context = context end |
Instance Method Details
#archive_path ⇒ String
Path to archive
105 106 107 |
# File 'lib/capistrano/git_copy/utility.rb', line 105 def archive_path @_archive_path ||= File.join(tmp_path, 'archive.tar.gz') end |
#check ⇒ Object
Check if repo is accessible
22 23 24 |
# File 'lib/capistrano/git_copy/utility.rb', line 22 def check git :'ls-remote --heads', repo_url end |
#cleanup ⇒ Object
Cleanup repo cache
82 83 84 85 86 |
# File 'lib/capistrano/git_copy/utility.rb', line 82 def cleanup execute :rm, '-rf', tmp_path info 'Local repo cache was removed' end |
#clone ⇒ Object
Clone repo to cache
29 30 31 32 33 |
# File 'lib/capistrano/git_copy/utility.rb', line 29 def clone execute :mkdir, '-p', tmp_path git :clone, fetch(:repo_url), repo_path end |
#fetch_revision ⇒ Object
Set deployed revision
75 76 77 |
# File 'lib/capistrano/git_copy/utility.rb', line 75 def fetch_revision capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', fetch(:branch)).strip end |
#prepare_release ⇒ Object
Create tar archive
55 56 57 |
# File 'lib/capistrano/git_copy/utility.rb', line 55 def prepare_release execute git_archive_all_bin, "--prefix=''", archive_path end |
#release ⇒ Object
Upload and extract release
62 63 64 65 66 67 68 69 70 |
# File 'lib/capistrano/git_copy/utility.rb', line 62 def release remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path)) upload! archive_path, remote_archive_path execute :mkdir, '-p', release_path execute :tar, '-f', remote_archive_path, '-x', '-C', release_path execute :rm, '-f', remote_archive_path end |
#repo_path ⇒ String
Path to repo cache
98 99 100 |
# File 'lib/capistrano/git_copy/utility.rb', line 98 def repo_path @_repo_path ||= File.join(tmp_path, 'repo') end |
#test ⇒ Boolean
Check if repo cache exists
15 16 17 |
# File 'lib/capistrano/git_copy/utility.rb', line 15 def test test! " [ -d #{repo_path} ] " end |
#tmp_path ⇒ String
Temporary path for all git-copy operations
91 92 93 |
# File 'lib/capistrano/git_copy/utility.rb', line 91 def tmp_path @_tmp_path ||= File.join(Dir.tmpdir, deploy_id) end |
#update ⇒ Object
Update repo and submodules to branch
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/capistrano/git_copy/utility.rb', line 38 def update git :remote, :update git :reset, '--hard', commit_hash # submodules git :submodule, :init git :submodule, :update git :submodule, :foreach, '--recursive', :git, :submodule, :update, '--init' # cleanup git :clean, '-d', '-f' git :submodule, :foreach, '--recursive', :git, :clean, '-d', '-f' end |