Class: Tebako::DeployHelper

Inherits:
ScenarioManagerWithBundler show all
Defined in:
lib/tebako/deploy_helper.rb

Overview

Tebako packaging support (deployer)

Constant Summary collapse

BUNDLE_CACHE_VERSION =

rubocop:disable Metrics/ClassLength

1

Instance Attribute Summary collapse

Attributes inherited from ScenarioManager

#bundler_version, #fs_entrance, #fs_entry_point, #gemfile_path, #needs_bundler, #scenario, #with_gemfile

Attributes inherited from ScenarioManagerBase

#exe_suffix, #fs_mount_point

Instance Method Summary collapse

Methods inherited from ScenarioManager

#bundler_reference, #configure_scenario

Methods inherited from ScenarioManagerBase

#b_env, #linux?, #linux_gnu?, #linux_musl?, #m_files, #macos?, #msys?, #musl?, #ncores

Constructor Details

#initialize(fs_root, fs_entrance, target_dir, pre_dir, bundle_cache_dir = nil, native_gem_cache_dir = nil, tool_bin_dir: nil) ⇒ DeployHelper

rubocop:disable Metrics/ParameterLists



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tebako/deploy_helper.rb', line 50

def initialize(fs_root, fs_entrance, target_dir, pre_dir, bundle_cache_dir = nil, # rubocop:disable Metrics/ParameterLists
               native_gem_cache_dir = nil, tool_bin_dir: nil)
  super(fs_root, fs_entrance)
  @fs_root = fs_root
  @fs_entrance = fs_entrance
  @target_dir = target_dir
  @pre_dir = pre_dir
  @bundle_cache_dir = bundle_cache_dir
  @native_gem_cache_dir = native_gem_cache_dir
  @tool_bin_dir = tool_bin_dir
  @verbose = %w[yes true].include?(ENV.fetch("VERBOSE", nil))
end

Instance Attribute Details

#gem_homeObject (readonly)

Returns the value of attribute gem_home.



63
64
65
# File 'lib/tebako/deploy_helper.rb', line 63

def gem_home
  @gem_home
end

Instance Method Details

#configure(ruby_ver, cwd) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tebako/deploy_helper.rb', line 65

def configure(ruby_ver, cwd)
  @ruby_ver = ruby_ver
  @needs_bundler = true unless @ruby_ver.ruby31?
  @cwd = cwd

  @tbd = File.join(@target_dir, "bin")
  @tgd = @gem_home = File.join(@target_dir, "lib", "ruby", "gems", @ruby_ver.api_version)
  @tld = File.join(@target_dir, "local")

  configure_scenario
  configure_commands
end

#deploy(install_runtime: true) ⇒ Object

rubocop:disable Metrics/MethodLength



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tebako/deploy_helper.rb', line 78

def deploy(install_runtime: true) # rubocop:disable Metrics/MethodLength
  BuildHelpers.with_env(deploy_env) do
    restore_bundle_cache
    native_gem_cache.restore
    update_rubygems
    system(*gem_command("env")) if @verbose
    install_gem("tebako-runtime") if install_runtime
    install_gem("bundler", @bundler_version) if @needs_bundler
    deploy_solution
    native_gem_cache.save
    check_cwd
  end
end

#deploy_envObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/tebako/deploy_helper.rb', line 99

def deploy_env
  environment = {
    "GEM_HOME" => gem_home,
    "GEM_PATH" => gem_home,
    "GEM_SPEC_CACHE" => File.join(@target_dir, "spec_cache"),
    "TEBAKO_PASS_THROUGH" => "1"
  }
  environment["RUBYLIB"] = tool_ruby_lib if @tool_bin_dir
  environment
end

#deploy_runtimeObject

rubocop:enable Metrics/MethodLength



92
93
94
95
96
97
# File 'lib/tebako/deploy_helper.rb', line 92

def deploy_runtime
  BuildHelpers.with_env(deploy_env) do
    update_rubygems
    install_gem("tebako-runtime")
  end
end

#install_gem(name, ver = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/tebako/deploy_helper.rb', line 110

def install_gem(name, ver = nil)
  puts "   ... installing #{name} gem#{" version #{ver}" if ver}"

  params = gem_command("install", name.to_s)
  params += ["-v", ver.to_s] if ver
  params += ["--no-document", "--install-dir", @tgd, "--bindir", @tbd]
  params += ["--platform", "ruby"] if msys?
  BuildHelpers.run_with_capture_v(params)
end

#update_rubygemsObject



120
121
122
123
124
125
126
127
128
# File 'lib/tebako/deploy_helper.rb', line 120

def update_rubygems
  return if @ruby_ver.ruby31?

  puts "   ... updating rubygems to #{Tebako::RUBYGEMS_VERSION}"
  BuildHelpers.run_with_capture_v(gem_command("update", "--no-doc", "--system", Tebako::RUBYGEMS_VERSION))

  patch = Packager::RubygemsUpdatePatch.new(@fs_mount_point).patch_map
  Packager.do_patch(patch, "#{@target_dir}/lib/ruby/site_ruby/#{@ruby_ver.api_version}")
end