lib/minke/docker/service_discovery.rb in minke-1.10.0 vs lib/minke/docker/service_discovery.rb in minke-1.11.0

- old
+ new

@@ -1,13 +1,14 @@ module Minke module Docker ## # ServiceDiscovery allows you to look up the publicly accessible address and port for a server class ServiceDiscovery - def initialize project_name, docker_runner + def initialize project_name, docker_runner, docker_network = nil @project_name = project_name @docker_runner = docker_runner + @docker_network = docker_network end ## # Will attempt to locate the public details for a running container given # its name and private port @@ -45,10 +46,24 @@ raise "Unable to find bridge address for network: #{network}, container: #{service_name}, port: #{private_port}" end return "#{ip}:#{private_port}" end - :private + ## + # builds an address for the given url + def build_address url + if url.type == 'external' + "#{url.protocol}://#{url.address}:#{url.port}#{url.path}" + elsif url.type == 'bridge' + address = bridge_address_for @docker_network, url.address, url.port + "#{url.protocol}://#{address}#{url.path}" + elsif url.type == 'public' + address = public_address_for url.address, url.port + "#{url.protocol}://#{address}#{url.path}" + end + end + + private def find_container_by_name name containers = @docker_runner.running_containers containers.select { |c| c.info['Names'].include?(name) } end end