Class: Command::Base
- Inherits:
-
Object
show all
- Includes:
- Helpers
- Defined in:
- lib/command/base.rb
Overview
rubocop:disable Metrics/ClassLength
Direct Known Subclasses
AiGithubFlowPrompt, ApplyTemplate, BuildImage, CleanupImages, CleanupStaleApps, Config, CopyImageFromUpstream, Delete, DeployImage, Doctor, Env, Exists, Generate, GenerateGithubActions, GithubFlowReadiness, Info, LatestImage, Logs, Maintenance, MaintenanceOff, MaintenanceOn, MaintenanceSetPage, NoCommand, Open, OpenConsole, PromoteAppFromUpstream, Ps, PsRestart, PsStart, PsStop, PsWait, Run, SetupApp, Terraform::Base, Test, UpdateGithubActions, Version
Constant Summary
collapse
- VALIDATIONS_WITHOUT_ADDITIONAL_OPTIONS =
%w[config].freeze
- VALIDATIONS_WITH_ADDITIONAL_OPTIONS =
%w[templates].freeze
- ALL_VALIDATIONS =
VALIDATIONS_WITHOUT_ADDITIONAL_OPTIONS + VALIDATIONS_WITH_ADDITIONAL_OPTIONS
- SUBCOMMAND_NAME =
Used to call the command (cpflow SUBCOMMAND_NAME NAME)
nil
- USAGE =
Used to call the command (cpflow NAME)
NAME = ""
Displayed when running cpflow help or cpflow help NAME (defaults to NAME)
""
- REQUIRES_ARGS =
Throws error if true and no arguments are passed to the command
or if false and arguments are passed to the command
false
- DEFAULT_ARGS =
Default arguments if none are passed to the command
[].freeze
- OPTIONS =
Options for the command (use option methods below)
[].freeze
false
- EXAMPLES =
Displayed when running cpflow help
DESCRIPTION = ""
Displayed when running cpflow help NAME
LONG_DESCRIPTION = ""
Displayed along with LONG_DESCRIPTION when running cpflow help NAME
""
- HIDE =
If true, hides the command from cpflow help
false
true
- VALIDATIONS =
Which validations to run before the command
%w[config].freeze
- REQUIRES_STARTUP_CHECKS =
Whether or not to run CLI startup checks such as cpln availability and update checks
true
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#args_join(args) ⇒ Object
NOTE: use simplified variant atm, as shelljoin do different escaping TODO: most probably need better logic for escaping various quotes.
-
#bind_shared_secret_policy_grant(grant, policy) ⇒ Object
-
#bind_shared_secret_policy_grants(grant_policy_pairs) ⇒ Object
-
#cp ⇒ Object
-
#ensure_docker_running! ⇒ Object
-
#ensure_shared_secret_policy_targets_secret!(grant, policy) ⇒ Object
-
#identity_bound_to_policy_with_reveal?(policy) ⇒ Boolean
-
#identity_policy_permissions(policy) ⇒ Object
-
#initialize(config) ⇒ Base
constructor
-
#progress ⇒ Object
-
#resolve_shared_secret_policy_grant(grant) ⇒ Object
-
#resolve_shared_secret_policy_grants ⇒ Object
-
#run_command_in_latest_image(command, title:) ⇒ Object
-
#run_cpflow_command(command, *args) ⇒ Object
-
#shared_secret_policy_missing_message(grant) ⇒ Object
-
#shared_secret_policy_target_links(grant) ⇒ Object
-
#shared_secret_policy_targets_secret?(grant, policy) ⇒ Boolean
-
#step(message, abort_on_error: true, retry_on_failure: false, max_retry_count: 1000, wait: 1, &block) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#step_finish(success, abort_on_error: true) ⇒ Object
-
#wait_for_workloads_ready(workloads, reverse: false) ⇒ Object
-
#with_retry(max_retry_count:, wait:) ⇒ Object
Methods included from Helpers
normalize_command_name, normalize_option_name, random_four_digits, strip_str_and_validate
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
46
47
48
|
# File 'lib/command/base.rb', line 46
def initialize(config)
@config = config
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7
8
9
|
# File 'lib/command/base.rb', line 7
def config
@config
end
|
Class Method Details
.add_app_identity_option(required: false) ⇒ Object
473
474
475
476
477
478
479
480
481
482
|
# File 'lib/command/base.rb', line 473
def self.add_app_identity_option(required: false)
{
name: :add_app_identity,
params: {
desc: "Adds app identity template if it does not exist",
type: :boolean,
required: required
}
}
end
|
.all_commands ⇒ Object
rubocop:disable Metrics/MethodLength
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/command/base.rb', line 50
def self.all_commands Dir["#{__dir__}/**/*.rb"].each_with_object({}) do |file, result|
content = File.read(file, encoding: "UTF-8")
classname = content.match(/^\s+class (?!Base\b)(\w+) < (?:.*(?!Command::)Base)(?:$| .*$)/)&.captures&.first
next unless classname
namespaces = content.scan(/^\s+module (\w+)/).flatten
full_classname = [*namespaces, classname].join("::").prepend("::")
command_key = File.basename(file, ".rb")
prefix = namespaces[1..].map(&:downcase).join("_")
command_key.prepend(prefix.concat("_")) unless prefix.empty?
result[command_key.to_sym] = Object.const_get(full_classname)
end
end
|
.all_options ⇒ Object
rubocop:enable Metrics/MethodLength
520
521
522
|
# File 'lib/command/base.rb', line 520
def self.all_options
methods.grep(/_option$/).map { |method| send(method.to_s) }
end
|
.all_options_by_key_name ⇒ Object
524
525
526
527
528
529
|
# File 'lib/command/base.rb', line 524
def self.all_options_by_key_name
all_options.each_with_object({}) do |option, result|
option[:params][:aliases]&.each { |current_alias| result[current_alias.to_s] = option }
result["--#{option[:name]}"] = option
end
end
|
.app_option(required: false) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/command/base.rb', line 86
def self.app_option(required: false)
{
name: :app,
params: {
aliases: ["-a"],
banner: "APP_NAME",
desc: "Application name",
type: :string,
required: required
}
}
end
|
.commit_option(required: false) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/command/base.rb', line 153
def self.commit_option(required: false)
{
name: :commit,
params: {
aliases: ["-c"],
banner: "COMMIT_HASH",
desc: "Commit hash",
type: :string,
required: required
}
}
end
|
.common_options ⇒ Object
68
69
70
|
# File 'lib/command/base.rb', line 68
def self.common_options
[org_option, verbose_option, trace_option]
end
|
.cpu_option(required: false) ⇒ Object
394
395
396
397
398
399
400
401
402
403
404
405
406
|
# File 'lib/command/base.rb', line 394
def self.cpu_option(required: false)
{
name: :cpu,
params: {
banner: "CPU",
desc: "Overrides CPU millicores " \
"(e.g., '100m' for 100 millicores, '1' for 1 core)",
type: :string,
required: required,
valid_regex: /^\d+m?$/
}
}
end
|
.detached_option(required: false) ⇒ Object
383
384
385
386
387
388
389
390
391
392
|
# File 'lib/command/base.rb', line 383
def self.detached_option(required: false)
{
name: :detached,
params: {
desc: "Runs non-interactive command, detaches, and prints commands to log and stop the job",
type: :boolean,
required: required
}
}
end
|
.dir_option(required: false) ⇒ Object
495
496
497
498
499
500
501
502
503
504
505
|
# File 'lib/command/base.rb', line 495
def self.dir_option(required: false)
{
name: :dir,
params: {
banner: "DIR",
desc: "Output directory",
type: :string,
required: required
}
}
end
|
.docker_context_option ⇒ Object
484
485
486
487
488
489
490
491
492
493
|
# File 'lib/command/base.rb', line 484
def self.docker_context_option
{
name: :docker_context,
params: {
desc: "Path to the docker build context directory",
type: :string,
required: false
}
}
end
|
.domain_option(required: false) ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/command/base.rb', line 179
def self.domain_option(required: false)
{
name: :domain,
params: {
banner: "DOMAIN_NAME",
desc: "Domain name",
type: :string,
required: required
}
}
end
|
.entrypoint_option(required: false) ⇒ Object
422
423
424
425
426
427
428
429
430
431
432
433
434
|
# File 'lib/command/base.rb', line 422
def self.entrypoint_option(required: false)
{
name: :entrypoint,
params: {
banner: "ENTRYPOINT",
desc: "Overrides entrypoint " \
"(must be a single command or a script path that exists in the container)",
type: :string,
required: required,
valid_regex: /^\S+$/
}
}
end
|
.force_option(required: false) ⇒ Object
334
335
336
337
338
339
340
341
342
343
|
# File 'lib/command/base.rb', line 334
def self.force_option(required: false)
{
name: :force,
params: {
desc: "Overwrite existing generated files",
type: :boolean,
required: required
}
}
end
|
.image_option(required: false) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/command/base.rb', line 126
def self.image_option(required: false)
{
name: :image,
params: {
aliases: ["-i"],
banner: "IMAGE_NAME",
desc: "Image name",
type: :string,
required: required
}
}
end
|
.interactive_option(required: false) ⇒ Object
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/command/base.rb', line 372
def self.interactive_option(required: false)
{
name: :interactive,
params: {
desc: "Runs interactive command",
type: :boolean,
required: required
}
}
end
|
.location_option(required: false) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/command/base.rb', line 166
def self.location_option(required: false)
{
name: :location,
params: {
aliases: ["-l"],
banner: "LOCATION_NAME",
desc: "Location name",
type: :string,
required: required
}
}
end
|
.log_method_option(required: false) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/command/base.rb', line 139
def self.log_method_option(required: false)
{
name: :log_method,
params: {
type: :numeric,
banner: "LOG_METHOD",
desc: "Log method",
required: required,
valid_values: [1, 2, 3],
default: 3
}
}
end
|
.logs_limit_option(required: false) ⇒ Object
345
346
347
348
349
350
351
352
353
354
355
356
|
# File 'lib/command/base.rb', line 345
def self.logs_limit_option(required: false)
{
name: :limit,
params: {
banner: "NUMBER",
desc: "Limit on number of log entries to show",
type: :numeric,
required: required,
default: 200
}
}
end
|
.logs_since_option(required: false) ⇒ Object
358
359
360
361
362
363
364
365
366
367
368
369
370
|
# File 'lib/command/base.rb', line 358
def self.logs_since_option(required: false)
{
name: :since,
params: {
banner: "DURATION",
desc: "Loopback window for showing logs " \
"(see https://www.npmjs.com/package/parse-duration for the accepted formats, e.g., '1h')",
type: :string,
required: required,
default: "1h"
}
}
end
|
.memory_option(required: false) ⇒ Object
408
409
410
411
412
413
414
415
416
417
418
419
420
|
# File 'lib/command/base.rb', line 408
def self.memory_option(required: false)
{
name: :memory,
params: {
banner: "MEMORY",
desc: "Overrides memory size " \
"(e.g., '100Mi' for 100 mebibytes, '1Gi' for 1 gibibyte)",
type: :string,
required: required,
valid_regex: /^\d+[MG]i$/
}
}
end
|
.org_option(required: false) ⇒ Object
rubocop:disable Metrics/MethodLength
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/command/base.rb', line 73
def self.org_option(required: false)
{
name: :org,
params: {
aliases: ["-o"],
banner: "ORG_NAME",
desc: "Organization name",
type: :string,
required: required
}
}
end
|
.replica_option(required: false) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/command/base.rb', line 113
def self.replica_option(required: false)
{
name: :replica,
params: {
aliases: ["-r"],
banner: "REPLICA_NAME",
desc: "Replica name",
type: :string,
required: required
}
}
end
|
.run_release_phase_option(required: false) ⇒ Object
311
312
313
314
315
316
317
318
319
320
|
# File 'lib/command/base.rb', line 311
def self.run_release_phase_option(required: false)
{
name: :run_release_phase,
params: {
desc: "Runs release phase",
type: :boolean,
required: required
}
}
end
|
.skip_confirm_option(required: false) ⇒ Object
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/command/base.rb', line 204
def self.skip_confirm_option(required: false)
{
name: :yes,
params: {
aliases: ["-y"],
banner: "SKIP_CONFIRM",
desc: "Skip confirmation",
type: :boolean,
required: required
}
}
end
|
.skip_post_creation_hook_option(required: false) ⇒ Object
451
452
453
454
455
456
457
458
459
460
|
# File 'lib/command/base.rb', line 451
def self.skip_post_creation_hook_option(required: false)
{
name: :skip_post_creation_hook,
params: {
desc: "Skips post-creation hook",
type: :boolean,
required: required
}
}
end
|
.skip_pre_deletion_hook_option(required: false) ⇒ Object
462
463
464
465
466
467
468
469
470
471
|
# File 'lib/command/base.rb', line 462
def self.skip_pre_deletion_hook_option(required: false)
{
name: :skip_pre_deletion_hook,
params: {
desc: "Skips pre-deletion hook",
type: :boolean,
required: required
}
}
end
|
.skip_secret_access_binding_option(required: false) ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
|
# File 'lib/command/base.rb', line 288
def self.skip_secret_access_binding_option(required: false)
{
name: :skip_secret_access_binding,
new_name: :skip_secrets_setup,
params: {
desc: "Skips secret access binding",
type: :boolean,
required: required
}
}
end
|
.skip_secrets_setup_option(required: false) ⇒ Object
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/command/base.rb', line 300
def self.skip_secrets_setup_option(required: false)
{
name: :skip_secrets_setup,
params: {
desc: "Skips secrets setup",
type: :boolean,
required: required
}
}
end
|
.staging_branch_option(required: false) ⇒ Object
322
323
324
325
326
327
328
329
330
331
332
|
# File 'lib/command/base.rb', line 322
def self.staging_branch_option(required: false)
{
name: :staging_branch,
params: {
banner: "BRANCH",
desc: "Branch that should auto-deploy staging; defaults to main/master",
type: :string,
required: required
}
}
end
|
.terminal_size_option(required: false) ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/command/base.rb', line 241
def self.terminal_size_option(required: false)
{
name: :terminal_size,
params: {
banner: "ROWS,COLS",
desc: "Override remote terminal size (e.g. `--terminal-size 10,20`)",
type: :string,
required: required,
valid_regex: /^\d+,\d+$/
}
}
end
|
.trace_option(required: false) ⇒ Object
277
278
279
280
281
282
283
284
285
286
|
# File 'lib/command/base.rb', line 277
def self.trace_option(required: false)
{
name: :trace,
params: {
desc: "Shows trace of API calls. WARNING: may contain sensitive data",
type: :boolean,
required: required
}
}
end
|
.upstream_token_option(required: false) ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/command/base.rb', line 191
def self.upstream_token_option(required: false)
{
name: :upstream_token,
params: {
aliases: ["-t"],
banner: "UPSTREAM_TOKEN",
desc: "Upstream token",
type: :string,
required: required
}
}
end
|
.use_digest_image_ref_option(required: false) ⇒ Object
507
508
509
510
511
512
513
514
515
516
|
# File 'lib/command/base.rb', line 507
def self.use_digest_image_ref_option(required: false)
{
name: :use_digest_image_ref,
params: {
desc: "Uses the image's digest (SHA256 value) for referencing the Docker image",
type: :boolean,
required: required
}
}
end
|
.use_local_token_option(required: false) ⇒ Object
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/command/base.rb', line 230
def self.use_local_token_option(required: false)
{
name: :use_local_token,
params: {
desc: "Override remote CPLN_TOKEN with local token",
type: :boolean,
required: required
}
}
end
|
.validations_option(required: false) ⇒ Object
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
# File 'lib/command/base.rb', line 436
def self.validations_option(required: false)
{
name: :validations,
params: {
banner: "VALIDATION_1,VALIDATION_2,...",
desc: "Which validations to run " \
"(must be separated by a comma)",
type: :string,
required: required,
default: VALIDATIONS_WITHOUT_ADDITIONAL_OPTIONS.join(","),
valid_regex: /^(#{ALL_VALIDATIONS.join('|')})(,(#{ALL_VALIDATIONS.join('|')}))*$/
}
}
end
|
.verbose_option(required: false) ⇒ Object
265
266
267
268
269
270
271
272
273
274
275
|
# File 'lib/command/base.rb', line 265
def self.verbose_option(required: false)
{
name: :verbose,
params: {
aliases: ["-d"],
desc: "Shows detailed logs",
type: :boolean,
required: required
}
}
end
|
.version_option(required: false) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/command/base.rb', line 217
def self.version_option(required: false)
{
name: :version,
params: {
aliases: ["-v"],
banner: "VERSION",
desc: "Displays the current version of the CLI",
type: :boolean,
required: required
}
}
end
|
.wait_option(title = "", required: false) ⇒ Object
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/command/base.rb', line 254
def self.wait_option(title = "", required: false)
{
name: :wait,
params: {
desc: "Waits for #{title}",
type: :boolean,
required: required
}
}
end
|
.workload_option(required: false, repeatable: false) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/command/base.rb', line 99
def self.workload_option(required: false, repeatable: false)
{
name: :workload,
params: {
aliases: ["-w"],
banner: "WORKLOAD_NAME",
desc: "Workload name",
type: :string,
repeatable: repeatable,
required: required
}
}
end
|
Instance Method Details
#args_join(args) ⇒ Object
NOTE: use simplified variant atm, as shelljoin do different escaping
TODO: most probably need better logic for escaping various quotes
533
534
535
|
# File 'lib/command/base.rb', line 533
def args_join(args)
args.join(" ")
end
|
#bind_shared_secret_policy_grant(grant, policy) ⇒ Object
625
626
627
628
629
630
631
632
|
# File 'lib/command/base.rb', line 625
def bind_shared_secret_policy_grant(grant, policy)
policy_name = grant.fetch(:policy_name)
return if identity_bound_to_policy_with_reveal?(policy)
step("Binding identity '#{config.identity}' to shared secret policy '#{policy_name}'") do
cp.bind_identity_to_policy(config.identity_link, policy_name)
end
end
|
#bind_shared_secret_policy_grants(grant_policy_pairs) ⇒ Object
605
606
607
608
609
|
# File 'lib/command/base.rb', line 605
def bind_shared_secret_policy_grants(grant_policy_pairs)
grant_policy_pairs.each do |grant, policy|
bind_shared_secret_policy_grant(grant, policy)
end
end
|
#cp ⇒ Object
601
602
603
|
# File 'lib/command/base.rb', line 601
def cp
@cp ||= Controlplane.new(config)
end
|
#ensure_docker_running! ⇒ Object
674
675
676
677
678
679
|
# File 'lib/command/base.rb', line 674
def ensure_docker_running!
result = Shell.cmd("docker", "version", capture_stderr: true)
return if result[:success]
raise "Can't run Docker. Please make sure that it's installed and started, then try again."
end
|
#ensure_shared_secret_policy_targets_secret!(grant, policy) ⇒ Object
634
635
636
637
638
639
|
# File 'lib/command/base.rb', line 634
def ensure_shared_secret_policy_targets_secret!(grant, policy)
return if shared_secret_policy_targets_secret?(grant, policy)
raise "Shared secret policy '#{grant.fetch(:policy_name)}' for shared_secret_grants entry " \
"'#{grant.fetch(:name)}' must target only secret '#{grant.fetch(:secret_name)}'."
end
|
#identity_bound_to_policy_with_reveal?(policy) ⇒ Boolean
657
658
659
|
# File 'lib/command/base.rb', line 657
def identity_bound_to_policy_with_reveal?(policy)
identity_policy_permissions(policy).include?("reveal")
end
|
#identity_policy_permissions(policy) ⇒ Object
661
662
663
664
665
666
667
|
# File 'lib/command/base.rb', line 661
def identity_policy_permissions(policy)
Array(policy["bindings"]).flat_map do |binding|
next [] unless Array(binding["principalLinks"]).include?(config.identity_link)
Array(binding["permissions"])
end.uniq
end
|
#progress ⇒ Object
537
538
539
|
# File 'lib/command/base.rb', line 537
def progress
$stderr
end
|
#resolve_shared_secret_policy_grant(grant) ⇒ Object
617
618
619
620
621
622
623
|
# File 'lib/command/base.rb', line 617
def resolve_shared_secret_policy_grant(grant)
policy = cp.fetch_policy(grant.fetch(:policy_name))
raise shared_secret_policy_missing_message(grant) if policy.nil?
ensure_shared_secret_policy_targets_secret!(grant, policy)
policy
end
|
#resolve_shared_secret_policy_grants ⇒ Object
611
612
613
614
615
|
# File 'lib/command/base.rb', line 611
def resolve_shared_secret_policy_grants
config.shared_secret_grants.map do |grant|
[grant, resolve_shared_secret_policy_grant(grant)]
end
end
|
#run_command_in_latest_image(command, title:) ⇒ Object
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
# File 'lib/command/base.rb', line 681
def run_command_in_latest_image(command, title:)
path = Pathname.new("#{config.app_cpln_dir}/#{command}").expand_path
command = ".controlplane/#{command}" if File.exist?(path)
progress.puts("Running #{title}...\n\n")
begin
run_cpflow_command("run", "-a", config.app, "--image", "latest", "--", command)
rescue SystemExit => e
progress.puts
raise "Failed to run #{title}." if e.status.nonzero?
progress.puts("Finished running #{title}.\n\n")
end
end
|
#run_cpflow_command(command, *args) ⇒ Object
701
702
703
704
705
706
707
708
709
710
711
712
713
|
# File 'lib/command/base.rb', line 701
def run_cpflow_command(command, *args)
common_args = []
self.class.common_options.each do |option|
value = config.options[option[:name]]
next if value.nil?
name = "--#{option[:name].to_s.tr('_', '-')}"
common_args.push(name, value)
end
Cpflow::Cli.start([command, *common_args, *args])
end
|
#shared_secret_policy_missing_message(grant) ⇒ Object
669
670
671
672
|
# File 'lib/command/base.rb', line 669
def shared_secret_policy_missing_message(grant)
"Shared secret policy '#{grant.fetch(:policy_name)}' for shared_secret_grants entry " \
"'#{grant.fetch(:name)}' does not exist. Create the policy or remove the shared secret grant."
end
|
#shared_secret_policy_target_links(grant) ⇒ Object
649
650
651
652
653
654
655
|
# File 'lib/command/base.rb', line 649
def shared_secret_policy_target_links(grant)
secret_name = grant.fetch(:secret_name)
[
"//secret/#{secret_name}",
"/org/#{config.org}/secret/#{secret_name}"
]
end
|
#shared_secret_policy_targets_secret?(grant, policy) ⇒ Boolean
641
642
643
644
645
646
647
|
# File 'lib/command/base.rb', line 641
def shared_secret_policy_targets_secret?(grant, policy)
target_links = Array(policy["targetLinks"])
policy["targetKind"] == "secret" &&
target_links.one? &&
shared_secret_policy_target_links(grant).include?(target_links.first)
end
|
#step(message, abort_on_error: true, retry_on_failure: false, max_retry_count: 1000, wait: 1, &block) ⇒ Object
rubocop:disable Metrics/MethodLength
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
# File 'lib/command/base.rb', line 550
def step(message, abort_on_error: true, retry_on_failure: false, max_retry_count: 1000, wait: 1, &block) progress.print("#{message}...")
Shell.use_tmp_stderr do
success = false
begin
success =
if retry_on_failure
with_retry(max_retry_count: max_retry_count, wait: wait, &block)
else
yield
end
rescue RuntimeError => e
Shell.write_to_tmp_stderr(e.message)
end
step_finish(success, abort_on_error: abort_on_error)
end
end
|
#step_finish(success, abort_on_error: true) ⇒ Object
#wait_for_workloads_ready(workloads, reverse: false) ⇒ Object
587
588
589
590
591
592
593
594
595
596
597
598
599
|
# File 'lib/command/base.rb', line 587
def wait_for_workloads_ready(workloads, reverse: false)
workloads_to_wait_for = reverse ? workloads.reverse : workloads
workloads_to_wait_for.each do |workload|
if cp.workload_suspended?(workload)
progress.puts("Workload '#{workload}' is suspended. Skipping...")
else
step("Waiting for workload '#{workload}' to be ready", retry_on_failure: true) do
cp.workload_deployments_ready?(workload, location: config.location, expected_status: true)
end
end
end
end
|
#with_retry(max_retry_count:, wait:) ⇒ Object
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
# File 'lib/command/base.rb', line 571
def with_retry(max_retry_count:, wait:)
retry_count = 0
success = false
while !success && retry_count <= max_retry_count
success = yield
break if success
progress.print(".")
Kernel.sleep(wait)
retry_count += 1
end
success
end
|