17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/kuber_kit/service_deployer/strategies/docker.rb', line 17
def deploy(shell, service)
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
container_name = strategy_options.fetch(:container_name, service.uri)
docker_run_args = strategy_options.fetch(:docker_run_args, nil)
docker_run_command = strategy_options.fetch(:docker_run_command, nil)
image_name = strategy_options.fetch(:image_name, nil)
if image_name.nil?
raise KuberKit::Error, "image_name is mandatory attribute for this deploy strategy"
end
image = image_store.get_image(image_name.to_sym)
delete_enabled = strategy_options.fetch(:delete_if_exists, false)
if delete_enabled && docker_commands.container_exists?(shell, container_name)
docker_commands.delete_container(shell, container_name)
end
docker_commands.run(shell, image.remote_registry_url, run_args: docker_run_args, run_command: docker_run_command)
end
|