Class: Capistrano::BundleRsync::GitTurbo

Inherits:
SCM
  • Object
show all
Defined in:
lib/capistrano/bundle_rsync/git_turbo.rb

Overview

Make Deployment Super-Fast by Utilizing Hardlink and Rsync

Instance Method Summary collapse

Methods inherited from SCM

#rsync_shared

Methods inherited from Base

#config, #initialize

Constructor Details

This class inherits a constructor from Capistrano::BundleRsync::Base

Instance Method Details

#checkObject



6
7
8
9
10
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 6

def check
  execute :git, 'ls-remote', repo_url, 'HEAD'
  execute :mkdir, '-p', config.local_base_path
  execute :mkdir, '-p', config.local_releases_path
end

#clean_releaseObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 52

def clean_release
  releases = capture(:ls, '-x', config.local_releases_path).split
  if releases.count >= config.keep_releases
    directories = (releases - releases.last(config.keep_releases))
    if directories.any?
      directories_str = directories.map do |release|
        File.join(config.local_releases_path, release)
      end.join(' ')
      execute :rm, '-rf', directories_str
    end
  end
end

#cloneObject



12
13
14
15
16
17
18
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 12

def clone
  if test "[ -f #{config.local_mirror_path}/HEAD ]"
    info t(:mirror_exists, at: config.local_mirror_path)
  else
    execute :git, :clone, '--mirror', repo_url, config.local_mirror_path
  end
end

#create_releaseObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 26

def create_release
  set_current_revision

  worktree = local_worktree_path
  if test "[ -f #{worktree.join('.git')} ]"
    within worktree do
      execute :git, 'checkout', '--detach', fetch(:current_revision)
      execute :git, 'reset', '--hard'
      execute :git, 'clean', '--force', '-x'
    end
  else
    within config.local_mirror_path do
      execute :git, 'worktree', 'add', '-f', '--detach', worktree, fetch(:current_revision)
    end
  end

  source = fetch(:repo_tree) ? worktree.join(fetch(:repo_tree)) : worktree
  within config.local_base_path do
    execute :cp, '-al', source, config.local_release_path
  end

  within config.local_release_path do
    execute :rm, '-f', '.git'
  end
end

#rsync_releaseObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 65

def rsync_release
  hosts = release_roles(:all)
  c = config
  on hosts, in: :groups, limit: config.max_parallels(hosts), wait: 0 do |host|
    execute :mkdir, '-p', releases_path

    if source = capture(:ls, '-x', releases_path).split.last
      execute :cp, '-al', releases_path.join(source), release_path
    else
      execute :mkdir, '-p', release_path
    end

    run_locally do
      ssh = c.build_ssh_command(host)
      execute :rsync, "#{c.rsync_options} --rsh='#{ssh}' #{c.local_release_path}/ #{host}:#{release_path}/"
    end
  end
end

#set_current_revisionObject



84
85
86
87
88
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 84

def set_current_revision
  within config.local_mirror_path do
    set :current_revision, capture(:git, "rev-list --max-count=1 #{fetch(:branch)}")
  end
end

#updateObject



20
21
22
23
24
# File 'lib/capistrano/bundle_rsync/git_turbo.rb', line 20

def update
  within config.local_mirror_path do
    execute :git, :remote, :update, '--prune'
  end
end