Class: Luban::Deployment::Application

Inherits:
Command
  • Object
show all
Includes:
Command::Tasks::Control, Command::Tasks::Deploy, Command::Tasks::Install, Parameters::Application, Parameters::Project
Defined in:
lib/luban/deployment/cli/application/base.rb,
lib/luban/deployment/cli/application/worker.rb,
lib/luban/deployment/cli/application/scm/git.rb,
lib/luban/deployment/cli/application/publisher.rb,
lib/luban/deployment/cli/application/scm/rsync.rb,
lib/luban/deployment/cli/application/controller.rb,
lib/luban/deployment/cli/application/repository.rb,
lib/luban/deployment/cli/application/constructor.rb,
lib/luban/deployment/cli/application/configurator.rb,
lib/luban/deployment/cli/application/authenticator.rb

Defined Under Namespace

Classes: Authenticator, Configurator, Constructor, Controller, Publisher, Repository, Worker

Constant Summary

Constants included from Command::Tasks::Control

Command::Tasks::Control::Actions

Constants included from Command::Tasks::Deploy

Command::Tasks::Deploy::Actions

Constants included from Command::Tasks::Install

Command::Tasks::Install::Actions

Constants included from Parameters::General

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::Control

#process_monitor_via

Methods included from Parameters::Base

#parameter

Methods inherited from Command

#base_templates_path, #default_templates, default_worker_class, dispatch_task, #display_name, #run_task, #task, worker_class

Methods included from Parameters::General

included

Methods included from Helpers::Configuration

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

Instance Attribute Details

#current_appObject (readonly)

Returns the value of attribute current_app.



12
13
14
# File 'lib/luban/deployment/cli/application/base.rb', line 12

def current_app
  @current_app
end

#current_profileObject (readonly)

Returns the value of attribute current_profile.



14
15
16
# File 'lib/luban/deployment/cli/application/base.rb', line 14

def current_profile
  @current_profile
end

#packagesObject (readonly)

Returns the value of attribute packages.



10
11
12
# File 'lib/luban/deployment/cli/application/base.rb', line 10

def packages
  @packages
end

#profile_optsObject (readonly)

Returns the value of attribute profile_opts.



15
16
17
# File 'lib/luban/deployment/cli/application/base.rb', line 15

def profile_opts
  @profile_opts
end

#release_optsObject (readonly)

Returns the value of attribute release_opts.



13
14
15
# File 'lib/luban/deployment/cli/application/base.rb', line 13

def release_opts
  @release_opts
end

#servicesObject (readonly)

Returns the value of attribute services.



11
12
13
# File 'lib/luban/deployment/cli/application/base.rb', line 11

def services
  @services
end

Class Method Details

.action_on_packages(action, as: action) ⇒ Object



17
18
19
20
21
22
# File 'lib/luban/deployment/cli/application/base.rb', line 17

def self.action_on_packages(action, as: action)
  define_method(action) do |args:, opts:|
    packages.each_value { |p| p.send(as, args: args, opts: opts) }
  end
  protected action
end

.action_on_services(action, as: action) ⇒ Object



24
25
26
27
28
29
# File 'lib/luban/deployment/cli/application/base.rb', line 24

def self.action_on_services(action, as: action)
  define_method(action) do |args:, opts:|
    services.each_value { |s| s.send(as, args: args, opts: opts) }
  end
  protected action
end

.application_action(action, dispatch_to: nil, as: action, locally: false, &blk) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/luban/deployment/cli/application/base.rb', line 31

def self.application_action(action, dispatch_to: nil, as: action, locally: false, &blk)
  define_method(action) do |args:, opts:|
    if current_app
      send("#{__method__}!", args: args, opts: opts.merge(version: current_app))
    else
      abort "Aborted! No current version of #{display_name} is specified."
    end
  end
  unless dispatch_to.nil?
    dispatch_task "#{action}!", to: dispatch_to, as: as, locally: locally, &blk
    protected "#{action}!"
  end
end

Instance Method Details

#build(args:, opts:) ⇒ Object



136
137
138
139
140
# File 'lib/luban/deployment/cli/application/base.rb', line 136

def build(args:, opts:)
  show_app_environment
  install_all!(args: args, opts: opts)
  build_repositories(args: args, opts: opts)
end

#cleanup(args:, opts:) ⇒ Object



161
162
163
164
165
# File 'lib/luban/deployment/cli/application/base.rb', line 161

def cleanup(args:, opts:)
  show_app_environment
  cleanup_packages!(args: args, opts: opts)
  cleanup_application!(args: args, opts: opts)
end

#controllable?Boolean

Returns:

  • (Boolean)


57
# File 'lib/luban/deployment/cli/application/base.rb', line 57

def controllable?; has_source? or has_services?; end

#default_source?Boolean

Returns:

  • (Boolean)


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

def default_source?
  has_source? and source[:from] == default_source_path
end

#default_source_pathObject



103
104
105
# File 'lib/luban/deployment/cli/application/base.rb', line 103

def default_source_path
  @default_source_path ||= config_finder[:application].stage_config_path.join('app')
end

#deploy(args:, opts:) ⇒ Object



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

def deploy(args:, opts:)
  show_app_environment
  deploy_release(args: args, opts: opts) if has_source?
  deploy_profile(args: args, opts: opts) if has_profile?
end

#deployable?Boolean

Returns:

  • (Boolean)


56
# File 'lib/luban/deployment/cli/application/base.rb', line 56

def deployable?;   has_source?  or has_profile? end

#deployable_versionsObject



117
# File 'lib/luban/deployment/cli/application/base.rb', line 117

def deployable_versions; release_opts.select {|r, o| !o[:deprecated] }.keys; end

#deprecated_versionsObject



116
# File 'lib/luban/deployment/cli/application/base.rb', line 116

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

#destroy(args:, opts:) ⇒ Object



142
143
144
145
# File 'lib/luban/deployment/cli/application/base.rb', line 142

def destroy(args:, opts:)
  uninstall_all!(args: args, opts: opts)
  destroy!(args: args, opts: opts)
end

#destroy_project(args:, opts:) ⇒ Object



147
148
149
150
# File 'lib/luban/deployment/cli/application/base.rb', line 147

def destroy_project(args:, opts:)
  show_app_environment
  destroy!(args: args, opts: opts.merge(destroy_project: true))
end

#find_application(name = nil) ⇒ Object



46
47
48
# File 'lib/luban/deployment/cli/application/base.rb', line 46

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

#find_projectObject



45
# File 'lib/luban/deployment/cli/application/base.rb', line 45

def find_project; parent; end

#has_packages?Boolean

Returns:

  • (Boolean)


52
# File 'lib/luban/deployment/cli/application/base.rb', line 52

def has_packages?; !packages.empty?; end

#has_profile?Boolean

Returns:

  • (Boolean)


51
# File 'lib/luban/deployment/cli/application/base.rb', line 51

def has_profile?;  !profile.empty?; end

#has_services?Boolean

Returns:

  • (Boolean)


53
# File 'lib/luban/deployment/cli/application/base.rb', line 53

def has_services?; !services.empty?; end

#has_source?Boolean

Returns:

  • (Boolean)


50
# File 'lib/luban/deployment/cli/application/base.rb', line 50

def has_source?;   !source.empty?; end

#has_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/luban/deployment/cli/application/base.rb', line 111

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

#init_profile(args:, opts:) ⇒ Object



219
220
221
222
223
# File 'lib/luban/deployment/cli/application/base.rb', line 219

def init_profile(args:, opts:)
  if opts[:app] or opts[:service].nil?
    init_profile!(args: args, opts: opts.merge(default_templates: default_templates))
  end
end

#init_profiles(args:, opts:) ⇒ Object



205
206
207
208
209
210
# File 'lib/luban/deployment/cli/application/base.rb', line 205

def init_profiles(args:, opts:)
  show_app_environment
  init_profile(args: args, opts: opts)
  init_service_profiles(args: args, opts: opts)
  init_source(args: args, opts: opts)
end

#init_service_profiles(args:, opts:) ⇒ Object



226
227
228
229
230
231
232
233
# File 'lib/luban/deployment/cli/application/base.rb', line 226

def init_service_profiles(args:, opts:)
  return if opts[:app]
  if services.has_key?(opts[:service])
    services[opts[:service]].init_profile(args: args, opts: opts)
  else
    services.each_value { |s| s.init_profile(args: args, opts: opts) }
  end
end

#init_source(args:, opts:) ⇒ Object



212
213
214
215
216
# File 'lib/luban/deployment/cli/application/base.rb', line 212

def init_source(args:, opts:)
  if default_source?
    init_source!(args: args, opts: opts.merge(source: source))
  end
end

#installable?Boolean

Returns:

  • (Boolean)


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

def installable?;  has_packages?; end

#other_package_users_for(package_name, package_version, servers: []) ⇒ Object



66
67
68
69
# File 'lib/luban/deployment/cli/application/base.rb', line 66

def other_package_users_for(package_name, package_version, servers: [])
  find_project.package_users_for(package_name, package_version, 
                                 exclude: [name], servers: servers)
end

#package(name, version:, **opts) {|opts| ... } ⇒ Object Also known as: require_package

Yields:

  • (opts)


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/luban/deployment/cli/application/base.rb', line 71

def package(name, version:, **opts)
  yield opts if block_given?
  name = name.to_sym
  pkg = if has_command?(name)
          commands[name]
        else
          command(name, base: Luban::Deployment::Package::Base.package_class(name))
        end
  pkg.update_package_options(version, opts)
  services[name] = pkg if pkg.is_a?(Luban::Deployment::Service::Base)
  packages[name] = pkg
end

#password_for(user) ⇒ Object



119
# File 'lib/luban/deployment/cli/application/base.rb', line 119

def password_for(user); find_project.password_for(user); end

#profile(from = nil, **opts) ⇒ Object



85
86
87
# File 'lib/luban/deployment/cli/application/base.rb', line 85

def profile(from = nil, **opts)
  from.nil? ? @profile : (@profile = opts.merge(type: 'profile', from: from))
end

#profile_release(version, **opts) ⇒ Object



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

def profile_release(version, **opts)
  @current_profile = version if opts[:current]
  profile_opts[version] = opts.merge(version: version)
end

#promptless_authen(args:, opts:) ⇒ Object



121
122
123
124
125
# File 'lib/luban/deployment/cli/application/base.rb', line 121

def promptless_authen(args:, opts:)
  opts = opts.merge(app: self, public_keys: Array(public_key!(args: args, opts: opts)))
  opts[:roles] << scm_role unless scm_role.nil?
  promptless_authen!(args: args, opts: opts)
end

#release(version, **opts) ⇒ Object



98
99
100
101
# File 'lib/luban/deployment/cli/application/base.rb', line 98

def release(version, **opts)
  @current_app = version if opts[:current]
  release_opts[version] = opts.merge(version: version)
end

#setup(args:, opts:) ⇒ Object



129
130
131
132
133
# File 'lib/luban/deployment/cli/application/base.rb', line 129

def setup(args:, opts:)
  show_app_environment
  promptless_authen(args: args, opts: opts)
  setup!(args: args, opts: opts)
end

#show_current_application(args:, opts:) ⇒ Object



178
179
180
# File 'lib/luban/deployment/cli/application/base.rb', line 178

def show_current_application(args:, opts:)
  print_summary(get_summary(args: args, opts: opts.merge(version: current_app)))
end

#show_summary_application(args:, opts:) ⇒ Object



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

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

#source(from = nil, **opts) ⇒ Object



94
95
96
# File 'lib/luban/deployment/cli/application/base.rb', line 94

def source(from = nil, **opts)
  from.nil? ? @source : (@source = opts.merge(type: 'app', from: from))
end

#use_package?(package_name, package_version, servers: []) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
# File 'lib/luban/deployment/cli/application/base.rb', line 59

def use_package?(package_name, package_version, servers: [])
  package_name = package_name.to_sym
  packages.has_key?(package_name) and
  packages[package_name].has_version?(package_version) and
  packages[package_name].config.servers.any? { |s| servers.include?(s) }
end

#versionsObject



115
# File 'lib/luban/deployment/cli/application/base.rb', line 115

def versions; release_opts.keys; end