Class: Capistrano::NetStorage::Bundler

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/capistrano/net_storage/bundler.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



9
10
11
12
13
# File 'lib/capistrano/net_storage/bundler.rb', line 9

def check
  run_locally do
    execute :which, 'bundle'
  end
end

#installObject

Do bundle install locally. Installed gems are to be included to the release.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/capistrano/net_storage/bundler.rb', line 16

def install
  c = config
  run_locally do
    local_release_bundle_path = c.local_release_path.join('vendor', 'bundle')
    execute :mkdir, '-p', local_release_bundle_path
    execute :mkdir, '-p', "#{c.local_release_path}/.bundle"
    # Copy shared gems to release bundle path beforehand to reuse installed previously
    execute :rsync, '-a', "#{c.local_bundle_path}/", "#{local_release_bundle_path}/"

    within c.local_release_path do
      ::Bundler.with_clean_env do
        install_options = %W(
          --gemfile #{c.local_release_path}/Gemfile --deployment --quiet
          --path #{local_release_bundle_path} --without development test
        )
        execute :bundle, 'install', *install_options
        execute :bundle, 'clean'
        # Sync installed gems to shared directory to reuse them next time
        rsync_options = %W(-a --delete #{local_release_bundle_path}/ #{c.local_bundle_path}/)
        execute :rsync, *rsync_options
      end
    end
  end
end

#sync_configObject

Create .bundle/config at release path on remote servers



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/capistrano/net_storage/bundler.rb', line 42

def sync_config
  c = config

  on c.servers, in: :groups, limit: c.max_parallels do
    within release_path do
      execute :mkdir, '-p', '.bundle'
    end
  end

  bundle_config_path = "#{c.local_base_path}/bundle_config"
  File.open(bundle_config_path, 'w') do |file|
    file.print("---\nBUNDLE_FROZEN: \"1\"\nBUNDLE_PATH: \"\#{release_path.join('vendor', 'bundle')}\"\nBUNDLE_WITHOUT: \"development:test\"\nBUNDLE_DISABLE_SHARED_GEMS: \"true\"\nBUNDLE_BIN: \"\#{release_path.join('bin')}\"\n")
  end

  upload_files([bundle_config_path], dest_path: release_path.join('.bundle', 'config'))
end