Class: CapistranoMulticonfigParallel::BaseManager
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::BaseManager
show all
- Includes:
- Celluloid, Celluloid::Logger
- Defined in:
- lib/capistrano_multiconfig_parallel/helpers/base_manager.rb
Overview
finds app dependencies, shows menu and delegates jobs to celluloid manager rubocop:disable ClassLength
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(cap_app, top_level_tasks, stages) ⇒ BaseManager
Returns a new instance of BaseManager.
11
12
13
14
15
16
17
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 11
def initialize(cap_app, top_level_tasks, stages)
@cap_app = cap_app
@top_level_tasks = top_level_tasks
@stages = stages
@jobs = []
CapistranoMulticonfigParallel.enable_logging
end
|
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def application
@application
end
|
#args ⇒ Object
Returns the value of attribute args.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def args
@args
end
|
#argv ⇒ Object
Returns the value of attribute argv.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def argv
@argv
end
|
#condition ⇒ Object
Returns the value of attribute condition.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def condition
@condition
end
|
#default_stage ⇒ Object
Returns the value of attribute default_stage.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def default_stage
@default_stage
end
|
#deps ⇒ Object
Returns the value of attribute deps.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def deps
@deps
end
|
#job_registered_condition ⇒ Object
Returns the value of attribute job_registered_condition.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def job_registered_condition
@job_registered_condition
end
|
#jobs ⇒ Object
Returns the value of attribute jobs.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def jobs
@jobs
end
|
#manager ⇒ Object
Returns the value of attribute manager.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def manager
@manager
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def name
@name
end
|
#original_argv ⇒ Object
Returns the value of attribute original_argv.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def original_argv
@original_argv
end
|
#stage ⇒ Object
Returns the value of attribute stage.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9
def stage
@stage
end
|
Instance Method Details
#can_start? ⇒ Boolean
19
20
21
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 19
def can_start?
@top_level_tasks.size > 1 && (stages.include?(@top_level_tasks.first) || custom_command?) && ENV[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID].blank?
end
|
#can_tag_staging? ⇒ Boolean
114
115
116
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 114
def can_tag_staging?
using_git? && wants_deploy_production? && tag_staging_exists? && worker_environments.include?('staging')
end
|
#check_before_starting ⇒ Object
#check_giflow_tasks(*tasks) ⇒ Object
99
100
101
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 99
def check_giflow_tasks(*tasks)
tasks.all? {|t| t.present? && t.prerequisites.present? }
end
|
#check_multi_stages(stages) ⇒ Object
118
119
120
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 118
def check_multi_stages(stages)
can_tag_staging? ? stages.reject { |u| u == 'production' } : stages
end
|
#collect_jobs(options = {}, &block) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 74
def collect_jobs(options = {}, &block)
options = prepare_options(options)
block.call(options) if block_given?
rescue => e
raise [e, e.backtrace].inspect
end
|
#configuration ⇒ Object
40
41
42
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 40
def configuration
CapistranoMulticonfigParallel.configuration
end
|
#confirmation_applies_to_all_workers? ⇒ Boolean
145
146
147
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 145
def confirmation_applies_to_all_workers?
CapistranoMulticonfigParallel.configuration.apply_stage_confirmation.all? { |e| worker_environments.include?(e) }
end
|
#custom_command? ⇒ Boolean
23
24
25
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 23
def custom_command?
@top_level_tasks.first == 'ensure_stage' && !stages.include?(@top_level_tasks.second) && !stages.include?(@top_level_tasks.first) && custom_commands.values.include?(@top_level_tasks.second)
end
|
#custom_commands ⇒ Object
#deploy_app(options = {}) ⇒ Object
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 122
def deploy_app(options = {})
options = options.stringify_keys
app = options['app'].is_a?(Hash) ? options['app'] : { 'app' => options['app'] }
branch = @branch_backup.present? ? @branch_backup : @argv['BRANCH'].to_s
call_task_deploy_app({
branch: branch,
app: app,
action: options['action']
}.reverse_merge(options))
end
|
#executes_deploy_stages? ⇒ Boolean
32
33
34
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 32
def executes_deploy_stages?
@name == custom_commands[:stages]
end
|
#fetch_multi_stages ⇒ Object
103
104
105
106
107
108
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 103
def fetch_multi_stages
stages = @argv['STAGES'].blank? ? '' : @argv['STAGES']
@argv = @argv['STAGES'].present? ? @argv.except('STAGES') : @argv
stages = parse_inputted_value(value: stages).split(',').compact if stages.present?
stages.present? ? stages : [@default_stage]
end
|
#get_app_additional_env_options(app, app_message) ⇒ Object
133
134
135
136
137
138
139
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 133
def get_app_additional_env_options(app, app_message)
app_name = (app.is_a?(Hash) && app[:app].present?) ? app[:app].camelcase : app
app_name = app_name.present? ? app_name : 'current application'
message = "Please write additional ENV options for #{app_name} for #{app_message}"
set :app_additional_env_options, CapistranoMulticonfigParallel.ask_confirm(message, nil)
fetch_app_additional_env_options
end
|
#initialize_data ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 51
def initialize_data
@application = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[1]
@stage = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[0]
@stage = @stage.present? ? @stage : @default_stage
@name, @args = @cap_app.parse_task_string(@top_level_tasks.second)
@argv = @cap_app.handle_options.delete_if { |arg| arg == @stage || arg == @name || arg == @top_level_tasks.first }
@argv = multi_fetch_argv(@argv)
@original_argv = @argv.clone
end
|
#multi_apps? ⇒ Boolean
36
37
38
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 36
def multi_apps?
@cap_app.multi_apps?
end
|
#start(&block) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 44
def start(&block)
check_before_starting
initialize_data
block.call if block_given?
run
end
|
#tag_staging_exists? ⇒ Boolean
check exists task from capistrano-gitflow
#verify_options_custom_command(options) ⇒ Object
61
62
63
64
65
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 61
def verify_options_custom_command(options)
options[:action] = @argv['ACTION'].present? ? @argv['ACTION'] : 'deploy'
@argv = @argv['ACTION'].present? ? @argv.except('ACTION') : @argv
options
end
|
#wants_deploy_production? ⇒ Boolean
110
111
112
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 110
def wants_deploy_production?
(!custom_command? && @stage == 'production') || (custom_command? && fetch_multi_stages.include?('production'))
end
|
#worker_environments ⇒ Object
141
142
143
|
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 141
def worker_environments
@jobs.map { |job| job['env'] }
end
|