Class: Capistrano::BundleRsync::Bundler

Inherits:
Base
  • Object
show all
Defined in:
lib/capistrano/bundle_rsync/bundler.rb

Instance Method Summary collapse

Methods inherited from Base

#config, #initialize

Constructor Details

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

Instance Method Details

#installObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/capistrano/bundle_rsync/bundler.rb', line 5

def install
  within config.local_release_app_path do
    Bundler.public_send(Bundler.respond_to?(:with_unbundled_env) ? :with_unbundled_env : :with_clean_env) do
      with bundle_app_config: config.local_base_path, rbenv_version: nil, rbenv_dir: nil do
        bundle_commands = if test :rbenv, 'version'
          %w[rbenv exec bundle]
        else
          %w[bundle]
        end

        execute *bundle_commands, 'config', '--local', 'deployment', 'true'
        execute *bundle_commands, 'config', '--local', 'path', config.local_bundle_path
        execute *bundle_commands, 'config', '--local', 'without', *config.bundle_without

        opts = ['--quiet']
        if jobs = config.bundle_install_jobs
          opts.push('--jobs', jobs)
        end

        if standalone = config.bundle_install_standalone_option
          opts.push(standalone)
        end

        execute *bundle_commands, *opts
        execute :rm, "#{config.local_base_path}/config"
      end
    end
  end
end

#rsyncObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capistrano/bundle_rsync/bundler.rb', line 35

def rsync
  hosts = release_roles(:all)
  release_app_path = config.release_app_path
  on hosts, in: :groups, limit: config.max_parallels(hosts) do
    within release_app_path do
      execute :mkdir, '-p', '.bundle'
    end
  end

  lines = <<-EOS
---
BUNDLE_FROZEN: '1'
BUNDLE_PATH: #{shared_path.join('bundle')}
BUNDLE_WITHOUT: #{config.bundle_without.join(':')}
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_BIN: #{release_app_path.join('bin')}
  EOS
  # BUNDLE_BIN requires rbenv-binstubs plugin to make it effectively work
  bundle_config_path = "#{config.local_base_path}/bundle_config"
  File.open(bundle_config_path, "w") {|file| file.print(lines) }

  hosts = ::Capistrano::Configuration.env.filter(hosts)
  rsync_options = config.rsync_options
  Parallel.each(hosts, in_threads: config.max_parallels(hosts)) do |host|
    ssh = config.build_ssh_command(host)
    execute :rsync, "#{rsync_options} --rsh='#{ssh}' #{config.local_bundle_path}/ #{host}:#{shared_path}/bundle/"
    execute :rsync, "#{rsync_options} --rsh='#{ssh}' #{bundle_config_path} #{host}:#{release_app_path}/.bundle/config"
  end
end