Class: Capistrano::GitCopy::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/git_copy/utility.rb

Overview

Utility stuff to avoid cluttering of deploy.cap

Instance Method Summary collapse

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_pathString

Path to archive

Returns:

  • (String)


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

#checkObject

Check if repo is accessible

Returns:

  • void



22
23
24
# File 'lib/capistrano/git_copy/utility.rb', line 22

def check
  git :'ls-remote --heads', repo_url
end

#cleanupObject

Cleanup repo cache

Returns:

  • void



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

#cloneObject

Clone repo to cache

Returns:

  • void



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_revisionObject

Set deployed revision

Returns:

  • void



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_releaseObject

Create tar archive

Returns:

  • void



55
56
57
# File 'lib/capistrano/git_copy/utility.rb', line 55

def prepare_release
  execute git_archive_all_bin, "--prefix=''", archive_path
end

#releaseObject

Upload and extract release

Returns:

  • void



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_pathString

Path to repo cache

Returns:

  • (String)


98
99
100
# File 'lib/capistrano/git_copy/utility.rb', line 98

def repo_path
  @_repo_path ||= File.join(tmp_path, 'repo')
end

#testBoolean

Check if repo cache exists

Returns:

  • (Boolean)

    indicates if repo cache exists



15
16
17
# File 'lib/capistrano/git_copy/utility.rb', line 15

def test
  test! " [ -d #{repo_path} ] "
end

#tmp_pathString

Temporary path for all git-copy operations

Returns:

  • (String)


91
92
93
# File 'lib/capistrano/git_copy/utility.rb', line 91

def tmp_path
  @_tmp_path ||= File.join(Dir.tmpdir, deploy_id)
end

#updateObject

Update repo and submodules to branch

Returns:

  • void



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