Module: Kontena::Cli::Stacks::Common

Defined Under Namespace

Modules: RegistryNameParam, StackFileOrNameParam, StackNameOption, StackNameParam, StackValuesFromOption, StackValuesToOption

Instance Method Summary collapse

Methods included from Kontena::Cli::Services::ServicesHelper

#create_service, #delete_service, #deploy_service, #get_service, #health_status, #health_status_icon, #int_to_filesize, #parse_build_args, #parse_container_name, #parse_deploy_opts, #parse_health_check, #parse_image, #parse_links, #parse_log_opts, #parse_memory, #parse_ports, #parse_relative_time, #parse_secrets, #parse_service_id, #render_service_deploy_instances, #restart_service, #scale_service, #show_service, #show_service_containers, #show_service_instances, #start_service, #stop_service, #update_service, #wait_for_deploy_to_finish

Methods included from Common

#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #caret, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_grid, #current_master_index, #debug?, #display_account_login_info, #display_login_info, display_logo, #display_master_login_info, #error, exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_token, #reset_client, #reset_cloud_client, #running_quiet?, #running_silent?, #running_verbose?, #spin_if, #spinner, #sprint, #sputs, #stdin_input, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning

Instance Method Details

#abort_on_validation_errors(errors, filename = nil) ⇒ Object



196
197
198
199
200
201
# File 'lib/kontena/cli/stacks/common.rb', line 196

def abort_on_validation_errors(errors, filename = nil)
  return if errors.nil? || errors.empty?
  $stderr.puts pastel.red("#{"(#{filename}) " if filename} YAML validation failed! Aborting.")
  display_notifications(errors, :red)
  abort
end

#current_dirString

Returns:



182
183
184
# File 'lib/kontena/cli/stacks/common.rb', line 182

def current_dir
  File.basename(Dir.getwd)
end

#display_notifications(messages, color = :yellow) ⇒ Object



186
187
188
# File 'lib/kontena/cli/stacks/common.rb', line 186

def display_notifications(messages, color = :yellow)
  $stderr.puts(pastel.send(color, messages.to_yaml.gsub(/^---$/, '')))
end

#hint_on_validation_notifications(notifications, filename = nil) ⇒ Object



190
191
192
193
194
# File 'lib/kontena/cli/stacks/common.rb', line 190

def hint_on_validation_notifications(notifications, filename = nil)
  return if notifications.nil? || notifications.empty?
  $stderr.puts pastel.yellow("#{"(#{filename}) " if filename}YAML contains the following unsupported options and they were rejected:")
  display_notifications(notifications)
end

#loaderStackFileLoader

Returns a loader for the stack origin defined through command-line options.

Returns:

  • (StackFileLoader)

    a loader for the stack origin defined through command-line options



13
14
15
# File 'lib/kontena/cli/stacks/common.rb', line 13

def loader
  @loader ||= loader_class.for(source)
end

#loader_classClass

Returns an accessor to StackFileLoader constant, for testing purposes.

Returns:

  • (Class)

    an accessor to StackFileLoader constant, for testing purposes



41
42
43
# File 'lib/kontena/cli/stacks/common.rb', line 41

def loader_class
  ::Kontena::Cli::Stacks::YAML::StackFileLoader
end

#readerYAML::Reader

Returns a YAML reader for the target file.

Returns:



18
19
20
# File 'lib/kontena/cli/stacks/common.rb', line 18

def reader
  @reader ||= loader.reader
end

#set_env_variables(stack, grid, platform = grid) ⇒ Object

Sets environment variables from parameters

Parameters:

  • stack (String)

    current stack name

  • grid (String)

    current grid name

  • platform (String) (defaults to: grid)

    current platform name, defaults to param grid value



175
176
177
178
179
# File 'lib/kontena/cli/stacks/common.rb', line 175

def set_env_variables(stack, grid, platform = grid)
  ENV['STACK'] = stack
  ENV['GRID'] = grid
  ENV['PLATFORM'] = platform
end

#stackHash

An accessor to the YAML Reader outcome. Passes parent name, values from command line and the stackname to the reader.

Returns:

  • (Hash)


32
33
34
35
36
37
38
# File 'lib/kontena/cli/stacks/common.rb', line 32

def stack
  @stack ||= reader.execute(
    name: stack_name,
    parent_name: self.respond_to?(:parent_name) ? self.parent_name : nil,
    values: (self.respond_to?(:values_from_options) ? self.values_from_options : {})
  )
end

#stack_nameString

Stack name read from -n parameter or the stack file

Returns:



24
25
26
# File 'lib/kontena/cli/stacks/common.rb', line 24

def stack_name
  @stack_name ||= (self.respond_to?(:name) && self.name) ? self.name : loader.stack_name.stack
end

#stacks_clientKontena::StacksClient

An accessor to stack registry client



205
206
207
# File 'lib/kontena/cli/stacks/common.rb', line 205

def stacks_client
  @stacks_client ||= Kontena::StacksClient.new(.stacks_url, .token, read_requires_token: .stacks_read_authentication)
end