Class: Command::ApplyTemplate

Inherits:
Base
  • Object
show all
Defined in:
lib/command/apply_template.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

NAME =
"apply-template"
USAGE =
"apply-template TEMPLATE [TEMPLATE] ... [TEMPLATE]"
REQUIRES_ARGS =
true
OPTIONS =
[
  app_option(required: true),
  skip_confirm_option
].freeze
DESCRIPTION =
"Applies application-specific configs from templates"
LONG_DESCRIPTION =
<<~DESC
  - Applies application-specific configs from templates (e.g., for every review-app)
  - Publishes (creates or updates) those at Control Plane infrastructure
  - Picks templates from the `.controlplane/templates` directory
  - Templates are ordinary Control Plane templates but with variable preprocessing

  **Preprocessed template variables:**

  ```
  APP_GVC      - basically GVC or app name
  APP_LOCATION - default location
  APP_ORG      - organization
  APP_IMAGE    - will use latest app image
  ```
DESC
EXAMPLES =
<<~EX
  ```sh
  # Applies single template.
  cpl apply-template redis -a $APP_NAME

  # Applies several templates (practically creating full app).
  cpl apply-template gvc postgres redis rails -a $APP_NAME
  ```
EX

Constants inherited from Base

Base::DEFAULT_ARGS, Base::HIDE, Base::NO_IMAGE_AVAILABLE

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

all_commands, all_options, all_options_by_key_name, app_option, #args_join, commit_option, #cp, #ensure_workload_deleted, image_option, #initialize, #latest_image, #latest_image_from, #latest_image_next, org_option, #perform, #progress, skip_confirm_option, #step, #step_error, #step_finish, terminal_size_option, upstream_token_option, use_local_token_option, version_option, #wait_for_replica, #wait_for_workload, wait_option, workload_option

Constructor Details

This class inherits a constructor from Command::Base

Instance Method Details

#callObject

rubocop:disable Metrics/MethodLength



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/command/apply_template.rb', line 38

def call # rubocop:disable Metrics/MethodLength
  ensure_templates!

  @app_status = :existing
  @created_workloads = []
  @failed_workloads = []
  @skipped_workloads = []

  @asked_for_confirmation = false

  pending_templates = templates.select do |template|
    if template == "gvc"
      confirm_app(template)
    else
      confirm_workload(template)
    end
  end

  progress.puts if @asked_for_confirmation

  pending_templates.each do |template, filename|
    step("Applying template '#{template}'", abort_on_error: false) do
      apply_template(filename)
      if $CHILD_STATUS.success?
        report_success(template)
      else
        report_failure(template)
      end

      $CHILD_STATUS.success?
    end
  end

  print_app_status
  print_created_workloads
  print_failed_workloads
  print_skipped_workloads
end