Class: KuberKit::ServiceDeployer::Strategies::DockerCompose

Inherits:
Abstract
  • Object
show all
Defined in:
lib/kuber_kit/service_deployer/strategies/docker_compose.rb

Constant Summary collapse

STRATEGY_OPTIONS =
[
  :service_name, 
  :command_name,
  :custom_args,
  :detached
]

Instance Method Summary collapse

Instance Method Details

#deploy(shell, service) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kuber_kit/service_deployer/strategies/docker_compose.rb', line 16

def deploy(shell, service)
  service_config = reader.read(shell, service)
  config_path    = "#{configs.service_config_dir}/#{service.name}.yml"
  shell.write(config_path, service_config)

  strategy_options = service.attribute(:deployer, default: {})
  unknown_options  = strategy_options.keys.map(&:to_sym) - STRATEGY_OPTIONS
  if unknown_options.any?
    raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
  end

  service_name = strategy_options.fetch(:service_name, service.name.to_s)
  command_name = strategy_options.fetch(:command_name, nil)
  custom_args  = strategy_options.fetch(:custom_args, nil)

  docker_compose_commands.run(shell, config_path, 
    service:      service_name, 
    command:      command_name,
    args:         custom_args, 
    detached:     !!strategy_options[:detached],
    interactive:  !strategy_options[:detached]
  )
end