capistrano_multiconfig_parallel 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b470f4de93b37af27d50688a0727461af844e4e
4
- data.tar.gz: c270b935db211232b3150c225db50eff605c0b03
3
+ metadata.gz: 8b780bcf8adad1a2bf148a693c85c6f20d3447ca
4
+ data.tar.gz: 202318a839cbfdbaa4465cbe2c0f1889f8cbc531
5
5
  SHA512:
6
- metadata.gz: 4bba067afc7d3e6728ae82eb23a0b2f0b5701ca81f5a9ed876d821b9ec41d7cbd620f5afddf953faaacbc156b632d9305e0865ca336b73d221c5a2aeec8bf445
7
- data.tar.gz: 5dcab7ebf63b73e79b89e8f4301ac126860a4b369178e99eba7af512cb7bdc492b68e022ce8726840d85834255c1c6863a0fd764cf5ce58c444a346dc9f8e99d
6
+ metadata.gz: d5881082a7933b6acc37ee0b01c4c1b6fb3a595c85c6b90dcaf32c200ebd2f5bd1a37295220c7a0d566a576562738c791cda799d8a7417363d38fc3afe097c2a
7
+ data.tar.gz: b9327016b1d9bb84cdebc51f58f0f458b51bb42f7d0529c981b73b9fd1d65e4b7808b8cd3379b13620178d041a9c4d80b1cadf0d20117c6a3a7ee8fbbb5bf61d
data/README.md CHANGED
@@ -40,6 +40,7 @@ Requirements
40
40
  12. [capistrano >= 3.0] [capistrano]
41
41
  13. [configliere >= 0.4] [configliere]
42
42
  14. [inquirer >= 0.2] [inquirer]
43
+ 14. [devnull >= 0.1] [inquirer]
43
44
 
44
45
  [ruby]: http://www.ruby-lang.org
45
46
  [activesupport]:https://rubygems.org/gems/activesupport
@@ -55,6 +56,7 @@ Requirements
55
56
  [capistrano]: https://github.com/capistrano/capistrano/
56
57
  [configliere]: https://github.com/infochimps-platform/configliere
57
58
  [inquirer]: https://github.com/arlimus/inquirer.rb
59
+ [devnull]: https://github.com/maraigue/devnull
58
60
 
59
61
  Compatibility
60
62
  --------
@@ -193,11 +195,15 @@ Also the script will ask if there are any other environment variables that user
193
195
 
194
196
  bundle exec multi_cap deploy_multi_stages STAGES=development, staging, production
195
197
  ```
198
+ NOTE: IF you want to execute a different command on all stages, you can specify environment variable **ACTION=<task_name>** either when you specify the STAGES, or can be done
199
+ individually for each task when prompted about additional ENV options
196
200
 
197
201
  If a branch is specified using "BRANCH=name" it will deploy same branch to all stages.The branch environment variable is then passed to the capistrano task
198
202
 
199
203
  Also the script will ask if there are any other environment variables that user might want to pass to each of the stages separately.
200
204
 
205
+ If you use **capistrano-gitflow**, the workers will first deploy to all the other stages
206
+ and only after staging is tagged , will trigger a new worker to start deploying to production
201
207
 
202
208
 
203
209
  ## 2.) Multiple Apps ( like [Caphub][caphub] )
@@ -250,9 +256,16 @@ Will ask user if he wants to deploy the apps "foo" and "bar" , since they appear
250
256
  bundle exec multi_cap deploy_multi_stages STAGES=development, staging, production
251
257
  ```
252
258
 
259
+ NOTE: IF you want to execute a different command on all stages, you can specify environment variable **ACTION=<task_name>** either when you specify the STAGES, or can be done
260
+ individually for each task when prompted about additional ENV options
261
+
253
262
  If a branch is specified using **BRANCH=<name>** it will deploy same branch to all stages.The branch environment variable is then passed to the capistrano task
254
263
  If you want different branches , capistrano will ask for additional ENV options for each stage, and can be specified then for each stage
255
264
 
265
+ If you use **capistrano-gitflow**, the workers will first deploy to all the other stages
266
+ and only after staging is tagged , will trigger a new worker to start deploying to production
267
+
268
+
256
269
  Testing
257
270
  --------
258
271
 
@@ -1,4 +1,3 @@
1
- Gem.find_files('capistrano_multiconfig_parallel/extensions/**/*.rb').each { |path| require path }
2
1
  module CapistranoMulticonfigParallel
3
2
  # class used as a wrapper around capistrano
4
3
  class Application < Capistrano::Application
@@ -5,8 +5,10 @@ module CapistranoMulticonfigParallel
5
5
  ENV_KEY_JOB_ID = 'multi_cap_job_id'
6
6
  MULTI_KEY = 'multi'
7
7
  SINGLE_KEY = 'single'
8
- GITFLOW_TAG_STAGING_TASK = "gitflow:tag_staging"
9
-
8
+ GITFLOW_TAG_STAGING_TASK = "gitflow:tag_staging"
9
+ GITFLOW_CALCULATE_TAG_TASK = 'gitflow:calculate_tag'
10
+ GITFLOW_VERIFY_UPTODATE_TASK = 'gitflow:verify_up_to_date'
11
+
10
12
  CUSTOM_COMMANDS = {
11
13
  CapistranoMulticonfigParallel::MULTI_KEY => {
12
14
  stages: 'deploy_multi_stages'
@@ -107,17 +107,20 @@ module CapistranoMulticonfigParallel
107
107
  end
108
108
 
109
109
  def apply_confirmations?
110
- CapistranoMulticonfigParallel.configuration.task_confirmation_active.to_s.downcase == 'true' &&
111
- CapistranoMulticonfigParallel.configuration.apply_stage_confirmation.include?(@job_manager.stage)
110
+ CapistranoMulticonfigParallel.configuration.task_confirmation_active.to_s.downcase == 'true'
112
111
  end
113
112
 
114
113
  def syncronized_confirmation?
115
- CapistranoMulticonfigParallel.configuration.syncronize_confirmation.to_s.downcase == 'true' &&
116
- !@job_manager.executes_deploy_stages?
114
+ (CapistranoMulticonfigParallel.configuration.syncronize_confirmation.to_s.downcase == 'true' && !@job_manager.executes_deploy_stages? ) ||
115
+ (@job_manager.executes_deploy_stages? && @job_manager.confirmation_applies_to_all_workers?)
116
+ end
117
+
118
+ def apply_confirmation_for_worker(worker)
119
+ worker.alive? && CapistranoMulticonfigParallel.configuration.apply_stage_confirmation.include?(worker.env_name)
117
120
  end
118
121
 
119
122
  def setup_worker_conditions(worker)
120
- return unless apply_confirmations?
123
+ return if !apply_confirmation_for_worker(worker) || !apply_confirmations?
121
124
  hash_conditions = {}
122
125
  CapistranoMulticonfigParallel.configuration.task_confirmations.each do |task|
123
126
  hash_conditions[task] = { condition: Celluloid::Condition.new, status: 'unconfirmed' }
@@ -126,7 +129,7 @@ module CapistranoMulticonfigParallel
126
129
  end
127
130
 
128
131
  def mark_completed_remaining_tasks(worker)
129
- return unless apply_confirmations?
132
+ return if !apply_confirmation_for_worker(worker) || !apply_confirmations?
130
133
  CapistranoMulticonfigParallel.configuration.task_confirmations.each_with_index do |task, _index|
131
134
  fake_result = proc { |sum| sum }
132
135
  task_confirmation = @job_to_condition[worker.job_id][task]
@@ -138,7 +141,7 @@ module CapistranoMulticonfigParallel
138
141
  end
139
142
 
140
143
  def wait_task_confirmations_worker(worker)
141
- return if !apply_confirmations? || syncronized_confirmation?
144
+ return if !apply_confirmations? || !apply_confirmation_for_worker(worker) || syncronized_confirmation?
142
145
  CapistranoMulticonfigParallel.configuration.task_confirmations.each_with_index do |task, _index|
143
146
  result = wait_condition_for_task(worker.job_id, task)
144
147
  confirm_task_approval(result, task, worker) if result.present?
@@ -150,7 +153,8 @@ module CapistranoMulticonfigParallel
150
153
  end
151
154
 
152
155
  def wait_task_confirmations
153
- return if !apply_confirmations? || !syncronized_confirmation?
156
+ stage_apply = CapistranoMulticonfigParallel.configuration.apply_stage_confirmation.include?(@job_manager.stage)
157
+ return if !apply_confirmations? || !stage_apply || !syncronized_confirmation?
154
158
  CapistranoMulticonfigParallel.configuration.task_confirmations.each_with_index do |task, _index|
155
159
  results = []
156
160
  @jobs.pmap do |job_id, _job|
@@ -199,7 +203,7 @@ module CapistranoMulticonfigParallel
199
203
  end
200
204
 
201
205
  def can_tag_staging?
202
- @job_manager.is_able_to_tag_staging? &&
206
+ @job_manager.can_tag_staging? &&
203
207
  @jobs.detect{|job_id, job| job['env'] == 'production'}.blank?
204
208
  end
205
209
 
@@ -126,7 +126,7 @@ module CapistranoMulticonfigParallel
126
126
 
127
127
  def handle_subscription(message)
128
128
  if message_is_about_a_task?(message)
129
- if @env_name == 'staging' && @manager.can_tag_staging? && has_executed_task?(CapistranoMulticonfigParallel::GITFLOW_TAG_STAGING_TASK)
129
+ if @env_name == 'staging' && @manager.can_tag_staging? && has_executed_task?(CapistranoMulticonfigParallel::GITFLOW_VERIFY_UPTODATE_TASK)
130
130
  @manager.dispatch_new_job(@job.merge('env' => 'production'))
131
131
  end
132
132
  save_tasks_to_be_executed(message)
@@ -1,4 +1,5 @@
1
1
  require_relative './all'
2
+ Gem.find_files('capistrano_multiconfig_parallel/extensions/**/*.rb').each { |path| require path }
2
3
  module CapistranoMulticonfigParallel
3
4
  # this is the class that will be invoked from terminal , and willl use the invoke task as the primary function.
4
5
  class CLI
@@ -6,7 +6,7 @@ module CapistranoMulticonfigParallel
6
6
  include Celluloid
7
7
  include Celluloid::Logger
8
8
 
9
- attr_accessor :condition, :manager, :deps, :application, :stage, :name, :args, :argv, :jobs, :job_registered_condition, :default_stage
9
+ attr_accessor :condition, :manager, :deps, :application, :stage, :name, :args, :argv, :jobs, :job_registered_condition, :default_stage, :original_argv
10
10
 
11
11
  def initialize(cap_app, top_level_tasks, stages)
12
12
  @cap_app = cap_app
@@ -51,10 +51,17 @@ module CapistranoMulticonfigParallel
51
51
  @name, @args = @cap_app.parse_task_string(@top_level_tasks.second)
52
52
  @argv = @cap_app.handle_options.delete_if { |arg| arg == @stage || arg == @name || arg == @top_level_tasks.first }
53
53
  @argv = multi_fetch_argv(@argv)
54
+ @original_argv = @argv.clone
54
55
  block.call if block_given?
55
56
  run
56
57
  end
57
58
 
59
+ def verify_options_custom_command(options)
60
+ options[:action] = @argv['ACTION'].present? ? @argv['ACTION'] : 'deploy'
61
+ @argv = @argv['ACTION'].present? ? @argv.except('ACTION') : @argv
62
+ options
63
+ end
64
+
58
65
  def check_before_starting
59
66
  @condition = Celluloid::Condition.new
60
67
  @manager = CapistranoMulticonfigParallel::CelluloidManager.new(Actor.current)
@@ -78,7 +85,10 @@ module CapistranoMulticonfigParallel
78
85
 
79
86
  def tag_staging_exists? # check exists task from capistrano-gitflow
80
87
  begin
81
- Rake::Task[CapistranoMulticonfigParallel::GITFLOW_TAG_STAGING_TASK].present?
88
+ rake1 = Rake::Task[CapistranoMulticonfigParallel::GITFLOW_TAG_STAGING_TASK]
89
+ rake2 = Rake::Task[GITFLOW_CALCULATE_TAG_TASK]
90
+ rake3 = Rake::Task[GITFLOW_VERIFY_UPTODATE_TASK]
91
+ rake1.present? && rake2.present? && rake3.present? && rake2.prerequisites.present? && rake2.actions.present? && rake3.prerequisites.present?
82
92
  rescue
83
93
  return false
84
94
  end
@@ -86,6 +96,7 @@ module CapistranoMulticonfigParallel
86
96
 
87
97
  def fetch_multi_stages
88
98
  stages = @argv['STAGES'].blank? ? '' : @argv['STAGES']
99
+ @argv = @argv['STAGES'].present? ? @argv.except('STAGES') : @argv
89
100
  stages = parse_inputted_value(value: stages).split(',').compact if stages.present?
90
101
  stages.present? ? stages : [@default_stage]
91
102
  end
@@ -94,12 +105,12 @@ module CapistranoMulticonfigParallel
94
105
  (!custom_command? && @stage == 'production') || (custom_command? && fetch_multi_stages.include?("production"))
95
106
  end
96
107
 
97
- def is_able_to_tag_staging?
108
+ def can_tag_staging?
98
109
  using_git? && wants_deploy_production? && tag_staging_exists?
99
110
  end
100
111
 
101
112
  def check_multi_stages(stages)
102
- is_able_to_tag_staging? ? stages.reject{|u| u == 'production'} : stages
113
+ can_tag_staging? ? stages.reject{|u| u == 'production'} : stages
103
114
  end
104
115
 
105
116
  def deploy_app(options = {})
@@ -121,6 +132,11 @@ module CapistranoMulticonfigParallel
121
132
  fetch_app_additional_env_options
122
133
  end
123
134
 
135
+ def confirmation_applies_to_all_workers?
136
+ environments = @jobs.map{|job| job['env']}
137
+ CapistranoMulticonfigParallel.configuration.apply_stage_confirmation.all? { |e| environments.include?(e) }
138
+ end
139
+
124
140
  private
125
141
 
126
142
  def call_task_deploy_app(options = {})
@@ -167,17 +183,21 @@ module CapistranoMulticonfigParallel
167
183
  options['env_options'] = options['env_options'].reverse_merge(env_opts.except('BOX'))
168
184
 
169
185
  env_options = branch_name.present? ? { 'BRANCH' => branch_name }.merge(options['env_options']) : options['env_options']
170
-
186
+ job_env_options = custom_command? && env_options['ACTION'].present? ? env_options.except('ACTION') : env_options
187
+
188
+
171
189
  job = {
172
190
  app: app,
173
191
  env: options['stage'],
174
- action: options['action'],
192
+ action: custom_command? ? env_options['ACTION'] : options['action'],
175
193
  task_arguments: options['task_arguments'],
176
- env_options: env_options
194
+ env_options: job_env_options
177
195
  }
178
-
196
+ job = job.stringify_keys
179
197
  @jobs << job
180
198
  end
199
+
200
+
181
201
 
182
202
  def prepare_options(options)
183
203
  options = options.stringify_keys
@@ -37,7 +37,7 @@ module CapistranoMulticonfigParallel
37
37
  def run_custom_command(options)
38
38
  return unless custom_command?
39
39
  CapistranoMulticonfigParallel.interactive_menu = true
40
- options[:action] = @argv['ACTION'].present? ? @argv['ACTION'].present? : 'deploy'
40
+ options = verify_options_custom_command(options)
41
41
  action_name = @name
42
42
  if action_name == custom_commands[:stages]
43
43
  multi_stage_deploy(options)
@@ -17,6 +17,7 @@ module CapistranoMulticonfigParallel
17
17
 
18
18
  def run_custom_command(options)
19
19
  return unless custom_command?
20
+ options = verify_options_custom_command(options)
20
21
  action_name = @name
21
22
  if action_name == custom_commands[:stages]
22
23
  stage_deploy(options)
@@ -32,7 +33,7 @@ module CapistranoMulticonfigParallel
32
33
  stages = check_multi_stages(stages)
33
34
  collect_jobs(options) do |new_options|
34
35
  stages.each do |stage|
35
- deploy_app(new_options.merge('stage' => stage, 'action' => 'deploy'))
36
+ deploy_app(new_options.merge('stage' => stage))
36
37
  end
37
38
  end
38
39
  end
@@ -8,7 +8,7 @@ module CapistranoMulticonfigParallel
8
8
  module VERSION
9
9
  MAJOR = 0
10
10
  MINOR = 6
11
- TINY = 2
11
+ TINY = 3
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.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-pmap