Class: Capistrano::Git::Copy::Utility
- Inherits:
-
Object
- Object
- Capistrano::Git::Copy::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
9 10 11 |
# File 'lib/capistrano/git/copy/utility.rb', line 9 def initialize(context) @context = context end |
Instance Method Details
#archive_path ⇒ String
Path to archive
106 107 108 |
# File 'lib/capistrano/git/copy/utility.rb', line 106 def archive_path @_archive_path ||= File.join(tmp_path, 'archive.tar.gz') end |
#check ⇒ Object
Check if repo is accessible
23 24 25 |
# File 'lib/capistrano/git/copy/utility.rb', line 23 def check git :'ls-remote --heads', repo_url end |
#cleanup ⇒ Object
Cleanup repo cache
83 84 85 86 87 |
# File 'lib/capistrano/git/copy/utility.rb', line 83 def cleanup execute :rm, '-rf', tmp_path info 'Local repo cache was removed' end |
#clone ⇒ Object
Clone repo to cache
30 31 32 33 34 |
# File 'lib/capistrano/git/copy/utility.rb', line 30 def clone execute :mkdir, '-p', tmp_path git :clone, fetch(:repo_url), repo_path end |
#fetch_revision ⇒ Object
Set deployed revision
76 77 78 |
# File 'lib/capistrano/git/copy/utility.rb', line 76 def fetch_revision capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', fetch(:branch)).strip end |
#prepare_release ⇒ Object
Create tar archive
56 57 58 |
# File 'lib/capistrano/git/copy/utility.rb', line 56 def prepare_release execute git_archive_all_bin, "--prefix=''", archive_path end |
#release ⇒ Object
Upload and extract release
63 64 65 66 67 68 69 70 71 |
# File 'lib/capistrano/git/copy/utility.rb', line 63 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
99 100 101 |
# File 'lib/capistrano/git/copy/utility.rb', line 99 def repo_path @_repo_path ||= File.join(tmp_path, 'repo') end |
#test ⇒ Boolean
Check if repo cache exists
16 17 18 |
# File 'lib/capistrano/git/copy/utility.rb', line 16 def test test! " [ -d #{repo_path} ] " end |
#tmp_path ⇒ String
Temporary path for all git-copy operations
92 93 94 |
# File 'lib/capistrano/git/copy/utility.rb', line 92 def tmp_path @_tmp_path ||= File.join(Dir.tmpdir, deploy_id) end |
#update ⇒ Object
Update repo and submodules to branch
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/capistrano/git/copy/utility.rb', line 39 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 |