class Object

Constants

CONFIGURATION_OPTIONS
CONSOLE_COLORS
DELIMITER_WIDTH

Public Instance Methods

block_output(header) { || ... } click to toggle source
# File lib/k8s-deploy/tasks/console_formatters.rb, line 20
def block_output(header)
  prepared_header = color_output(:yellow) { " #{header} " }

  # adding 12 to fix size of non-visible color symbols
  puts
  puts prepared_header.center(DELIMITER_WIDTH + 12, '=')

  puts
  yield
  puts
end
build_full_image_name(configuration) click to toggle source
# File lib/k8s-deploy/tasks/deploy.rb, line 14
def build_full_image_name(configuration)
  registry = configuration['container_registry']
  gcloud_project_name = configuration['gcloud_project_name']
  docker_image_name = configuration['kubernetes_docker_image_name']
  local_git_hash = get_git_hash(configuration)[0..6]
  tag = build_tag_name(local_git_hash)

  "#{registry}/#{gcloud_project_name}/#{docker_image_name}:#{tag}"
end
build_tag_name(git_hash) click to toggle source
# File lib/k8s-deploy/tasks/deploy.rb, line 5
def build_tag_name(git_hash)
  build_timestamp + '-' + git_hash
end
build_timestamp() click to toggle source
# File lib/k8s-deploy/tasks/deploy.rb, line 1
def build_timestamp
  CURRENT_TIME.strftime('%Y%m%d%H%M%S')
end
check_result_output(result) click to toggle source
# File lib/k8s-deploy/tasks/console_formatters.rb, line 32
def check_result_output(result)
  if result
    color_output(:green) { 'Ok' }
  else
    color_output(:red) { 'Fail' }
  end
end
color_output(color) { || ... } click to toggle source

colorizing output

# File lib/k8s-deploy/tasks/console_formatters.rb, line 11
def color_output(color)
  raise 'Wrong color name' unless CONSOLE_COLORS.key?(color)
  CONSOLE_COLORS[color] + yield.to_s + CONSOLE_COLORS[:no_color]
end
command_output(text) click to toggle source
# File lib/k8s-deploy/tasks/console_formatters.rb, line 16
def command_output(text)
  puts "#> #{text}"
end
get_git_hash(configuration) click to toggle source
# File lib/k8s-deploy/tasks/deploy.rb, line 9
def get_git_hash(configuration)
  conf_branch = configuration['git_branch']
  `git rev-parse #{conf_branch}`
end
print_configuration(configuration) click to toggle source
print_deploy_build(configuration) click to toggle source
print_deploy_deployment_patch(configuration) click to toggle source
print_deploy_push(configuration) click to toggle source
print_deploy_rollback(configuration) click to toggle source
print_deploy_scale(configuration, replicas_count) click to toggle source
print_deployment_status(configuration) click to toggle source
print_docker_image_status(configuration) click to toggle source
print_gcloud_check_kubectl_context(configuration) click to toggle source
print_gcloud_check_project(configuration) click to toggle source
print_git_check_branch(configuration) click to toggle source
print_git_check_remote_branch(configuration) click to toggle source
print_git_check_uncommitted() click to toggle source
print_pods_status(configuration) click to toggle source
validate_configuration(configuration) click to toggle source
# File lib/k8s-deploy/tasks/configuration.rb, line 12
def validate_configuration(configuration)
  missed_parameters = CONFIGURATION_OPTIONS.keys - configuration.keys

  unless missed_parameters.empty?
    params_string = missed_parameters.join(', ')
    raise "Missed parameters in configuration: #{params_string}."
  end
end