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),
  location_option,
  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_ORG}}           - organization name
  {{APP_NAME}}          - GVC/app name
  {{APP_LOCATION}}      - location, per YML file, ENV, or command line arg
  {{APP_LOCATION_LINK}} - full link for location, ready to be used for the value of `staticPlacement.locationLinks` in the templates
  {{APP_IMAGE}}         - latest app image
  {{APP_IMAGE_LINK}}    - full link for latest app image, ready to be used for the value of `containers[].image` in the templates
  {{APP_IDENTITY}}      - default identity
  {{APP_IDENTITY_LINK}} - full link for identity, ready to be used for the value of `identityLink` in the templates
  ```
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::ACCEPTS_EXTRA_OPTIONS, Base::DEFAULT_ARGS, Base::HIDE, Base::NO_IMAGE_AVAILABLE, Base::WITH_INFO_HEADER

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_identity, #app_identity_link, #app_image_link, #app_location_link, app_option, #app_secrets, #app_secrets_policy, #args_join, clean_on_failure_option, commit_option, common_options, #cp, domain_option, #ensure_workload_deleted, #extract_image_commit, image_option, #initialize, #latest_image, #latest_image_from, #latest_image_next, location_option, org_option, #perform!, #progress, run_release_phase_option, skip_confirm_option, skip_secret_access_binding_option, #step, #step_error, #step_finish, terminal_size_option, trace_option, upstream_token_option, use_local_token_option, verbose_option, version_option, #wait_for_replica, #wait_for_workload, wait_option, workload_option

Methods included from Helpers

#random_four_digits, #strip_str_and_validate

Constructor Details

This class inherits a constructor from Command::Base

Instance Method Details

#callObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



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
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/command/apply_template.rb', line 43

def call # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
  ensure_templates!

  @created_items = []
  @failed_templates = []
  @skipped_templates = []

  @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

  @deprecated_variables = []

  pending_templates.each do |template, filename|
    step("Applying template '#{template}'", abort_on_error: false) do
      items = apply_template(filename)
      if items
        items.each do |item|
          report_success(item)
        end
      else
        report_failure(template)
      end

      $CHILD_STATUS.success?
    end
  end

  warn_deprecated_variables

  print_created_items
  print_failed_templates
  print_skipped_templates

  exit(1) if @failed_templates.any?
end