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_templates_path, 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



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

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

#cleanup(args:, opts:) ⇒ Object



153
154
155
156
157
# File 'lib/luban/deployment/cli/application/base.rb', line 153

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

#controllable?Boolean



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

def controllable?; has_source? or has_services?; end

#deploy(args:, opts:) ⇒ Object



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

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



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

def deployable?;   has_source?  or has_profile? end

#deployable_versionsObject



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

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

#deprecated_versionsObject



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

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

#destroy(args:, opts:) ⇒ Object



134
135
136
137
# File 'lib/luban/deployment/cli/application/base.rb', line 134

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

#destroy_project(args:, opts:) ⇒ Object



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

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



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

def has_packages?; !packages.empty?; end

#has_profile?Boolean



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

def has_profile?;  !profile.empty?; end

#has_services?Boolean



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

def has_services?; !services.empty?; end

#has_source?Boolean



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

def has_source?;   !source.empty?; end

#has_version?(version) ⇒ Boolean



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

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

#init_profile(args:, opts:) ⇒ Object



203
204
205
206
207
# File 'lib/luban/deployment/cli/application/base.rb', line 203

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



197
198
199
200
201
# File 'lib/luban/deployment/cli/application/base.rb', line 197

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

#init_service_profiles(args:, opts:) ⇒ Object



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

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

#installable?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



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

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



113
114
115
116
117
# File 'lib/luban/deployment/cli/application/base.rb', line 113

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



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

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



170
171
172
# File 'lib/luban/deployment/cli/application/base.rb', line 170

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



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

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



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



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

def versions; release_opts.keys; end