Class: DockerBoss::Module::DNS

Inherits:
DockerBoss::Module show all
Defined in:
lib/docker_boss/module/dns.rb

Defined Under Namespace

Classes: Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DockerBoss::Module

inherited

Constructor Details

#initialize(config) ⇒ DNS

Returns a new instance of DNS.



10
11
12
13
14
15
16
# File 'lib/docker_boss/module/dns.rb', line 10

def initialize(config)
  @records = {}
  @setup_records = {}
  @config = config
  DockerBoss.logger.debug "dns: Set up"
  setup
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



8
9
10
# File 'lib/docker_boss/module/dns.rb', line 8

def records
  @records
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/docker_boss/module/dns.rb', line 26

def run
  listen = []

  DockerBoss.logger.debug "dns: Starting DNS server"

  @config['listen'].each do |l|
    host = DockerBoss::Helpers.render_erb(l['host'], {})
    listen << [:udp, host, l['port'].to_i]
    listen << [:tcp, host, l['port'].to_i]
    DockerBoss.logger.debug "dns: Listening on #{host} (port: #{l['port']})"
  end

  Thread.new do
    RubyDNS::run_server(:listen => listen, :ttl => @config['ttl'], :upstream_dns => @config['upstream'], :zones => @config['zones'], :supervisor_class => Server, :manager => self)
  end
end

#setupObject



18
19
20
21
22
23
24
# File 'lib/docker_boss/module/dns.rb', line 18

def setup
  setup = DockerBoss::Helpers.render_erb(@config.fetch('setup', ''), {})
  setup.lines.each do |line|
    (name, ip) = line.lstrip.chomp.split(" ", 2)
    @setup_records[name] = ip
  end
end

#trigger(containers, trigger_id) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/docker_boss/module/dns.rb', line 43

def trigger(containers, trigger_id)
  records = @setup_records.clone
  containers.each do |c|
    names = DockerBoss::Helpers.render_erb(@config['spec'], :container => c)
    names.lines.each do |n|
      records[n.lstrip.chomp] = c['NetworkSettings']['IPAddress']
    end
  end

  @records = records
end