Module: Kontena::Cli::Stacks::Common
- Includes:
- Kontena::Cli::Services::ServicesHelper
- Included in:
- BuildCommand, InstallCommand, ListCommand, MonitorCommand, Registry::CreateCommand, Registry::MakePrivateCommand, Registry::MakePublicCommand, Registry::PullCommand, Registry::PushCommand, Registry::RemoveCommand, Registry::SearchCommand, Registry::ShowCommand, RemoveCommand, RestartCommand, ShowCommand, StopCommand, UpgradeCommand, ValidateCommand, StacksCache::RegistryClientFactory
- Defined in:
- lib/kontena/cli/stacks/common.rb
Defined Under Namespace
Modules: RegistryNameParam, StackFileOrNameParam, StackNameOption, StackNameParam, StackValuesFromOption, StackValuesToOption
Instance Method Summary collapse
- #abort_on_validation_errors(errors, filename = nil) ⇒ Object
- #current_dir ⇒ String
- #display_notifications(messages, color = :yellow) ⇒ Object
- #hint_on_validation_notifications(notifications, filename = nil) ⇒ Object
-
#loader ⇒ StackFileLoader
A loader for the stack origin defined through command-line options.
-
#loader_class ⇒ Class
An accessor to StackFileLoader constant, for testing purposes.
-
#reader ⇒ YAML::Reader
A YAML reader for the target file.
-
#set_env_variables(stack, grid, platform = grid) ⇒ Object
Sets environment variables from parameters.
-
#stack ⇒ Hash
An accessor to the YAML Reader outcome.
-
#stack_name ⇒ String
Stack name read from -n parameter or the stack file.
-
#stacks_client ⇒ Kontena::StacksClient
An accessor to stack registry client.
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_dir ⇒ String
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(, color = :yellow) $stderr.puts(pastel.send(color, .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 |
#loader ⇒ StackFileLoader
Returns 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_class ⇒ Class
Returns 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 |
#reader ⇒ YAML::Reader
Returns a YAML reader for the target file.
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
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 |
#stack ⇒ Hash
An accessor to the YAML Reader outcome. Passes parent name, values from command line and the stackname to the reader.
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. : {}) ) end |
#stack_name ⇒ String
Stack name read from -n parameter or the stack file
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_client ⇒ Kontena::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(current_account.stacks_url, current_account.token, read_requires_token: current_account.stacks_read_authentication) end |