Class: Luban::Deployment::Package::Base

Inherits:
Command
  • Object
show all
Includes:
Command::Tasks::Provision, Luban::Deployment::Parameters::Application, Luban::Deployment::Parameters::Project
Defined in:
lib/luban/deployment/cli/package/base.rb

Constant Summary

Constants included from Command::Tasks::Provision

Command::Tasks::Provision::Actions

Constants included from Luban::Deployment::Parameters::Application

Luban::Deployment::Parameters::Application::DefaultLogrotateInterval, Luban::Deployment::Parameters::Application::DefaultLogrotateMaxAge

Constants included from Luban::Deployment::Parameters::General

Luban::Deployment::Parameters::General::DefaultLubanRootPath

Instance Attribute Summary collapse

Attributes included from Helpers::Configuration

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command::Tasks::Provision

#provision_tasks, #provisionable?

Methods included from Luban::Deployment::Parameters::Application

#dockerize, #dockerized?, #env_name, #logrotate_count, #monitor_itself?

Methods included from Luban::Deployment::Parameters::Base

#parameter

Methods included from Luban::Deployment::Parameters::Docker

#validate_for_docker_cert_path

Methods included from Luban::Deployment::Parameters::Project

#monitor_defined?, #process_monitor_via

Methods inherited from Command

#base_templates_path, #controllable?, #default_templates, #default_templates_paths, default_worker_class, #deployable?, dispatch_task, #display_name, #provisionable?, #run_task

Methods included from Luban::Deployment::Parameters::General

#current_uid, #current_user, included

Methods included from Helpers::Configuration

#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?

Instance Attribute Details

#current_versionObject (readonly)

Returns the value of attribute current_version.



93
94
95
# File 'lib/luban/deployment/cli/package/base.rb', line 93

def current_version
  @current_version
end

Class Method Details

.apply_to(version, &blk) ⇒ Object



23
24
25
# File 'lib/luban/deployment/cli/package/base.rb', line 23

def apply_to(version, &blk)
  dependencies.apply_to(version, &blk)
end

.decompose_version(version) ⇒ Object



51
52
53
# File 'lib/luban/deployment/cli/package/base.rb', line 51

def decompose_version(version)
  { major_version: version, patch_level: '' }
end

.dependenciesObject



19
20
21
# File 'lib/luban/deployment/cli/package/base.rb', line 19

def dependencies
  @dependencies ||= DependencySet.new
end

.get_latest_versionObject

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/luban/deployment/cli/package/base.rb', line 63

def get_latest_version
  raise NotImplementedError, "#{self.class.name}#get_latest_version is an abstract method."
end

.inherited(subclass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/luban/deployment/cli/package/base.rb', line 8

def inherited(subclass)
  super
  # Ensure package dependencies from base class
  # got inherited to its subclasses

  subclass.instance_variable_set(
    '@dependencies',
    Marshal.load(Marshal.dump(dependencies))
  )
end

.latest_versionObject



57
58
59
60
61
# File 'lib/luban/deployment/cli/package/base.rb', line 57

def latest_version
  version_mutex.synchronize do
    @latest_version ||= get_latest_version
  end
end

.package_class(package) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/luban/deployment/cli/package/base.rb', line 31

def package_class(package)
  require_path = package_require_path(package)
  require require_path.to_s
  package_base_class(require_path)
rescue LoadError => e
  abort "Aborted! Failed to load package #{require_path}: #{e.message}"
end

.required_packages_for(version) ⇒ Object



27
28
29
# File 'lib/luban/deployment/cli/package/base.rb', line 27

def required_packages_for(version)
  dependencies.dependencies_for(version)
end

.version_mutexObject



55
# File 'lib/luban/deployment/cli/package/base.rb', line 55

def version_mutex; @version_mutex ||= Mutex.new; end

.worker_class(worker, package: self) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/luban/deployment/cli/package/base.rb', line 39

def worker_class(worker, package: self)
  if package.is_a?(Class)
    if package == self
      super(worker)
    else
      package.worker_class(worker)
    end
  else
    package_class(package).worker_class(worker)
  end
end

Instance Method Details

#binstubs(args:, opts:) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'lib/luban/deployment/cli/package/base.rb', line 163

def binstubs(args:, opts:)
  if current_version
    update_binstubs(args: args, opts: opts.merge(version: current_version))
  else
    versions.each do |v|
      update_binstubs(args: args, opts: opts.merge(version: v))
    end
  end
end

#cleanup(args:, opts:) ⇒ Object



157
158
159
160
161
# File 'lib/luban/deployment/cli/package/base.rb', line 157

def cleanup(args:, opts:)
  versions.each do |v|
    cleanup_all(args: args, opts: opts.merge(version: v))
  end
end

#deprecated_versionsObject



112
# File 'lib/luban/deployment/cli/package/base.rb', line 112

def deprecated_versions; package_options.select { |v, o| o[:deprecated] }.keys; end

#find_application(name = nil) ⇒ Object



89
90
91
# File 'lib/luban/deployment/cli/package/base.rb', line 89

def find_application(name = nil)
  name.nil? ? parent : find_project.apps[name.to_sym]
end

#find_projectObject



88
# File 'lib/luban/deployment/cli/package/base.rb', line 88

def find_project; parent.parent; end

#has_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/luban/deployment/cli/package/base.rb', line 107

def has_version?(version)
  package_options.has_key?(version)
end

#install(args:, opts:) ⇒ Object



123
124
125
126
127
128
# File 'lib/luban/deployment/cli/package/base.rb', line 123

def install(args:, opts:)
  result = download_package(args: args, opts: opts)
  unless result.nil? or result.status == :failed
    install_package(args: args, opts: opts)
  end
end

#install_all(args:, opts:) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/luban/deployment/cli/package/base.rb', line 130

def install_all(args:, opts:)
  installable_versions.each do |v| 
    install(args: args, opts: opts.merge(version: v))
  end
  deprecated_versions.each do |v| 
    uninstall(args: args, opts: opts.merge(version: v))
  end
end

#installable_versionsObject



113
# File 'lib/luban/deployment/cli/package/base.rb', line 113

def installable_versions; package_options.select { |v, o| !o[:deprecated] }.keys; end

#monitorable?Boolean

Returns:

  • (Boolean)


86
# File 'lib/luban/deployment/cli/package/base.rb', line 86

def monitorable?; false; end

#package_optionsObject



95
# File 'lib/luban/deployment/cli/package/base.rb', line 95

def package_options; @package_options ||= {}; end

#show_current(args:, opts:) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/luban/deployment/cli/package/base.rb', line 173

def show_current(args:, opts:)
  if current_version
    print_summary(get_summary(args: args, opts: opts.merge(version: current_version)))
  else
    puts "    Warning! No current version of #{display_name} is specified."
  end
end

#show_summary(args:, opts:) ⇒ Object



181
182
183
184
185
# File 'lib/luban/deployment/cli/package/base.rb', line 181

def show_summary(args:, opts:)
  versions.each do |v|
    print_summary(get_summary(args: args, opts: opts.merge(version: v)))
  end
end

#uninstall(args:, opts:) ⇒ Object



146
147
148
149
150
151
152
153
154
155
# File 'lib/luban/deployment/cli/package/base.rb', line 146

def uninstall(args:, opts:)
  servers = select_servers(opts[:roles], opts[:hosts])
  apps = parent.other_package_users_for(name, opts[:version], servers: servers)
  if apps.empty? or opts[:force]
    uninstall!(args: args, opts: opts)
  else
    puts "Skipped. #{name}-#{opts[:version]} is being referenced by #{apps.join(', ')}. " +
         "use -f to force uninstalling if necessary."
  end
end

#uninstall!Object



145
# File 'lib/luban/deployment/cli/package/base.rb', line 145

alias_method :uninstall!, :uninstall

#uninstall_all(args:, opts:) ⇒ Object



139
140
141
142
143
# File 'lib/luban/deployment/cli/package/base.rb', line 139

def uninstall_all(args:, opts:)
  versions.each do |v|
    uninstall(args: args, opts: opts.merge(version: v))
  end
end

#update_package_options(version, **opts) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/luban/deployment/cli/package/base.rb', line 97

def update_package_options(version, **opts)
  unless has_version?(version)
    version = self.class.package_class(name).latest_version if version == 'latest'
    package_options[version] = 
      { name: name.to_s }.merge!(self.class.decompose_version(version))
  end
  @current_version = version if opts[:current]
  package_options[version].merge!(opts)
end

#versionsObject



111
# File 'lib/luban/deployment/cli/package/base.rb', line 111

def versions; package_options.keys; end

#whence(args:, opts:) ⇒ Object



195
196
197
198
199
# File 'lib/luban/deployment/cli/package/base.rb', line 195

def whence(args:, opts:)
  versions.each do |v|
    print_summary(whence_origin(args: args, opts: opts.merge(version: v)))
  end
end

#which(args:, opts:) ⇒ Object



187
188
189
190
191
192
193
# File 'lib/luban/deployment/cli/package/base.rb', line 187

def which(args:, opts:)
  if current_version
    print_summary(which_current(args: args, opts: opts.merge(version: current_version)))
  else
    puts "    Warning! No current version of #{display_name} is specified."
  end
end