Class: KuberKit::Actions::ServiceDeployer

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/actions/service_deployer.rb

Instance Method Summary collapse

Instance Method Details

#call(services:, tags:, skip_services: nil, skip_compile: false, require_confirmation: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/kuber_kit/actions/service_deployer.rb', line 21

def call(services:, tags:, skip_services: nil, skip_compile: false, require_confirmation: false)
  deployment_result     = KuberKit::Actions::ActionResult.new()
  current_configuration = KuberKit.current_configuration

  if services.empty? && tags.empty?
    services, tags = show_tags_selection
  end


  disabled_services = current_configuration.disabled_services.map(&:to_s)
  disabled_services += skip_services if skip_services

  service_names = service_list_resolver.resolve(
    services:         services || [],
    tags:             tags || [],
    enabled_services:   current_configuration.enabled_services.map(&:to_s),
    disabled_services:  disabled_services
  ).map(&:to_sym)

  # Return the list of services with all dependencies.
  all_service_names = service_dependency_resolver.get_all(service_names)

  unless all_service_names.any?
    ui.print_warning "ServiceDeployer", "No service found with given options, nothing will be deployed."
    return false
  end

  services_list = all_service_names.map(&:to_s).map(&:yellow).join(", ")
  ui.print_info "ServiceDeployer", "The following services will be deployed: #{services_list}"

  if require_confirmation
    result = ui.prompt("Please confirm to continue deployment", ["confirm".green, "cancel".red])
    return false unless ["confirm".green, "confirm", "yes"].include?(result)
  end

  services = all_service_names.map do |service_name|
    service_store.get_service(service_name.to_sym)
  end

  images_names = services.map(&:images).flatten.uniq

  unless skip_compile
    compilation_result = compile_images(images_names)

    return false unless compilation_result && compilation_result.succeeded?
  end

  service_dependency_resolver.each_with_deps(service_names) do |dep_service_names|
    ui.print_debug("ServiceDeployer", "Scheduling to compile: #{dep_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")

    if deployment_result.succeeded?
      deploy_simultaneously(dep_service_names, deployment_result)
    end
  end

  deployment_result
rescue KuberKit::Error => e
  ui.print_error("Error", e.message)

  compilation_result.failed!(e.message)

  false
rescue Interrupt => e
  process_cleaner.clean
end