Class: Command::SetupApp

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

Constant Summary collapse

NAME =
"setup-app"
OPTIONS =
[
  app_option(required: true),
  skip_secret_access_binding_option,
  skip_secrets_setup_option,
  skip_post_creation_hook_option
].freeze
DESCRIPTION =
"Creates an app and all its workloads"
LONG_DESCRIPTION =
<<~DESC
  - Creates an app and all its workloads
  - Specify the templates for the app and workloads through `setup_app_templates` in the `.controlplane/controlplane.yml` file
  - This should only be used for temporary apps like review apps, never for persistent apps like production or staging (to update workloads for those, use 'cpflow apply-template' instead)
  - Configures app to have org-level secrets with default name `"{APP_PREFIX}-secrets"`
    using org-level policy with default name `"{APP_PREFIX}-secrets-policy"` (names can be customized, see docs)
  - Creates identity for secrets if it does not exist
  - Use `--skip-secrets-setup` to prevent the automatic setup of secrets,
    or set it through `skip_secrets_setup` in the `.controlplane/controlplane.yml` file
  - Runs a post-creation hook after the app is created if `hooks.post_creation` is specified in the `.controlplane/controlplane.yml` file
  - If the hook exits with a non-zero code, the command will stop executing and also exit with a non-zero code
  - Use `--skip-post-creation-hook` to skip the hook if specified in `controlplane.yml`
DESC
VALIDATIONS =
%w[config templates].freeze

Constants inherited from Base

Base::ACCEPTS_EXTRA_OPTIONS, Base::ALL_VALIDATIONS, Base::DEFAULT_ARGS, Base::EXAMPLES, Base::HIDE, Base::REQUIRES_ARGS, Base::USAGE, Base::VALIDATIONS_WITHOUT_ADDITIONAL_OPTIONS, Base::VALIDATIONS_WITH_ADDITIONAL_OPTIONS, Base::WITH_INFO_HEADER

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

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

#callObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/command/setup_app.rb', line 28

def call # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
  templates = config[:setup_app_templates]

  app = cp.fetch_gvc
  if app
    raise "App '#{config.app}' already exists. If you want to update this app, " \
          "either run 'cpflow delete -a #{config.app}' and then re-run this command, " \
          "or run 'cpflow apply-template #{templates.join(' ')} -a #{config.app}'."
  end

  skip_secrets_setup = config.options[:skip_secret_access_binding] ||
                       config.options[:skip_secrets_setup] || config.current[:skip_secrets_setup]

  create_secret_and_policy_if_not_exist unless skip_secrets_setup

  args = []
  args.push("--add-app-identity") unless skip_secrets_setup
  run_cpflow_command("apply-template", *templates, "-a", config.app, *args)

  bind_identity_to_policy unless skip_secrets_setup
  run_post_creation_hook unless config.options[:skip_post_creation_hook]
end