lib/kontena/cli/apps/service_generator.rb in kontena-cli-0.14.7 vs lib/kontena/cli/apps/service_generator.rb in kontena-cli-0.15.0.rc1

- old
+ new

@@ -28,11 +28,11 @@ data['image'] = parse_image(options['image']) data['env'] = merge_env_vars(options) data['container_count'] = options['instances'] data['links'] = parse_links(options['links'] || []) data['external_links'] = parse_links(options['external_links'] || []) - data['ports'] = parse_ports(options['ports'] || []) + data['ports'] = parse_stringified_ports(options['ports'] || []) data['memory'] = parse_memory(options['mem_limit'].to_s) if options['mem_limit'] data['memory_swap'] = parse_memory(options['memswap_limit'].to_s) if options['memswap_limit'] data['cpu_shares'] = options['cpu_shares'] if options['cpu_shares'] data['volumes'] = options['volumes'] || [] data['volumes_from'] = options['volumes_from'] || [] @@ -57,10 +57,21 @@ data['deploy_opts'] = deploy end data['hooks'] = options['hooks'] || {} data['secrets'] = options['secrets'] if options['secrets'] data['build'] = parse_build_options(options) if options['build'] + health_check = {} + health_opts = options['health_check'] || {} + health_check['protocol'] = health_opts['protocol'] if health_opts.has_key?('protocol') + health_check['uri'] = health_opts['uri'] if health_opts.has_key?('uri') + health_check['port'] = health_opts['port'] if health_opts.has_key?('port') + health_check['timeout'] = health_opts['timeout'] if health_opts.has_key?('timeout') + health_check['interval'] = health_opts['interval'] if health_opts.has_key?('interval') + health_check['initial_delay'] = health_opts['initial_delay'] if health_opts.has_key?('initial_delay') + unless health_check.empty? + data['health_check'] = health_check + end data end # @param [Hash] options def merge_env_vars(options) @@ -75,24 +86,21 @@ end # @param [String] path def read_env_file(path) - File.readlines(path).delete_if { |line| line.start_with?('#') || line.empty? } + File.readlines(path).delete_if { |line| line.start_with?('#') || line.strip.empty? } end # @param [Array<String>] port_options # @return [Array<Hash>] - def parse_ports(port_options) - port_options.map{|p| - node_port, container_port, protocol = p.split(':') - if node_port.nil? || container_port.nil? - raise ArgumentError.new("Invalid port value #{p}") - end + def parse_stringified_ports(port_options) + parse_ports(port_options).map {|p| { - 'container_port' => container_port, - 'node_port' => node_port, - 'protocol' => protocol || 'tcp' + 'ip' => p[:ip], + 'container_port' => p[:container_port], + 'node_port' => p[:node_port], + 'protocol' => p[:protocol] } } end # @param [Array<String>] link_options