capistrano_multiconfig_parallel 0.16.2 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +10 -10
  4. data/img/interactive_menu.png +0 -0
  5. data/lib/capistrano_multiconfig_parallel/all.rb +1 -1
  6. data/lib/capistrano_multiconfig_parallel/application.rb +11 -73
  7. data/lib/capistrano_multiconfig_parallel/base.rb +31 -13
  8. data/lib/capistrano_multiconfig_parallel/celluloid/rake_worker.rb +19 -8
  9. data/lib/capistrano_multiconfig_parallel/{helpers → classes}/dependency_tracker.rb +0 -0
  10. data/lib/capistrano_multiconfig_parallel/{helpers → classes}/input_stream.rb +0 -0
  11. data/lib/capistrano_multiconfig_parallel/{helpers → classes}/interactive_menu.rb +0 -0
  12. data/lib/capistrano_multiconfig_parallel/{helpers → classes}/output_stream.rb +0 -0
  13. data/lib/capistrano_multiconfig_parallel/{helpers → classes}/rake_hook_actor.rb +0 -0
  14. data/lib/capistrano_multiconfig_parallel/{helpers → classes}/standard_deploy.rb +1 -1
  15. data/lib/capistrano_multiconfig_parallel/cli.rb +36 -18
  16. data/lib/capistrano_multiconfig_parallel/{initializers → configuration}/default.yml +0 -0
  17. data/lib/capistrano_multiconfig_parallel/helpers/application_helper.rb +45 -0
  18. data/lib/capistrano_multiconfig_parallel/helpers/configuration.rb +1 -17
  19. data/lib/capistrano_multiconfig_parallel/helpers/{helper.rb → core_helper.rb} +40 -55
  20. data/lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb +33 -0
  21. data/lib/capistrano_multiconfig_parallel/{extensions → initializers}/rake.rb +1 -1
  22. data/lib/capistrano_multiconfig_parallel/version.rb +2 -2
  23. metadata +13 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99e92a6da9184666f399d4821380706a6a361197
4
- data.tar.gz: a3bb52d48c80affcad5d4a3541fb91a03cedfa21
3
+ metadata.gz: 383ca1a8dd3caa6d1ae38370f3a3f5b7d05c6dbc
4
+ data.tar.gz: 4a2bce60bf821d9f65692c40fd133c67e5e77a04
5
5
  SHA512:
6
- metadata.gz: 7b6cc7dea5188da7fd45f0297a97836d7ab8d98291a69318969b7850a36228c36ac2d9976a663b7901956040d4811c986f8b22d1ed94e62d36d3b9a759d072b7
7
- data.tar.gz: f43866f7a24f267147e0f1b58124ebf992239b749ff8c71d83d9c2300c24086251ae1433ccbdf09dc3359447b7e925edb7e7633326f77b9f945610f49f2d5a9f
6
+ metadata.gz: a426aff1833349f6862f9aa2bd42f4f3e249df4057659f86f29a1e3c60e2682c4b474c7c0bbf8f4b25ef1f1400351aaf10fd85e6ae9e96ea1c40b2b54fe6f4c0
7
+ data.tar.gz: 5b3ed5196838866db3f1b4369785f3eb0fc49dec74665139e4dde7488f9ccf1995dc8542be6045125224c1ea4f724e47b36ddef3cbe2628a0d35ec683e872875
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano_multiconfig_parallel (0.16.0)
4
+ capistrano_multiconfig_parallel (0.16.2)
5
5
  activesupport (~> 4.0, >= 4.0)
6
6
  capistrano (~> 3.0, >= 3.0)
7
7
  celluloid-pmap (~> 0.2, >= 0.2.2)
data/README.md CHANGED
@@ -22,17 +22,17 @@ Requirements
22
22
 
23
23
  1. [Ruby 1.9.x or Ruby 2.x.x](http://www.ruby-lang.org)
24
24
  2. [ActiveSuport >= 4.2.0](https://rubygems.org/gems/activesupport)
25
- 3. [celluloid-pmap >= 0.2.0](https://github.com/jwo/celluloid-pmap)
25
+ 3. [celluloid-pmap >= 0.2.2](https://github.com/jwo/celluloid-pmap)
26
26
  4. [composable_state_machine >= 1.0.2](https://github.com/swoop-inc/composable_state_machine)
27
- 5. [terminal-table >= 1.4.5](https://github.com/tj/terminal-table)
28
- 6. [colorize](https://github.com/fazibear/colorize)
29
- 7. [eventmachine >= 1.0.7](https://github.com/eventmachine/eventmachine)
27
+ 5. [terminal-table >= 1.5.2](https://github.com/tj/terminal-table)
28
+ 6. [colorize >= 0.7](https://github.com/fazibear/colorize)
29
+ 7. [eventmachine >= 1.0.3](https://github.com/eventmachine/eventmachine)
30
30
  8. [right_popen >= 1.1.3](https://github.com/rightscale/right_popen)
31
- 9. [capistrano-multiconfig >= 3.0.8](https://github.com/railsware/capistrano-multiconfig)
32
- 10. [capistrano >= 3.0](https://github.com/capistrano/capistrano/)
33
- 11. [configliere >= 0.4](https://github.com/infochimps-platform/configliere)
34
- 12. [inquirer >= 0.2](https://github.com/arlimus/inquirer.rb)
35
- 13. [devnull >= 0.1](https://github.com/arlimus/inquirer.rb)
31
+ 9. [capistrano >= 3.0](https://github.com/capistrano/capistrano/)
32
+ 10. [configliere >= 0.4](https://github.com/infochimps-platform/configliere)
33
+ 11. [inquirer >= 0.2](https://github.com/arlimus/inquirer.rb)
34
+ 12. [devnull >= 0.1](https://github.com/arlimus/inquirer.rb)
35
+ 13. [versionomy >= 0.4.4](https://github.com/dazuma/versionomy)
36
36
 
37
37
  Compatibility
38
38
  -------------
@@ -46,7 +46,7 @@ Rubinius and Jruby support temporarily dropped due to Rails 4 incompatibility.
46
46
  Installation Instructions
47
47
  -------------------------
48
48
 
49
- Add the following to your Gemfile:
49
+ Add the following to your Gemfile after requiring **capistrano** and **capistrano-multiconfig**:
50
50
 
51
51
  ```ruby
52
52
  gem "capistrano_multiconfig_parallel"
Binary file
@@ -27,7 +27,7 @@ require 'stringio'
27
27
  # fix error with not files that can not be found
28
28
  Gem.find_files('composable_state_machine/**/*.rb').each { |path| require path }
29
29
 
30
- Gem.find_files('capistrano_multiconfig_parallel/initializers/**/*.rb').each { |path| require path }
30
+ Gem.find_files('capistrano_multiconfig_parallel/classes/**/*.rb').each { |path| require path }
31
31
  Gem.find_files('capistrano_multiconfig_parallel/helpers/**/*.rb').each { |path| require path }
32
32
  Gem.find_files('capistrano_multiconfig_parallel/celluloid/**/*.rb').each { |path| require path }
33
33
 
@@ -4,57 +4,33 @@ module CapistranoMulticonfigParallel
4
4
  class Application
5
5
  include Celluloid
6
6
  include Celluloid::Logger
7
+ include CapistranoMulticonfigParallel::StagesHelper
8
+ include CapistranoMulticonfigParallel::ApplicationHelper
7
9
 
8
- attr_accessor :stages,:stage_apps, :top_level_tasks, :jobs, :branch_backup, :condition, :manager, :dependency_tracker, :application, :stage, :name, :args, :argv, :default_stage
10
+ attr_reader :stages, :stage_apps, :top_level_tasks, :jobs, :branch_backup, :condition, :manager, :dependency_tracker, :application, :stage, :name, :args, :argv, :default_stage
9
11
 
10
12
  def initialize
11
13
  Celluloid.boot
12
14
  @stages = fetch_stages
13
- @stage_apps = multi_apps? ? @stages.map { |stage| stage.split(':').reverse[1] }.uniq : []
15
+ @stage_apps = multi_apps? ? @stages.map { |stage| stage.split(':').reverse[1] }.uniq : []
14
16
  collect_command_line_tasks(CapistranoMulticonfigParallel.original_args)
15
17
  @jobs = []
16
18
  end
17
19
 
18
-
19
20
  def start
20
- verify_app_dependencies(@stages) if multi_apps? && configuration.application_dependencies.present?
21
+ verify_app_dependencies if multi_apps? && configuration.application_dependencies.present?
21
22
  check_before_starting
22
23
  initialize_data
23
24
  run
24
25
  end
25
26
 
26
- def verify_app_dependencies(stages)
27
+ def verify_app_dependencies
27
28
  wrong = configuration.application_dependencies.find do |hash|
28
29
  !@stage_apps.include?(hash[:app]) || (hash[:dependencies].present? && hash[:dependencies].find { |val| !@stage_apps.include?(val) })
29
30
  end
30
- raise ArgumentError,"Invalid configuration for #{wrong.inspect}".red if wrong.present?
31
- end
32
-
33
-
34
- def fetch_stages
35
- fetch_stages_paths do |paths|
36
- paths.reject! { |path| check_stage_path(paths, path) }
37
- paths.sort if paths.present?
38
- end
39
- end
40
-
41
- def check_stage_path(paths, path)
42
- paths.any? { |another| another != path && another.start_with?(path + ':') }
43
- end
44
-
45
- def stages_paths
46
- stages_root = 'config/deploy'
47
- Dir["#{stages_root}/**/*.rb"].map do |file|
48
- file.slice(stages_root.size + 1..-4).tr('/', ':')
49
- end
50
- end
51
-
52
- def fetch_stages_paths
53
- stages_paths.tap { |paths| yield paths if block_given? }
31
+ raise ArgumentError, "Invalid configuration for #{wrong.inspect}".red if wrong.present?
54
32
  end
55
33
 
56
-
57
-
58
34
  def run_custom_command(options)
59
35
  custom_stages = fetch_multi_stages
60
36
  return if custom_stages.blank?
@@ -78,7 +54,6 @@ module CapistranoMulticonfigParallel
78
54
  @argv['BRANCH'] = nil
79
55
  end
80
56
 
81
-
82
57
  def custom_command?
83
58
  if multi_apps?
84
59
  !@stages.include?(@top_level_tasks.first) && custom_commands.values.include?(@top_level_tasks.first)
@@ -100,7 +75,6 @@ module CapistranoMulticonfigParallel
100
75
  CapistranoMulticonfigParallel.configuration
101
76
  end
102
77
 
103
-
104
78
  def initialize_data
105
79
  @application = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[1]
106
80
  @stage = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[0]
@@ -121,28 +95,6 @@ module CapistranoMulticonfigParallel
121
95
  @top_level_tasks.push(Rake.application.default_task_name) if @top_level_tasks.blank?
122
96
  end
123
97
 
124
- def parse_task_string(string) # :nodoc:
125
- /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
126
-
127
- name = Regexp.last_match(1)
128
- remaining_args = Regexp.last_match(2)
129
-
130
- return string, [] unless name
131
- return name, [] if remaining_args.empty?
132
-
133
- args = []
134
-
135
- loop do
136
- /((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
137
-
138
- remaining_args = Regexp.last_match(2)
139
- args << Regexp.last_match(1).gsub(/\\(.)/, '\1')
140
- break if remaining_args.blank?
141
- end
142
-
143
- [name, args]
144
- end
145
-
146
98
  def verify_options_custom_command(options)
147
99
  options[:action] = @argv['ACTION'].present? ? @argv['ACTION'] : 'deploy'
148
100
  options
@@ -181,10 +133,9 @@ module CapistranoMulticonfigParallel
181
133
  CapistranoMulticonfigParallel.find_loaded_gem('capistrano-gitflow').present?
182
134
  end
183
135
 
184
-
185
136
  def fetch_multi_stages
186
137
  custom_stages = @argv['STAGES'].blank? ? '' : @argv['STAGES']
187
- custom_stages = parse_inputted_value('value' => custom_stages).split(',').compact if custom_stages.present?
138
+ custom_stages = strip_characters_from_string(custom_stages).split(',').compact if custom_stages.present?
188
139
  custom_stages = custom_stages.present? ? custom_stages : [@default_stage]
189
140
  custom_stages
190
141
  end
@@ -267,6 +218,7 @@ module CapistranoMulticonfigParallel
267
218
  terminate
268
219
  end
269
220
 
221
+ # rubocop:disable CyclomaticComplexity
270
222
  def prepare_job(options)
271
223
  options = options.stringify_keys
272
224
  branch_name = options.fetch('branch', {})
@@ -302,24 +254,10 @@ module CapistranoMulticonfigParallel
302
254
  options
303
255
  end
304
256
 
305
- def parse_inputted_value(options = {})
306
- options = options.stringify_keys
307
- value = options['value'].present? ? options['value'] : nil
308
- if value.present?
309
- branch = value.gsub("\r\n", '')
310
- branch = branch.delete("\n") if branch.present?
311
- branch = branch.gsub(/\s+/, ' ') if branch.present?
312
- branch = branch.strip if branch.present?
313
- return branch
314
- else
315
- return ''
316
- end
317
- end
318
-
319
257
  def fetch_app_additional_env_options(variable)
320
258
  options = {}
321
259
  return options if variable.blank?
322
- env_options = parse_inputted_value('value' => variable)
260
+ env_options = strip_characters_from_string(variable)
323
261
  env_options = env_options.split(' ')
324
262
  options = multi_fetch_argv(env_options)
325
263
  options.stringify_keys!
@@ -337,7 +275,7 @@ module CapistranoMulticonfigParallel
337
275
  end
338
276
 
339
277
  def execute_on_multiple_boxes(main_box_name, options)
340
- boxes = parse_inputted_value('value' => main_box_name).split(',').compact
278
+ boxes = strip_characters_from_string(main_box_name).split(',').compact
341
279
  boxes.each do |box_name|
342
280
  options['env_options']['BOX'] = box_name
343
281
  prepare_job(options)
@@ -1,24 +1,42 @@
1
1
  # base module that has the statis methods that this gem is using
2
2
  module CapistranoMulticonfigParallel
3
-
4
3
  ENV_KEY_JOB_ID = 'multi_cap_job_id'
5
- MULTI_KEY = 'multi'
6
- SINGLE_KEY = 'single'
7
4
  GITFLOW_TAG_STAGING_TASK = 'gitflow:tag_staging'
8
5
  GITFLOW_CALCULATE_TAG_TASK = 'gitflow:calculate_tag'
9
6
  GITFLOW_VERIFY_UPTODATE_TASK = 'gitflow:verify_up_to_date'
10
7
 
11
- CUSTOM_COMMANDS = {
12
- CapistranoMulticonfigParallel::MULTI_KEY => {
13
- stages: 'deploy_multi_stages'
14
- },
15
- CapistranoMulticonfigParallel::SINGLE_KEY => {
16
- stages: 'deploy_multi_stages'
17
- }
18
- }
19
-
20
8
  class << self
21
- include CapistranoMulticonfigParallel::Helper
9
+ attr_accessor :logger, :original_args
10
+
22
11
  include CapistranoMulticonfigParallel::Configuration
12
+ include CapistranoMulticonfigParallel::ApplicationHelper
13
+ include CapistranoMulticonfigParallel::CoreHelper
14
+
15
+ def enable_logging
16
+ enable_file_logging
17
+ self.logger ||= ::Logger.new(DevNull.new)
18
+ Celluloid.logger = CapistranoMulticonfigParallel.logger
19
+ Celluloid.task_class = Celluloid::TaskThread
20
+ end
21
+
22
+ def enable_file_logging
23
+ return if configuration.multi_debug.to_s.downcase != 'true'
24
+ FileUtils.mkdir_p(log_directory) unless File.directory?(log_directory)
25
+ FileUtils.touch(main_log_file) unless File.file?(main_log_file)
26
+ log_file = File.open(main_log_file, 'w')
27
+ log_file.sync = true
28
+ self.logger = ::Logger.new(main_log_file)
29
+ end
30
+
31
+ def custom_commands
32
+ {
33
+ 'multi ' => {
34
+ stages: 'deploy_multi_stages'
35
+ },
36
+ 'single' => {
37
+ stages: 'deploy_multi_stages'
38
+ }
39
+ }
40
+ end
23
41
  end
24
42
  end
@@ -75,25 +75,34 @@ module CapistranoMulticonfigParallel
75
75
 
76
76
  def on_message(message)
77
77
  return unless message.present?
78
- debug("Rake worker #{@job_id} received after parse #{message}") # if debug_enabled?
78
+ log_debug('on_message', message)
79
79
  if @client.succesfull_subscription?(message)
80
- debug("Rake worker #{@job_id} received parse #{message}") if debug_enabled?
81
- @successfull_subscription = true
82
- publish_to_worker(task_data)
83
- elsif message['task'].present?
80
+ publish_subscription_successfull(message)
81
+ elsif msg_for_task?(message) || msg_for_stdin?(message)
84
82
  task_approval(message)
85
- elsif message['action'].present? && message['action'] == 'stdin'
86
83
  stdin_approval(message)
87
84
  else
88
85
  warn "unknown action: #{message.inspect}" if debug_enabled?
89
86
  end
90
87
  end
91
88
 
89
+ def log_debug(action, message)
90
+ debug("Rake worker #{@job_id} received after #{action}: #{message}") if debug_enabled?
91
+ end
92
+
92
93
  def msg_for_stdin?(message)
93
94
  message['action'] == 'stdin'
94
95
  end
95
96
 
96
- def publish_subscription_successfull
97
+ def msg_for_task?(message)
98
+ message['task'].present?
99
+ end
100
+
101
+ def publish_subscription_successfull(message)
102
+ return unless @client.succesfull_subscription?(message)
103
+ log_debug('publish_subscription_successfull', message)
104
+ @successfull_subscription = true
105
+ publish_to_worker(task_data)
97
106
  end
98
107
 
99
108
  def wait_for_stdin_input
@@ -104,7 +113,8 @@ module CapistranoMulticonfigParallel
104
113
  end
105
114
 
106
115
  def stdin_approval(message)
107
- if @job_id.to_i == message['job_id'].to_i && message['result'].present? && message['action'] == 'stdin'
116
+ return unless msg_for_stdin?(message)
117
+ if @job_id.to_i == message['job_id'].to_i && message['result'].present?
108
118
  @stdin_result = message['result']
109
119
  else
110
120
  warn "unknown invocation #{message.inspect}" if debug_enabled?
@@ -112,6 +122,7 @@ module CapistranoMulticonfigParallel
112
122
  end
113
123
 
114
124
  def task_approval(message)
125
+ return unless msg_for_task?(message)
115
126
  if @job_id.to_i == message['job_id'].to_i && message['task'] == task_name && message['approved'] == 'yes'
116
127
  @task_approved = true
117
128
  else
@@ -4,7 +4,7 @@ module CapistranoMulticonfigParallel
4
4
  class StandardDeploy
5
5
  include FileUtils
6
6
 
7
- attr_accessor :app, :stage, :action, :task_arguments, :env_options
7
+ attr_reader :app, :stage, :action, :task_arguments, :env_options
8
8
  def initialize(options)
9
9
  @app = options.fetch('app', '')
10
10
  @stage = options.fetch('env', '')
@@ -1,26 +1,44 @@
1
1
  require_relative './all'
2
- Gem.find_files('capistrano_multiconfig_parallel/extensions/**/*.rb').each { |path| require path }
2
+ Gem.find_files('capistrano_multiconfig_parallel/initializers/**/*.rb').each { |path| require path }
3
3
  module CapistranoMulticonfigParallel
4
4
  # this is the class that will be invoked from terminal , and willl use the invoke task as the primary function.
5
5
  class CLI
6
- # method used to start
7
- def self.start
8
- CapistranoMulticonfigParallel.check_terminal_tty
9
- CapistranoMulticonfigParallel.original_args = ARGV.dup
10
- CapistranoMulticonfigParallel.configuration_valid?
11
- job_manager = CapistranoMulticonfigParallel::Application.new
12
- if job_manager.argv[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID].blank?
13
- job_manager.start
14
- else
15
- Capistrano::Application.new.run
6
+ class << self
7
+ # method used to start
8
+ def start
9
+ verify_validation
10
+ start_work
11
+ rescue Interrupt
12
+ rescue_interrupt
13
+ rescue => error
14
+ rescue_error(error)
15
+ end
16
+
17
+ def rescue_interrupt
18
+ `stty icanon echo`
19
+ $stderr.puts 'Command cancelled.'
20
+ end
21
+
22
+ def rescue_error(error)
23
+ $stderr.puts error
24
+ $stderr.puts error.backtrace if error.respond_to?(:backtrace)
25
+ exit(1)
26
+ end
27
+
28
+ def verify_validation
29
+ CapistranoMulticonfigParallel.check_terminal_tty
30
+ CapistranoMulticonfigParallel.original_args = ARGV.dup
31
+ CapistranoMulticonfigParallel.configuration_valid?
32
+ end
33
+
34
+ def start_work
35
+ job_manager = CapistranoMulticonfigParallel::Application.new
36
+ if job_manager.argv[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID].blank?
37
+ job_manager.start
38
+ else
39
+ Capistrano::Application.new.run
40
+ end
16
41
  end
17
- rescue Interrupt
18
- `stty icanon echo`
19
- $stderr.puts 'Command cancelled.'
20
- rescue => error
21
- $stderr.puts error
22
- $stderr.puts error.backtrace if error.respond_to?(:backtrace)
23
- exit(1)
24
42
  end
25
43
  end
26
44
  end
@@ -0,0 +1,45 @@
1
+ require_relative './core_helper'
2
+ module CapistranoMulticonfigParallel
3
+ # class that holds the options that are configurable for this gem
4
+ module ApplicationHelper
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ def app_configuration
8
+ CapistranoMulticonfigParallel.configuration
9
+ end
10
+
11
+ def change_config_type(type)
12
+ ['boolean'].include?(type) ? type.delete(':').to_sym : type.constantize
13
+ end
14
+
15
+ def strip_characters_from_string(value)
16
+ return unless value.present?
17
+ value = value.delete("\r\n").delete("\n")
18
+ value = value.gsub(/\s+/, ' ').strip if value.present?
19
+ value
20
+ end
21
+
22
+ def parse_task_string(string) # :nodoc:
23
+ /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
24
+
25
+ name = Regexp.last_match(1)
26
+ remaining_args = Regexp.last_match(2)
27
+
28
+ return string, [] unless name
29
+ return name, [] if remaining_args.empty?
30
+
31
+ args = []
32
+
33
+ loop do
34
+ /((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
35
+
36
+ remaining_args = Regexp.last_match(2)
37
+ args << Regexp.last_match(1).gsub(/\\(.)/, '\1')
38
+ break if remaining_args.blank?
39
+ end
40
+
41
+ [name, args]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -4,14 +4,13 @@ module CapistranoMulticonfigParallel
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- attr_accessor :configuration
7
+ attr_reader :configuration
8
8
 
9
9
  def configuration
10
10
  @config ||= fetch_configuration
11
11
  @config
12
12
  end
13
13
 
14
-
15
14
  def fetch_configuration
16
15
  @fetched_config = Configliere::Param.new
17
16
  command_line_params.each do |param|
@@ -33,24 +32,11 @@ module CapistranoMulticonfigParallel
33
32
  @fetched_config.resolve!
34
33
  end
35
34
 
36
- def config_file
37
- File.join(CapistranoMulticonfigParallel.detect_root.to_s, 'config', 'multi_cap.yml')
38
- end
39
-
40
- def internal_config_directory
41
- File.join(CapistranoMulticonfigParallel.root.to_s, 'capistrano_multiconfig_parallel', 'initializers')
42
- end
43
-
44
35
  def command_line_params
45
36
  @default_config ||= YAML.load_file(File.join(internal_config_directory, 'default.yml'))['default_config']
46
37
  @default_config
47
38
  end
48
39
 
49
- def change_config_type(type)
50
- ['boolean'].include?(type) ? type.delete(':').to_sym : type.constantize
51
- end
52
-
53
-
54
40
  def verify_array_of_strings(value)
55
41
  return true if value.blank?
56
42
  value.reject(&:blank?)
@@ -72,8 +58,6 @@ module CapistranoMulticonfigParallel
72
58
  end
73
59
  end
74
60
 
75
-
76
-
77
61
  def check_boolean(c, prop)
78
62
  raise ArgumentError, "the property `#{prop}` must be boolean" unless %w(true false).include?(c[prop].to_s.downcase)
79
63
  end
@@ -1,10 +1,41 @@
1
1
  module CapistranoMulticonfigParallel
2
- module Helper
2
+ # class that holds the options that are configurable for this gem
3
+ module CoreHelper
3
4
  extend ActiveSupport::Concern
4
-
5
5
  included do
6
+ def config_file
7
+ File.join(detect_root.to_s, 'config', 'multi_cap.yml')
8
+ end
9
+
10
+ def internal_config_directory
11
+ File.join(root.to_s, 'capistrano_multiconfig_parallel', 'configuration')
12
+ end
6
13
 
7
- attr_accessor :logger, :original_args
14
+ def find_env_multi_cap_root
15
+ ENV['MULTI_CAP_ROOT']
16
+ end
17
+
18
+ def detect_root
19
+ if find_env_multi_cap_root
20
+ Pathname.new(find_env_multi_cap_root)
21
+ elsif defined?(::Rails)
22
+ ::Rails.root
23
+ else
24
+ try_detect_capfile
25
+ end
26
+ end
27
+
28
+ def log_directory
29
+ File.join(detect_root.to_s, 'log')
30
+ end
31
+
32
+ def main_log_file
33
+ File.join(log_directory, 'multi_cap.log')
34
+ end
35
+
36
+ def websokect_log_file
37
+ File.join(log_directory, 'multi_cap_websocket.log')
38
+ end
8
39
 
9
40
  def root
10
41
  File.expand_path(File.dirname(File.dirname(__dir__)))
@@ -26,72 +57,26 @@ module CapistranoMulticonfigParallel
26
57
  return nil
27
58
  end
28
59
 
29
- def log_directory
30
- File.join(CapistranoMulticonfigParallel.detect_root.to_s, 'log')
31
- end
32
-
33
- def main_log_file
34
- File.join(log_directory, 'multi_cap.log')
35
- end
36
-
37
- def websokect_log_file
38
- File.join(log_directory, 'multi_cap_websocket.log')
39
- end
40
-
41
- def enable_logging
42
- FileUtils.mkdir_p(log_directory) unless File.directory?(log_directory)
43
- if CapistranoMulticonfigParallel::CelluloidManager.debug_enabled.to_s.downcase == 'true'
44
- FileUtils.touch(main_log_file) unless File.file?(main_log_file)
45
- log_file = File.open(main_log_file, 'w')
46
- log_file.sync = true
47
- self.logger = ::Logger.new(main_log_file)
48
- else
49
- self.logger = ::Logger.new(DevNull.new)
50
- end
51
- Celluloid.logger = CapistranoMulticonfigParallel.logger
52
- Celluloid.task_class = Celluloid::TaskThread
53
- end
54
-
55
60
  def log_message(message)
56
61
  return unless logger.present?
57
- error_message = message.respond_to?(:message) ? message.message : message.inspect
58
- err_backtrace = message.respond_to?(:backtrace) ? message.backtrace.join("\n\n") : ''
59
- if err_backtrace.present?
60
- logger.debug(
62
+ logger.debug(
61
63
  class_name: message.class,
62
- message: error_message,
63
- backtrace: err_backtrace
64
- )
65
- else
66
- logger.debug(message)
67
- end
68
- end
69
-
70
-
71
- def detect_root
72
- if ENV['MULTI_CAP_ROOT']
73
- Pathname.new(ENV['MULTI_CAP_ROOT'])
74
- elsif defined?(::Rails)
75
- ::Rails.root
76
- else
77
- try_detect_capfile
78
- end
64
+ message: message.respond_to?(:message) ? message.message : message.inspect,
65
+ backtrace: message.respond_to?(:backtrace) ? message.backtrace.join("\n\n") : ''
66
+ )
79
67
  end
80
68
 
81
69
  def try_detect_capfile
82
70
  root = Pathname.new(FileUtils.pwd)
83
71
  root = root.parent unless root.directory?
84
72
  root = root.parent until root.children.find { |f| f.file? && f.basename.to_s.downcase == 'capfile' }.present? || root.root?
85
- raise "Can't detect Capfile in the application root".red if root.root?
73
+ fail "Can't detect Capfile in the application root".red if root.root?
86
74
  root
87
75
  end
88
76
 
89
77
  def find_loaded_gem(name)
90
- Gem.loaded_specs.values.detect{|repo| repo.name == name }
78
+ Gem.loaded_specs.values.find { |repo| repo.name == name }
91
79
  end
92
-
93
-
94
-
95
80
  end
96
81
  end
97
82
  end
@@ -0,0 +1,33 @@
1
+ module CapistranoMulticonfigParallel
2
+ # module used to fetch the stages (code taken from https://github.com/railsware/capistrano-multiconfig)
3
+ # TODO: find a way to do this without copying code. Can't currently use gem specification to require that gem
4
+ # because that is only compatible with capistrano version 3
5
+ module StagesHelper
6
+ module_function
7
+
8
+ def fetch_stages
9
+ fetch_stages_paths do |paths|
10
+ checks_paths(paths)
11
+ end
12
+ end
13
+
14
+ def checks_paths(paths)
15
+ paths.reject! { |path| check_stage_path(paths, path) }.uniq.sort
16
+ end
17
+
18
+ def check_stage_path(paths, path)
19
+ paths.any? { |another| another != path && another.start_with?(path + ':') }
20
+ end
21
+
22
+ def stages_paths
23
+ stages_root = 'config/deploy'
24
+ Dir["#{stages_root}/**/*.rb"].map do |file|
25
+ file.slice(stages_root.size + 1..-4).tr('/', ':')
26
+ end
27
+ end
28
+
29
+ def fetch_stages_paths
30
+ stages_paths.tap { |paths| yield paths if block_given? }
31
+ end
32
+ end
33
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../helpers/rake_hook_actor'
1
+ require_relative '../classes/rake_hook_actor'
2
2
  Rake::Task.class_eval do
3
3
  alias_method :original_execute, :execute
4
4
 
@@ -7,8 +7,8 @@ module CapistranoMulticonfigParallel
7
7
  # module used for generating the version
8
8
  module VERSION
9
9
  MAJOR = 0
10
- MINOR = 16
11
- TINY = 2
10
+ MINOR = 17
11
+ TINY = 0
12
12
  PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano_multiconfig_parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-02 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-pmap
@@ -628,17 +628,19 @@ files:
628
628
  - lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
629
629
  - lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb
630
630
  - lib/capistrano_multiconfig_parallel/celluloid/web_server.rb
631
+ - lib/capistrano_multiconfig_parallel/classes/dependency_tracker.rb
632
+ - lib/capistrano_multiconfig_parallel/classes/input_stream.rb
633
+ - lib/capistrano_multiconfig_parallel/classes/interactive_menu.rb
634
+ - lib/capistrano_multiconfig_parallel/classes/output_stream.rb
635
+ - lib/capistrano_multiconfig_parallel/classes/rake_hook_actor.rb
636
+ - lib/capistrano_multiconfig_parallel/classes/standard_deploy.rb
631
637
  - lib/capistrano_multiconfig_parallel/cli.rb
632
- - lib/capistrano_multiconfig_parallel/extensions/rake.rb
638
+ - lib/capistrano_multiconfig_parallel/configuration/default.yml
639
+ - lib/capistrano_multiconfig_parallel/helpers/application_helper.rb
633
640
  - lib/capistrano_multiconfig_parallel/helpers/configuration.rb
634
- - lib/capistrano_multiconfig_parallel/helpers/dependency_tracker.rb
635
- - lib/capistrano_multiconfig_parallel/helpers/helper.rb
636
- - lib/capistrano_multiconfig_parallel/helpers/input_stream.rb
637
- - lib/capistrano_multiconfig_parallel/helpers/interactive_menu.rb
638
- - lib/capistrano_multiconfig_parallel/helpers/output_stream.rb
639
- - lib/capistrano_multiconfig_parallel/helpers/rake_hook_actor.rb
640
- - lib/capistrano_multiconfig_parallel/helpers/standard_deploy.rb
641
- - lib/capistrano_multiconfig_parallel/initializers/default.yml
641
+ - lib/capistrano_multiconfig_parallel/helpers/core_helper.rb
642
+ - lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb
643
+ - lib/capistrano_multiconfig_parallel/initializers/rake.rb
642
644
  - lib/capistrano_multiconfig_parallel/version.rb
643
645
  homepage: http://github.com/bogdanRada/capistrano_multiconfig_parallel/
644
646
  licenses: