Class: Command::ApplyTemplate
- 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, add_app_identity_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. cpflow apply-template redis -a $APP_NAME # Applies several templates (practically creating full app). cpflow apply-template app postgres redis rails -a $APP_NAME ``` EX
- VALIDATIONS =
%w[config templates].freeze
Constants inherited from Base
Base::ACCEPTS_EXTRA_OPTIONS, Base::ALL_VALIDATIONS, Base::DEFAULT_ARGS, Base::HIDE, Base::VALIDATIONS_WITHOUT_ADDITIONAL_OPTIONS, Base::VALIDATIONS_WITH_ADDITIONAL_OPTIONS, Base::WITH_INFO_HEADER
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Metrics/MethodLength.
Methods inherited from Base
add_app_identity_option, all_commands, all_options, all_options_by_key_name, app_option, #args_join, commit_option, common_options, #cp, cpu_option, detached_option, docker_context_option, domain_option, #ensure_docker_running!, entrypoint_option, image_option, #initialize, interactive_option, location_option, log_method_option, logs_limit_option, logs_since_option, memory_option, org_option, #progress, replica_option, #run_command_in_latest_image, #run_cpflow_command, run_release_phase_option, skip_confirm_option, skip_post_creation_hook_option, skip_pre_deletion_hook_option, skip_secret_access_binding_option, skip_secrets_setup_option, #step, #step_finish, terminal_size_option, trace_option, upstream_token_option, use_local_token_option, validations_option, verbose_option, version_option, wait_option, #with_retry, workload_option
Methods included from Helpers
normalize_command_name, normalize_option_name, random_four_digits, strip_str_and_validate
Constructor Details
This class inherits a constructor from Command::Base
Instance Method Details
#call ⇒ Object
rubocop:disable Metrics/MethodLength
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 |
# File 'lib/command/apply_template.rb', line 45 def call # rubocop:disable Metrics/MethodLength @template_parser = TemplateParser.new(self) @names_to_filenames = config.args.to_h do |name| [name, @template_parser.template_filename(name)] end ensure_templates! @created_items = [] @failed_templates = [] @skipped_templates = [] templates = @template_parser.parse(@names_to_filenames.values) pending_templates = confirm_templates(templates) add_app_identity_template(pending_templates) if config.[:add_app_identity] pending_templates.each do |template| apply_template(template) end print_created_items print_failed_templates print_skipped_templates exit(ExitCode::ERROR_DEFAULT) if @failed_templates.any? end |