class Luban::Deployment::Package::Installer
Constants
- DefaultLibExtension
- DefaultSrcFileExtName
- LibExtensions
Shared library file extension name based on OS
- UncompressOptions
Attributes
build_env_vars[R]
configure_opts[R]
Public Instance Methods
build_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 47 def build_path @build_path ||= package_tmp_path.join(package_full_name) end
cached?()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 39 def cached? md5_matched?(src_cache_path, src_file_md5) end
cleanup_all()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 122 def cleanup_all cleanup_temp! cleanup_logs! update_result "Cleaned up temporary files in #{package_full_name} installation" end
configure_executable()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 27 def configure_executable @configure_executable ||= './configure' end
current_configured?()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 23 def current_configured?; task.opts.current; end
Also aliased as: current?
current_package_version()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 28 def current_package_version if symlink?(current_path) File.basename(readlink(current_path)) else nil end end
current_symlinked?()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 19 def current_symlinked? current_package_version == package_version end
currently_used_by()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 15 def currently_used_by parent.currently_used_by end
default_configure_opts()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 36 def default_configure_opts @default_configure_opts ||= [] end
deprecated?()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 26 def deprecated?; task.opts.deprecated; end
download()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 48 def download info "Downloading #{package_full_name}" if downloaded? create_src_md5_file unless file?(src_md5_file_path) update_result "Skipped! #{package_full_name} has been downloaded ALREADY." else download_package! if downloaded? create_src_md5_file unless file?(src_md5_file_path) update_result "Successfully downloaded #{package_full_name}." else update_result "Failed to download #{package_full_name}. " + "Please check install log for details: #{install_log_file_path}", status: :failed, level: :error end end end
download_url()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 35 def download_url @download_url ||= File.join(source_repo, source_url_root, src_file_name) end
downloaded?()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 35 def downloaded? file?(src_file_path) end
get_summary()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 128 def get_summary status = if current_symlinked? current? ? " *" : "s*" else current? ? "c*" : (deprecated? ? " d" : " ") end if installed? installed = 'installed' alert = case status when "s*" "Alert! #{package_full_name} is not the current version but symlinked IMPROPERLY. " + "Run \"binstubs\" to fix it." when "c*" "Alert! #{package_full_name} is set as current version but NOT symlinked properly. " + "Run \"binstubs\" to fix it." end else installed = 'NOT installed' alert = nil end update_result summary: { name: package_full_name, installed: installed, status: status, alert: alert } end
include_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 43 def include_path @include_path ||= install_path.join('include') end
install()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 66 def install info "Installing #{package_full_name}" if installed? if force? install! else return update_result("Skipped! #{package_full_name} has been installed ALREADY.", status: :skipped) end else install! end if installed? update_result "Successfully installed #{package_full_name}." else update_result "Failed to install #{package_full_name}. " + "Please check install log for details: #{install_log_file_path}", status: :failed, level: :error end end
install_log_file_name()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 59 def install_log_file_name @install_log_file_name ||= "#{package_full_name}-install-#{Time.now.strftime("%Y%m%d-%H%M%S")}.log" end
install_log_file_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 55 def install_log_file_path @install_log_file_path ||= install_log_path.join(install_log_file_name) end
install_log_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 51 def install_log_path @install_log_path ||= package_path.join('log', package_full_name) end
installed?()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 31 def installed? raise NotImplementedError, "#{self.class.name}#installed? is an abstract method." end
lib_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 39 def lib_path @lib_path ||= install_path.join('lib') end
required_packages()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 21 def required_packages @required_packages ||= self.class.package_class(package_name). required_packages_for(package_major_version) end
source_repo()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 27 def source_repo raise NotImplementedError, "#{self.class.name}#source_repo is an abstract method." end
source_url_root()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 31 def source_url_root raise NotImplementedError, "#{self.class.name}#source_url_root is an abstract method." end
src_cache_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 15 def src_cache_path @src_cache_path ||= tmp_path.join(src_file_name) end
src_file_extname()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 11 def src_file_extname @src_file_extname ||= DefaultSrcFileExtName end
src_file_md5()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 17 def src_file_md5 @src_file_md5 ||= File.file?(src_md5_file_path) ? File.read(src_md5_file_path).chomp : '' end
src_file_name()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 7 def src_file_name @src_file_name ||= "#{package_full_name}.#{src_file_extname}" end
src_file_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 19 def src_file_path @src_file_path ||= package_downloads_path.join(src_file_name) end
src_md5_file_path()
click to toggle source
# File lib/luban/deployment/cli/package/installer/paths.rb, line 23 def src_md5_file_path @src_md5_file_path ||= package_downloads_path.join("#{src_file_name}.md5") end
uninstall()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 88 def uninstall info "Uninstalling #{package_full_name}" if installed? if current? and !force? update_result "Skippped! #{package_full_name} is the current version in use. " + "Please switch to other version before uninstalling this version or " + "use -f to force uninstalling.", status: :skipped, level: :warn else uninstall! update_result "#{package_full_name} is uninstalled. " end else message = if deprecated? "#{package_full_name} has been deprecated." else "#{package_full_name} is NOT installed." end if directory?(install_path) or directory?(build_path) if force? uninstall! update_result message + "Cleaned up leftover of #{package_full_name} from last installation." else update_result message + "But leftover from last installation is found. " + "Use -f to force clean it up." end else update_result "Skipped! #{message}" end end end
update_binstubs()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 153 def update_binstubs return if child? if current? if installed? update_binstubs! update_result "Updated #{package_name} binstubs/symlinks with current version #{package_version}" else update_result "Skipped! #{package_full_name} is NOT installed yet. Please install it first.", status: :failed, level: :error end else if current_symlinked? remove_binstubs! remove_symlinks! update_result "Removed #{package_name} binstubs/symlinks with version #{package_version}. " + "Current version of #{package_name} is NOT specified.", level: :warn end end end
validate_download_url()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 43 def validate_download_url info "Validating download URL for #{package_full_name}" validate_download_url! end
whence_origin()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 184 def whence_origin get_summary.tap do |result| result.summary[:executable] = "Not found" if file?(executable = bin_path.join(task.args.executable)) result.summary[:executable] = executable end end end
which_current()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 174 def which_current get_summary.tap do |result| result.summary[:executable] = "Not found" if current? and current_symlinked? and file?(executable = File.join(readlink(current_path), 'bin', task.args.executable)) result.summary[:executable] = executable end end end
Protected Instance Methods
abort_action(action)
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 406 def abort_action(action) cleanup_temp! task.result.status = :failed task.result.message = "Failed to #{action} package #{package_full_name}." + "Please check install log for details: #{install_log_file_path}" raise InstallFailure, task.result.message end
after_download()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 203 def after_download download_required_packages(:after_install) end
after_install()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 231 def after_install install_required_packages(:after_install) update_binstubs end
before_download()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 195 def before_download unless downloaded? bootstrap_download validate_download_url end download_required_packages(:before_install) end
before_install()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 226 def before_install bootstrap_install install_required_packages(:before_install) end
bootstrap_download()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 318 def bootstrap_download assure_dirs(package_downloads_path) end
bootstrap_install()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 322 def bootstrap_install assure_dirs(tmp_path, app_bin_path, package_tmp_path, install_path, install_log_path) end
build_package()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 370 def build_package within build_path do configure_package make_package install_package end end
cleanup_build!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 278 def cleanup_build! rmdir(build_path) end
cleanup_logs!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 282 def cleanup_logs! rmdir(install_log_path) end
cleanup_temp!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 265 def cleanup_temp! Luban::Deployment::Package::DependencyTypes.each do |type| required_packages[type].each do |d| self.class.worker_class(:installer, package: d.name).new( config: config, backend: backend, cmd: :cleanup_all, args: {}, opts: d.options.merge(name: d.name, version: d.version, parent: self) ).run end end cleanup_build! end
compose_build_env_variables()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 70 def compose_build_env_variables build_env_vars.inject({}) do |vars, (k, v)| vars[k] = "#{v.join(' ').strip}" unless v.all?(&:empty?) vars end end
compose_build_options()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 84 def compose_build_options @configure_opts.reject(&:empty?).join(' ') end
configure_build_env_variables()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 48 def configure_build_env_variables @build_env_vars = { ldflags: [ENV['LDFLAGS'].to_s], cflags: [ENV['CFLAGS'].to_s] } if child? configure_parent_build_env_variables configure_parent_build_options end end
configure_build_options()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 77 def configure_build_options @configure_opts = default_configure_opts @configure_opts |= task.opts.configure_opts unless task.opts.configure_opts.nil? @configure_opts |= task.opts.__remaining__ unless task.opts.__remaining__.nil? @configure_opts.unshift(install_prefix) end
configure_package()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 378 def configure_package info "Configuring #{package_full_name}" abort_action('configure') unless configure_package! end
configure_package!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 383 def configure_package! test(configure_executable, "#{compose_build_options} >> #{install_log_file_path} 2>&1") end
configure_parent_build_env_variables()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 59 def configure_parent_build_env_variables parent.build_env_vars[:ldflags] << "-L#{lib_path}" parent.build_env_vars[:cflags] << "-I#{include_path}" end
configure_parent_build_options()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 64 def configure_parent_build_options if parent.respond_to?("with_#{package_name}_dir") parent.send("with_#{package_name}_dir", install_path) end end
create_binstubs!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 297 def create_binstubs! return unless directory?(bin_path) find_cmd = "find #{bin_path}/* -type f -print && find #{bin_path}/* -type l -print" capture(find_cmd).split("\n").each do |bin| ln(bin, app_bin_path.join(File.basename(bin))) end end
create_src_md5_file()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 334 def create_src_md5_file execute(:echo, "#{md5_for_file(src_file_path)} > #{src_md5_file_path}") end
create_symlinks!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 293 def create_symlinks! ln(install_path, current_path) end
download_package!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 327 def download_package! unless test(:curl, "-L -o #{src_file_path} #{download_url}") rm(src_file_path) abort_action('download') end end
download_required_packages(type)
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 207 def download_required_packages(type) manage_required_packages(type, :download) end
init()
click to toggle source
Calls superclass method
# File lib/luban/deployment/cli/package/installer/core.rb, line 42 def init super configure_build_env_variables configure_build_options end
install!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 247 def install! cleanup_build! # Cleanup leftover from last install if any upload_package uncompress_package build_package cleanup_build! end
install_package()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 397 def install_package info "Installing #{package_full_name}" abort_action('install') unless install_package! end
install_package!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 402 def install_package! test(:make, "install >> #{install_log_file_path} 2>&1") end
install_prefix()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 88 def install_prefix "--prefix=#{install_path}" end
install_required_packages(type)
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 236 def install_required_packages(type) manage_required_packages(type, :install) end
lib_extension()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 94 def lib_extension @lib_extension ||= LibExtensions.fetch(os_name.to_sym, DefaultLibExtension) end
make_package()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 388 def make_package info "Making #{package_full_name}" abort_action('make') unless make_package! end
make_package!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 393 def make_package! test(:make, ">> #{install_log_file_path} 2>&1") end
manage_required_packages(type, cmd)
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 211 def manage_required_packages(type, cmd) required_packages[type].each do |d| version = task.opts.send(d.name) || d.version next if version == 'default' version = self.class.package_class(d.name).latest_version if version == 'latest' self.class.worker_class(:installer, package: d.name).new( config: config, backend: backend, cmd: cmd, args: {}, opts: d.options.merge(name: d.name, version: version, current: true, parent: self). merge(self.class.package_class(d.name).decompose_version(version)) ).run end end
remove_binstubs!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 309 def remove_binstubs! return unless directory?(current_bin_path) find_cmd = "find #{current_bin_path}/* -type f -print && find #{current_bin_path}/* -type l -print" capture(find_cmd).split("\n").each do |bin| bin_symlink = app_bin_path.join(File.basename(bin)) symlink?(bin_symlink) and rm(bin_symlink) end end
remove_symlinks!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 305 def remove_symlinks! symlink?(current_path) and rm(current_path) end
uncompress_option()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 360 def uncompress_option @uncompress_option ||= UncompressOptions[File.extname(src_file_name)] end
uncompress_package()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 355 def uncompress_package info "Uncompressing #{package_full_name} source package" uncompress_package! end
uncompress_package!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 364 def uncompress_package! unless test("tar #{uncompress_option} -xf #{src_cache_path} -C #{package_tmp_path} >> #{install_log_file_path} 2>&1") abort_action('uncompress') end end
uninstall!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 255 def uninstall! if current? remove_binstubs! remove_symlinks! end rmdir(install_path) cleanup_temp! cleanup_logs! end
update_binstubs!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 286 def update_binstubs! remove_binstubs! remove_symlinks! create_symlinks! create_binstubs! end
upload_package()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 338 def upload_package info "Uploading #{package_full_name} source package" if cached? info "#{package_full_name} is uploaded ALREADY" else upload_package! end end
upload_package!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 347 def upload_package! upload!(src_file_path.to_s, src_cache_path.to_s) unless md5_matched?(src_cache_path, src_file_md5) rm(src_cache_path) abort_action('upload') end end
validate()
click to toggle source
# File lib/luban/deployment/cli/package/installer/core.rb, line 92 def validate; end
validate_download_url!()
click to toggle source
# File lib/luban/deployment/cli/package/installer/install.rb, line 240 def validate_download_url! unless url_exists?(download_url) raise InstallFailure, "Package #{package_full_name} is NOT found from url: #{download_url}." end end