class Luban::Deployment::Application
Attributes
current_app[R]
current_profile[R]
packages[R]
profile_opts[R]
release_opts[R]
services[R]
Public Class Methods
action_on_packages(action, as: action)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Public Instance Methods
build(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 191 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")
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 118 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:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 216 def cleanup(args:, opts:) show_app_environment cleanup_packages!(args: args, opts: opts) cleanup_application!(args: args, opts: opts) end
controllable?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 60 def controllable?; has_source? or has_services?; end
depend_on_package?(package_name, package_version)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 67 def depend_on_package?(package_name, package_version) !dependent_packages_for(package_name, package_version).empty? end
dependent_packages_for(package_name, package_version)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 71 def dependent_packages_for(package_name, package_version) packages.inject([]) do |dependent_pkgs, (pkg_name, pkg)| if pkg.package_options.any? do |version, _| pkg.class.required_packages_for(version).any? do |_, deps| deps.any? { |dep| dep.name == package_name.to_s and dep.version == package_version } end end dependent_pkgs << "#{display_name}.#{pkg_name}" end dependent_pkgs end end
deploy(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 244 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?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 59 def deployable?; true; end
deployable_versions()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 163 def deployable_versions; release_opts.select {|r, o| !o[:deprecated] }.keys; end
deprecated_versions()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 162 def deprecated_versions; release_opts.select {|r, o| o[:deprecated] }.keys; end
destroy(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 197 def destroy(args:, opts:) uninstall_all!(args: args, opts: opts) destroy!(args: args, opts: opts) end
destroy_project(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 202 def destroy_project(args:, opts:) show_app_environment destroy!(args: args, opts: opts.merge(destroy_project: true)) end
find_application(name = nil)
click to toggle source
# 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()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 48 def find_project; parent; end
has_packages?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 55 def has_packages?; !packages.empty?; end
has_profile?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 54 def has_profile?; !profile.empty?; end
has_services?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 56 def has_services?; !services.empty?; end
has_source?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 53 def has_source?; !source.empty?; end
has_version?(version)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 157 def has_version?(version) release_opts.has_key?(version) end
init_profile(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 281 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:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 265 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:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 288 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:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 272 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()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 153 def local_source_base_path @local_source_base_path ||= config_finder[:application].base_path.join('app') end
local_source_path()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 142 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()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 148 def local_source_stage_path @local_source_stage_path ||= config_finder[:application].stage_config_path.join('app') end
Also aliased as: default_source_path
other_package_users_for(package_name, package_version, servers: [])
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 84 def other_package_users_for(package_name, package_version, servers: []) dependent_packages_for(package_name, package_version) | find_project.package_users_for(package_name, package_version, exclude: [name], servers: servers) end
package(name, version:, **opts) { |opts| ... }
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 101 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
Also aliased as: require_package
package_users_for(package_name, package_version, servers: [])
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 90 def package_users_for(package_name, package_version, servers: []) package_users = [] if config.servers.any? { |s| servers.include?(s) } if use_package?(package_name, package_version) package_users << "#{display_name}.#{package_name}" end package_users |= dependent_packages_for(package_name, package_version) end package_users end
password_for(user)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 165 def password_for(user); find_project.password_for(user); end
profile(from = nil, **opts)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 124 def profile(from = nil, **opts) from.nil? ? @profile : (@profile = opts.merge(type: 'profile', from: from)) end
profile_release(version, **opts)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 128 def profile_release(version, **opts) @current_profile = version if opts[:current] profile_opts[version] = opts.merge(version: version) end
promptless_authen(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 167 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?()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 58 def provisionable?; has_packages?; end
release(version, **opts)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 137 def release(version, **opts) @current_app = version if opts[:current] release_opts[version] = opts.merge(version: version) end
setup(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 184 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:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 233 def show_current_application(args:, opts:) print_summary(get_summary(args: args, opts: opts.merge(version: current_app))) end
show_summary_application(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 237 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)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 133 def source(from = nil, **opts) from.nil? ? @source : (@source = opts.merge(type: 'app', from: from)) end
use_package?(package_name, package_version)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 62 def use_package?(package_name, package_version) packages.has_key?(package_name) and packages[package_name].has_version?(package_version) end
versions()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 161 def versions; release_opts.keys; end
Protected Instance Methods
add_service_parameters(service)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 356 def add_service_parameters(service) service.class.parameters.each_pair do |param, default| singleton_class.send(:parameter, param, default: default) end end
after_configure()
click to toggle source
Calls superclass method
# File lib/luban/deployment/cli/application/base.rb, line 351 def after_configure super assign_cronjobs if has_cronjobs? end
build_repositories(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 393 def build_repositories(args:, opts:) build_repository!(args: args, opts: opts.merge(repository: profile)) if has_profile? build_repository!(args: args, opts: opts.merge(repository: source)) if has_source? end
compose_task_options(opts)
click to toggle source
Calls superclass method
Luban::Deployment::Command#compose_task_options
# File lib/luban/deployment/cli/application/base.rb, line 373 def compose_task_options(opts) super.merge(name: name.to_s, packages: packages).tap do |o| version = o[:version] unless version.nil? o.merge!(release: release_opts[version]) update_release_tag(o) end end end
deploy_cronjobs(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 444 def deploy_cronjobs(args:, opts:) opts = opts.merge(version: current_app) if has_source? deploy_cronjobs!(args: args, opts: opts) end
deploy_profile(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 399 def deploy_profile(args:, opts:) update_profile(args: args, opts: opts) deploy_profile!(args: args, opts: opts.merge(repository: profile.merge(version: current_profile))) end
deploy_profile!(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 439 def deploy_profile!(args:, opts:) deploy_release!(args: args, opts: opts) services.each_value { |s| s.binstubs(args: args, opts: opts) } end
deploy_release(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 410 def deploy_release(args:, opts:) deployable_versions.each do |version| deploy_release!(args: args, opts: opts.merge(repository: source.merge(version: version))) end deprecated_versions.each do |version| deprecate_release!(args: args, opts: opts.merge(repository: source.merge(version: version))) end end
deploy_release!(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 419 def deploy_release!(args:, opts:) package_release!(args: args, opts: opts)[:release_pack].tap do |pack| unless pack.nil? publish_release!(args: args, opts: opts.merge(release_pack: pack)) end end end
deprecate_release!(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 429 def deprecate_release!(args:, opts:) deprecate_packaged_release!(args: args, opts: opts)[:release_pack].tap do |pack| unless pack.nil? deprecate_published_release!(args: args, opts: opts.merge(release_pack: pack)) end end end
load_configuration()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 335 def load_configuration config_finder[:project].load_configuration config_finder[:application].load_configuration end
print_summary(result)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 450 def print_summary(result) Array(result).each do |entry| s = entry[:summary] puts " [#{entry[:hostname]}] #{s[:status]} #{s[:name]} (#{s[:published]})" puts " [#{entry[:hostname]}] #{s[:alert]}" unless s[:alert].nil? end end
set_default_for_profile()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 328 def set_default_for_profile if config_finder[:application].has_profile? profile(config_finder[:application].stage_profile_path, scm: :rsync) profile_release(stage, current: true) end end
set_default_for_source()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 321 def set_default_for_source unless local_source_path.nil? source(local_source_path, scm: :rsync) release(stage, current: true) end end
set_parameters()
click to toggle source
Calls superclass method
Luban::Deployment::Command#set_parameters
# File lib/luban/deployment/cli/application/base.rb, line 309 def set_parameters super copy_parameters_from_parent(:stage, :project, :process_monitor) set :application, self.class.name.split(':').last.snakecase @packages = {} @services = {} @source = {} @release_opts = {} @profile = {} @profile_opts = {} end
setup_descriptions()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 340 def setup_descriptions desc "Manage application #{display_name}" long_desc "Manage the deployment of application #{display_name} in #{parent.class.name}" end
setup_init_profiles()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 362 def setup_init_profiles _services = services.keys task :init do desc 'Initialize deployment app/service profiles' switch :app, "Application profile ONLY", short: :a option :service, "Service profile ONLY", short: :s, nullable: true, within: _services.push(nil), type: :symbol action! :init_profiles end end
setup_tasks()
click to toggle source
Calls superclass method
Luban::Deployment::Command#setup_tasks
# File lib/luban/deployment/cli/application/base.rb, line 345 def setup_tasks setup_init_profiles super setup_crontab_tasks end
show_app_environment()
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 389 def show_app_environment puts "#{display_name} in #{parent.class.name}" end
update_profile(args:, opts:)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 404 def update_profile(args:, opts:) update_profile!(args: args, opts: opts.merge(version: current_app)) services.each_value { |s| s.send(:update_profile, args: args, opts: opts) } end
update_release_tag(version:, **opts)
click to toggle source
# File lib/luban/deployment/cli/application/base.rb, line 383 def update_release_tag(version:, **opts) opts[:release][:tag] ||= release_tag(args: {}, opts: opts.merge(repository: source.merge(version: version))) end