class Nib::Integrate::IntegrationFileConfig
IntegrationFileConfig
creates a proper configuration yaml string and keeps track of port assignments
Attributes
app_name[R]
current_port[R]
Public Class Methods
new(app_name, current_port)
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 9 def initialize(app_name, current_port) @app_name = app_name @current_port = current_port end
Public Instance Methods
config()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 14 def config OpenStruct.new( config: config_hash, path: path, port: current_port ) end
empty_config()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 22 def empty_config OpenStruct.new( config: { 'version' => app_compose_contents['version'] }, path: empty_path ) end
Private Instance Methods
app()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 47 def app apps.find { |a| a['name'] == app_name } end
app_compose_contents()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 108 def app_compose_contents YAML.load_file("#{app['path']}/#{app['compose_file']}") end
app_docker_compose()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 104 def app_docker_compose @app_docker_compose ||= app_compose_contents end
app_services()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 112 def app_services app_docker_compose['services'].keys end
apps()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 43 def apps @apps ||= global_config['apps'] end
config_hash()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 31 def config_hash app_services.each_with_object(merged_config) do |elem, acc| service_definition = { 'external_links' => external_links, 'networks' => %w[default nib] } service_definition['ports'] = ports(elem) if ports(elem) acc['services'][elem].merge!(service_definition) end end
container_name(registration)
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 90 def container_name(registration) project_name = registration['path'].split('/').last.gsub(/[ _]/, '') service_name = registration['service'] "#{project_name}_#{service_name}" end
empty_path()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 59 def empty_path "#{app['path']}/.nib-integrate-empty-config-file" end
external_link()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 84 def external_link lambda do |registration| "#{container_name(registration)}_1:#{container_name(registration)}" end end
external_links()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 80 def external_links other_apps.map(&external_link) end
global_config()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 116 def global_config ConfigFile.read end
merged_config()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 63 def merged_config app_compose_contents.merge(network_config) end
network_config()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 96 def network_config { 'networks' => { 'nib' => { 'external' => { 'name' => 'nib-integrate-network' } } } } end
next_port()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 76 def next_port @current_port += 1 end
other_apps()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 51 def other_apps apps.reject { |a| a['name'] == app_name } end
path()
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 55 def path "#{app['path']}/.nib-integrate-network-config" end
ports(service_definition)
click to toggle source
# File lib/nib/integrate/integration_file_config.rb, line 67 def ports(service_definition) ports = app_docker_compose['services'][service_definition]['ports'] return unless ports && !ports.empty? ports.map do |port| existing_ports = port.split(':') [next_port, existing_ports[1]].join(':') end end