Class: Luban::Deployment::Application
- Inherits:
-
Command
- Object
- CLI::Command
- Command
- Luban::Deployment::Application
show all
- Includes:
- Command::Tasks::Control, Command::Tasks::Crontab, Command::Tasks::Deploy, Command::Tasks::Monitor, Command::Tasks::Provision, 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/crontab.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,
lib/luban/deployment/cli/application/docker/dockerable.rb,
lib/luban/deployment/cli/application/docker/dockerizer.rb
Direct Known Subclasses
Script
Defined Under Namespace
Modules: Dockerable
Classes: Authenticator, Configurator, Constructor, Controller, Crontab, Dockerizer, Publisher, Repository, Worker
Constant Summary
Command::Tasks::Crontab::Actions
Command::Tasks::Monitor::Actions
Command::Tasks::Control::Actions
Command::Tasks::Deploy::Actions
Command::Tasks::Provision::Actions
Parameters::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge
Parameters::General::DefaultLubanRootPath
Instance Attribute Summary collapse
#config
Class Method Summary
collapse
Instance Method Summary
collapse
-
#build(args:, opts:) ⇒ Object
-
#bundle_via(ruby:, project: "uber") ⇒ Object
-
#cleanup(args:, opts:) ⇒ Object
-
#controllable? ⇒ Boolean
-
#deploy(args:, opts:) ⇒ Object
-
#deployable? ⇒ Boolean
-
#deployable_versions ⇒ Object
-
#deprecated_versions ⇒ Object
-
#destroy(args:, opts:) ⇒ Object
-
#destroy_project(args:, opts:) ⇒ Object
-
#find_application(name = nil) ⇒ Object
-
#find_project ⇒ Object
-
#has_packages? ⇒ Boolean
-
#has_profile? ⇒ Boolean
-
#has_services? ⇒ Boolean
-
#has_source? ⇒ Boolean
-
#has_version?(version) ⇒ Boolean
-
#init_profile(args:, opts:) ⇒ Object
-
#init_profiles(args:, opts:) ⇒ Object
-
#init_service_profiles(args:, opts:) ⇒ Object
-
#init_source(args:, opts:) ⇒ Object
-
#local_source_base_path ⇒ Object
-
#local_source_path ⇒ Object
-
#local_source_stage_path ⇒ Object
(also: #default_source_path)
-
#other_package_users_for(package_name, package_version, servers: []) ⇒ Object
-
#package(name, version:, **opts) {|opts| ... } ⇒ Object
(also: #require_package)
-
#password_for(user) ⇒ Object
-
#profile(from = nil, **opts) ⇒ Object
-
#profile_release(version, **opts) ⇒ Object
-
#promptless_authen(args:, opts:) ⇒ Object
-
#provisionable? ⇒ Boolean
-
#release(version, **opts) ⇒ Object
-
#setup(args:, opts:) ⇒ Object
-
#show_current_application(args:, opts:) ⇒ Object
-
#show_summary_application(args:, opts:) ⇒ Object
-
#source(from = nil, **opts) ⇒ Object
-
#use_package?(package_name, package_version, servers: []) ⇒ Boolean
-
#versions ⇒ Object
#cronjob, #cronjobs, #crontab_tasks, #has_cronjobs?
#monitor_tasks, #monitorable?
#control_tasks
#provision_tasks
#dockerize, #dockerized?, #env_name, #logrotate_count, #monitor_itself?, #monitorable?
#parameter
#validate_for_docker_cert_path
#monitor_defined?, #process_monitor_via
Methods inherited from Command
#base_templates_path, #default_templates, #default_templates_paths, default_worker_class, dispatch_task, #display_name, inherited, #monitorable?, #run_task, worker_class
#current_uid, #current_user, included
#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Instance Attribute Details
#current_app ⇒ Object
Returns the value of attribute current_app.
15
16
17
|
# File 'lib/luban/deployment/cli/application/base.rb', line 15
def current_app
@current_app
end
|
#current_profile ⇒ Object
Returns the value of attribute current_profile.
17
18
19
|
# File 'lib/luban/deployment/cli/application/base.rb', line 17
def current_profile
@current_profile
end
|
#packages ⇒ Object
Returns the value of attribute packages.
13
14
15
|
# File 'lib/luban/deployment/cli/application/base.rb', line 13
def packages
@packages
end
|
#profile_opts ⇒ Object
Returns the value of attribute profile_opts.
18
19
20
|
# File 'lib/luban/deployment/cli/application/base.rb', line 18
def profile_opts
@profile_opts
end
|
#release_opts ⇒ Object
Returns the value of attribute release_opts.
16
17
18
|
# File 'lib/luban/deployment/cli/application/base.rb', line 16
def release_opts
@release_opts
end
|
#services ⇒ Object
Returns the value of attribute services.
14
15
16
|
# File 'lib/luban/deployment/cli/application/base.rb', line 14
def services
@services
end
|
Class Method Details
.action_on_packages(action, as: action) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/luban/deployment/cli/application/base.rb', line 20
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
27
28
29
30
31
32
|
# File 'lib/luban/deployment/cli/application/base.rb', line 27
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
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/luban/deployment/cli/application/base.rb', line 34
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
164
165
166
167
168
|
# File 'lib/luban/deployment/cli/application/base.rb', line 164
def build(args:, opts:)
show_app_environment
build_repositories(args: args, opts: opts)
install_all!(args: args, opts: opts)
end
|
#bundle_via(ruby:, project: "uber") ⇒ Object
91
92
93
94
95
|
# File 'lib/luban/deployment/cli/application/base.rb', line 91
def bundle_via(ruby:, project: "uber")
bundle_cmd = luban_root_path.join("env", "#{stage}.#{project}", ".luban", "pkg",
"ruby", "versions", ruby.to_s.downcase, 'bin', 'bundle')
set :bundle_via, bundle_cmd
end
|
#cleanup(args:, opts:) ⇒ Object
189
190
191
192
193
|
# File 'lib/luban/deployment/cli/application/base.rb', line 189
def cleanup(args:, opts:)
show_app_environment
cleanup_packages!(args: args, opts: opts)
cleanup_application!(args: args, opts: opts)
end
|
#controllable? ⇒ Boolean
60
|
# File 'lib/luban/deployment/cli/application/base.rb', line 60
def controllable?; has_source? or has_services?; end
|
#deploy(args:, opts:) ⇒ Object
217
218
219
220
221
222
|
# File 'lib/luban/deployment/cli/application/base.rb', line 217
def deploy(args:, opts:)
show_app_environment
deploy_profile(args: args, opts: opts) if has_profile?
deploy_release(args: args, opts: opts) if has_source?
deploy_cronjobs(args: args, opts: opts)
end
|
#deployable? ⇒ Boolean
59
|
# File 'lib/luban/deployment/cli/application/base.rb', line 59
def deployable?; true; end
|
#deployable_versions ⇒ Object
136
|
# File 'lib/luban/deployment/cli/application/base.rb', line 136
def deployable_versions; release_opts.select {|r, o| !o[:deprecated] }.keys; end
|
#deprecated_versions ⇒ Object
135
|
# File 'lib/luban/deployment/cli/application/base.rb', line 135
def deprecated_versions; release_opts.select {|r, o| o[:deprecated] }.keys; end
|
#destroy(args:, opts:) ⇒ Object
170
171
172
173
|
# File 'lib/luban/deployment/cli/application/base.rb', line 170
def destroy(args:, opts:)
uninstall_all!(args: args, opts: opts)
destroy!(args: args, opts: opts)
end
|
#destroy_project(args:, opts:) ⇒ Object
175
176
177
178
|
# File 'lib/luban/deployment/cli/application/base.rb', line 175
def destroy_project(args:, opts:)
show_app_environment
destroy!(args: args, opts: opts.merge(destroy_project: true))
end
|
#find_application(name = nil) ⇒ Object
49
50
51
|
# File 'lib/luban/deployment/cli/application/base.rb', line 49
def find_application(name = nil)
name.nil? ? self : find_project.apps[name.to_sym]
end
|
#find_project ⇒ Object
48
|
# File 'lib/luban/deployment/cli/application/base.rb', line 48
def find_project; parent; end
|
#has_packages? ⇒ Boolean
55
|
# File 'lib/luban/deployment/cli/application/base.rb', line 55
def has_packages?; !packages.empty?; end
|
#has_profile? ⇒ Boolean
54
|
# File 'lib/luban/deployment/cli/application/base.rb', line 54
def has_profile?; !profile.empty?; end
|
#has_services? ⇒ Boolean
56
|
# File 'lib/luban/deployment/cli/application/base.rb', line 56
def has_services?; !services.empty?; end
|
#has_source? ⇒ Boolean
53
|
# File 'lib/luban/deployment/cli/application/base.rb', line 53
def has_source?; !source.empty?; end
|
#has_version?(version) ⇒ Boolean
130
131
132
|
# File 'lib/luban/deployment/cli/application/base.rb', line 130
def has_version?(version)
release_opts.has_key?(version)
end
|
#init_profile(args:, opts:) ⇒ Object
254
255
256
257
258
|
# File 'lib/luban/deployment/cli/application/base.rb', line 254
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
238
239
240
241
242
243
|
# File 'lib/luban/deployment/cli/application/base.rb', line 238
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
261
262
263
264
265
266
267
268
|
# File 'lib/luban/deployment/cli/application/base.rb', line 261
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
245
246
247
248
249
250
251
|
# File 'lib/luban/deployment/cli/application/base.rb', line 245
def init_source(args:, opts:)
if respond_to?(:default_source_template_path, true)
init_source!(args: args,
opts: opts.merge(default_source_template_path: default_source_template_path,
default_source_path: default_source_path))
end
end
|
#local_source_base_path ⇒ Object
126
127
128
|
# File 'lib/luban/deployment/cli/application/base.rb', line 126
def local_source_base_path
@local_source_base_path ||= config_finder[:application].base_path.join('app')
end
|
#local_source_path ⇒ Object
115
116
117
118
119
|
# File 'lib/luban/deployment/cli/application/base.rb', line 115
def local_source_path
@local_source_path ||= [local_source_stage_path, local_source_base_path].find do |path|
File.directory?(path)
end
end
|
#local_source_stage_path ⇒ Object
Also known as:
default_source_path
121
122
123
|
# File 'lib/luban/deployment/cli/application/base.rb', line 121
def local_source_stage_path
@local_source_stage_path ||= config_finder[:application].stage_config_path.join('app')
end
|
#other_package_users_for(package_name, package_version, servers: []) ⇒ Object
69
70
71
72
|
# File 'lib/luban/deployment/cli/application/base.rb', line 69
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/luban/deployment/cli/application/base.rb', line 74
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.merge(packages: packages))
if pkg.is_a?(Luban::Deployment::Service::Base)
services[name] = pkg
add_service_parameters(pkg)
end
packages[name] = pkg
end
|
#password_for(user) ⇒ Object
138
|
# File 'lib/luban/deployment/cli/application/base.rb', line 138
def password_for(user); find_project.password_for(user); end
|
#profile(from = nil, **opts) ⇒ Object
97
98
99
|
# File 'lib/luban/deployment/cli/application/base.rb', line 97
def profile(from = nil, **opts)
from.nil? ? @profile : (@profile = opts.merge(type: 'profile', from: from))
end
|
#profile_release(version, **opts) ⇒ Object
101
102
103
104
|
# File 'lib/luban/deployment/cli/application/base.rb', line 101
def profile_release(version, **opts)
@current_profile = version if opts[:current]
profile_opts[version] = opts.merge(version: version)
end
|
#promptless_authen(args:, opts:) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/luban/deployment/cli/application/base.rb', line 140
def promptless_authen(args:, opts:)
opts = opts.merge(app: self, public_keys: Array(public_key!(args: args, opts: opts)))
public_keys = promptless_authen!(args: args, opts: opts).collect { |r| r[:public_key] }.compact
opts[:roles] = []
opts[:roles] << scm_role unless scm_role.nil?
opts[:roles] << archive_role unless archive_role.nil?
promptless_authen!(args: args, opts: opts) unless opts[:roles].empty?
unless archive_role.nil?
opts = opts.merge(roles: [archive_role], public_keys: public_keys)
promptless_authen!(args: args, opts: opts)
end
end
|
#provisionable? ⇒ Boolean
58
|
# File 'lib/luban/deployment/cli/application/base.rb', line 58
def provisionable?; has_packages?; end
|
#release(version, **opts) ⇒ Object
110
111
112
113
|
# File 'lib/luban/deployment/cli/application/base.rb', line 110
def release(version, **opts)
@current_app = version if opts[:current]
release_opts[version] = opts.merge(version: version)
end
|
#setup(args:, opts:) ⇒ Object
157
158
159
160
161
|
# File 'lib/luban/deployment/cli/application/base.rb', line 157
def setup(args:, opts:)
show_app_environment
promptless_authen(args: args, opts: opts) unless skip_promptless_authen
setup!(args: args, opts: opts)
end
|
#show_current_application(args:, opts:) ⇒ Object
206
207
208
|
# File 'lib/luban/deployment/cli/application/base.rb', line 206
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
210
211
212
213
214
|
# File 'lib/luban/deployment/cli/application/base.rb', line 210
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
106
107
108
|
# File 'lib/luban/deployment/cli/application/base.rb', line 106
def source(from = nil, **opts)
from.nil? ? @source : (@source = opts.merge(type: 'app', from: from))
end
|
#use_package?(package_name, package_version, servers: []) ⇒ Boolean
62
63
64
65
66
67
|
# File 'lib/luban/deployment/cli/application/base.rb', line 62
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
|
#versions ⇒ Object
134
|
# File 'lib/luban/deployment/cli/application/base.rb', line 134
def versions; release_opts.keys; end
|