Module: Capistrano::DSL::Opscomplete

Defined in:
lib/capistrano/dsl/opscomplete.rb

Overview

A whole capistrano/rake namespace, for grouping our helpers and tasks

Instance Method Summary collapse

Instance Method Details

#app_gemfile_bundled_with_versionObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/capistrano/dsl/opscomplete.rb', line 33

def app_gemfile_bundled_with_version
  release_gemfile_lock_file_path = release_path.join('Gemfile.lock').to_s

  if test("[ -f #{release_gemfile_lock_file_path} ]")
    debug('found release_dir/Gemfile.lock')

    grep_command = [:grep, '-A', '1', '"BUNDLED WITH"', release_gemfile_lock_file_path]

    if test(*grep_command)
      bundled_with_lines = capture(*grep_command)
      version = bundled_with_lines.split.last
      debug("Using version #{version.inspect} from server's release_dir/Gemfile.lock file.")
      version
    else
      # old bundler versions did not write "BUNDLED WITH"
      debug('Gemfile.lock was found but did not contain "BUNDLED WITH"-section')
    end
  else
    debug('There was no Gemfile.lock to parse the bundler version')
  end
end

#app_nodejs_versionObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/capistrano/dsl/opscomplete.rb', line 88

def app_nodejs_version
  # 1) Get version from capistrano configuration (highest precedence, 'override')
  if fetch(:opscomplete_nodejs_version)
    debug("Using version from :opscomplete_nodejs_version setting: #{fetch(:opscomplete_nodejs_version)}.")
    fetch(:opscomplete_nodejs_version)

  # 2) Get version from version file in release dir (after deploy:updating, before deploy:updated)
  elsif capture(:nodejs_get_version, release_path)
    debug("Using version from server's release_dir/.nvmrc, .node-version or .tool-versions file: #{capture(:nodejs_get_version, release_path)}")
    capture(:nodejs_get_version, release_path)

  else
    raise Capistrano::ValidationError, 'Could not find application\'s Node.js version. Consider setting opscomplete_ruby_version.'
  end
end

#app_ruby_versionObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capistrano/dsl/opscomplete.rb', line 9

def app_ruby_version
  release_ruby_version_file_path = release_path.join('.ruby-version').to_s

  # 1) Get version from capistrano configuration (highest precedence, 'override')
  if fetch(:opscomplete_ruby_version)
    debug("Using version from :opscomplete_ruby_version setting: #{fetch(:opscomplete_ruby_version)}.")
    fetch(:opscomplete_ruby_version)

  # 2) Get version from .ruby-version in release dir (after deploy:updating, before deploy:updated)
  elsif test("[ -f #{release_ruby_version_file_path} ]")
    debug("Using version from server's release_dir/.ruby-version file: #{capture(:cat, release_ruby_version_file_path)}")
    capture(:cat, release_ruby_version_file_path)

  # 3) Get version from local checkout/cwd
  elsif File.readable?('.ruby-version')
    debug("Using version from local (cwd) .ruby-version file: #{File.read('.ruby-version').strip}")
    File.read('.ruby-version').strip

  # FAIL: We have no idea which version to use
  else
    raise Capistrano::ValidationError, 'Could not find application\'s .ruby-version. Consider setting opscomplete_ruby_version.'
  end
end

#gem_install(name, version = nil, force = false) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/capistrano/dsl/opscomplete.rb', line 76

def gem_install(name, version = nil, force = false)
  if version
    execute(:ruby_install_gem, name, '--version', "'#{version}'", force ? '--force' : '')
  else
    execute(:ruby_install_gem, name)
  end
end

#gem_installed?(name, version = nil) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/capistrano/dsl/opscomplete.rb', line 68

def gem_installed?(name, version = nil)
  if version
    test(:ruby_installed_gem, name, '--version', "'#{version}'")
  else
    test(:ruby_installed_gem, name)
  end
end

#managed_nodejs?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/capistrano/dsl/opscomplete.rb', line 84

def managed_nodejs?
  test('[ -f ${HOME}/.nodejs_managed_by_makandra ]')
end

#managed_ruby?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/capistrano/dsl/opscomplete.rb', line 5

def managed_ruby?
  test(:ruby_update_management_tool, 'managed')
end

#nodejs_installable_versionsObject



104
105
106
107
108
# File 'lib/capistrano/dsl/opscomplete.rb', line 104

def nodejs_installable_versions
  nodejs_installable_versions = capture(:nodejs_installable_versions).split("\n")
  nodejs_installable_versions.map!(&:strip)
  nodejs_installable_versions
end

#nodejs_installed_versionsObject



110
111
112
113
# File 'lib/capistrano/dsl/opscomplete.rb', line 110

def nodejs_installed_versions
  nodejs_installed_versions = capture(:nodejs_installed_versions).split("\n")
  nodejs_installed_versions.map!(&:strip)
end

#ruby_installable_versionsObject



55
56
57
58
59
# File 'lib/capistrano/dsl/opscomplete.rb', line 55

def ruby_installable_versions
  ruby_installable_versions = capture(:ruby_installable_versions).split("\n")
  ruby_installable_versions.map!(&:strip)
  ruby_installable_versions
end

#ruby_installed_versionsObject



61
62
63
64
65
66
# File 'lib/capistrano/dsl/opscomplete.rb', line 61

def ruby_installed_versions
  ruby_installed_versions = capture(:ruby_installed_versions).split("\n")
  ruby_installed_versions.map!(&:strip)
  warn('Could not look up installed versions. This is probably the first ruby install.') if ruby_installed_versions.empty?
  ruby_installed_versions
end

#validation_error!(message) ⇒ Object

Raises:

  • (Capistrano::ValidationError)


115
116
117
# File 'lib/capistrano/dsl/opscomplete.rb', line 115

def validation_error!(message)
  raise Capistrano::ValidationError, message unless dry_run?
end