docker_boss 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a3b4b55a8a45eb94a4f4273cc1d7aa7aba31ac8
4
- data.tar.gz: 642f6c1f450af4c0af50ffd5250ef1add388f5fe
3
+ metadata.gz: 989d68fca738c872db812e961eb3689e989aa25a
4
+ data.tar.gz: 965fa76de0e26be5dbf48058c2245823e6fbcf9c
5
5
  SHA512:
6
- metadata.gz: 06e1efa8c82701c1f60a2108c481476866f949743ab8afd4a58030465b6bab57b99fd8feea5c2d306e92d8bcde5d0dbf71c7d3303c8bc47ae96be9d1c7d700be
7
- data.tar.gz: 7cc522cecde379acd03a4b9f04bfec8551c263b4633ee346660bfbb05daa65aad102739dafef46979cb22a84cd9f375490791776645d3dee9f51c4c196e64f79
6
+ metadata.gz: 20942bbc9402ddffa2e9fccff0e8654092a09d38dc16b78148192366ce82adbd4102c6e18b78b5e29b05d982cd56fa99bbcb35af1001178763dd1c415fcd9c02
7
+ data.tar.gz: 15644b7957449c2f917d23cd5b89f155c53c2f844f1e41d796bd23c304280cd58c6a322eb44b54b9f68a0a798fdf1d94031534d5d3391e2e4dbe220fbb2e5aa3
data/README.md CHANGED
@@ -10,6 +10,9 @@ DockerBoss has been built from the start to be completely pluggable. By default,
10
10
 
11
11
  - dns: The dns module has a very simple built-in DNS server. The DNS server's records get updated based on the container's addresses, names, environment variables, etc. The DNS server will pass through requests for zones that it is not the authoritative server for.
12
12
 
13
+ The pluggable design of DockerBoss, alongside the flexibility offered by the default modules, makes it possible to adapt DockerBoss to a large number of different use cases and scenarios, without being tied down to one particular convention as others do.
14
+
15
+
13
16
  ## Installation
14
17
 
15
18
  Add this line to your application's Gemfile:
@@ -247,9 +250,9 @@ A very simple example template file could look as follows:
247
250
 
248
251
  The etcd module adds/updates/removes keys in etcd based on changes to the containers. This can be used to provide dynamic settings based on the containers to other tools interfacing with etcd, such as SkyDNS and confd.
249
252
 
250
- The `server` setting defines the host and port of the etcd server. SSL and basic HTTP auth are not yet supported.
253
+ The `server` setting defines the host and port of the etcd server. SSL and basic HTTP auth are not yet supported. The `host` field is rendered as an ERB template, and has access to two helper functions, `interface_ipv4(some_intf)` and `interface_ipv6(some_intf)` which get the IPv4 or IPv6 address of a particular host interface.
251
254
 
252
- The `setup` setting is a template, each line of which can manipulate keys in etcd. These key manipulations are run once when the module/DockerBoss starts, and can be used to ensure a clean slate, free of any old keys from a previous run. Each line must follow one of the following formats:
255
+ The `setup` setting is a template, each line of which can manipulate keys in etcd. These key manipulations are run once when the module/DockerBoss starts, and can be used to ensure a clean slate, free of any old keys from a previous run. The `setup` template can use the `interface_ipv4` and `interface_ipv6` helpers. Each line must follow one of the following formats:
253
256
 
254
257
  - `ensure <key> <value>` - sets a given key in etcd to the given value.
255
258
  - `absent <key>` - removes a given key in etcd.
@@ -259,19 +262,20 @@ The `sets` setting supports any number of children, each of which is an ERB temp
259
262
 
260
263
  - `ensure <key> <value>` - ensure a key exists in etcd with the given value.
261
264
 
262
- The etcd will keep track of keys set during previous state updates, and if a key is no longer present, it will be removed from etcd.
265
+ The etcd module will keep track of keys set during previous state updates, and if a key is no longer present, it will be removed from etcd.
263
266
 
264
267
  Example configuration:
265
268
 
266
269
  ```yaml
267
270
  etcd:
268
271
  server:
269
- host: '127.0.0.1'
272
+ host: <%= interface_ipv4('docker0') %>
270
273
  port: 4001
271
274
 
272
275
  setup: |
273
276
  absent_recursive /skydns/docker
274
277
  absent_recursive /vhosts
278
+ ensure /skydns/docker/dockerhost/etcd <%= as_json(host: interface_ipv4('docker0'), port: '4001') %>
275
279
 
276
280
  sets:
277
281
  skydns: |
@@ -299,12 +303,14 @@ The DNS module starts a built-in DNS server based on `rubydns`. The DNS server c
299
303
 
300
304
  The `ttl` setting determines the `ttl` for each response, both positive and NXDOMAIN.
301
305
 
302
- The `listen` setting is an array of addresses/ports on which the DNS server should listen.
306
+ The `listen` setting is an array of addresses/ports on which the DNS server should listen. As with the `server.host` key for the etcd module, the `host` key is a template with access to the `interface_ipv4` and `interface_ipv6` helpers.
303
307
 
304
308
  The `upstream` setting is an array of upstream DNS servers to which requests should be forwarded to if no record is available locally and the name is not within one of the local zones.
305
309
 
306
310
  The `zones` setting is an array of zones for which the DNS server is authoritative. The DNS server will not forward requests in these zones to upstream DNS servers, not even if no local record is found.
307
311
 
312
+ The `setup` setting is a template, each line of which adds a new DNS record at setup time, independently of any containers. These records are added when the module/DockerBoss starts. Each line must follow the format of `some_host_name some_ip_address`. The `setup` template can use the `interface_ipv4` and `interface_ipv6` helpers.
313
+
308
314
  The `spec` setting is an ERB template which should render out all hostnames for a given container, each on a separate line. A container can have any number of host records, even none at all (by simply not rendering out any hostname).
309
315
 
310
316
  Example configuration:
@@ -313,7 +319,9 @@ Example configuration:
313
319
  dns:
314
320
  ttl: 5
315
321
  listen:
316
- - host: 0.0.0.0
322
+ - host: <%= interface_ipv4('docker0') %>
323
+ port: 5300
324
+ - host: 127.0.0.1
317
325
  port: 5300
318
326
 
319
327
  upstream:
@@ -324,6 +332,9 @@ dns:
324
332
  - .local
325
333
  - .docker
326
334
 
335
+ setup: |
336
+ etcd.dockerhost.docker <%= interface_ipv4('docker0') %>
337
+
327
338
  spec: |
328
339
  <%= container['Config']['Env'].fetch('SERVICE_NAME', container['Name'][1..-1]) %>.docker
329
340
  <%= container['Config']['Hostname'] %>.docker
@@ -359,7 +370,7 @@ class DockerBoss::Module::Foo < DockerBoss::Module
359
370
  def trigger(containers, trigger_id)
360
371
  DockerBoss.logger.debug "foo: State change triggered by container_id=#{trigger_id}"
361
372
  containers.each do |c|
362
- DockerBoss.logger.debug "foo: container: #{c['Id]}"
373
+ DockerBoss.logger.debug "foo: container: #{c['Id']}"
363
374
  end
364
375
  end
365
376
  end
@@ -1,7 +1,7 @@
1
1
  dns:
2
2
  ttl: 5
3
3
  listen:
4
- - host: 0.0.0.0
4
+ - host: <%= interface_ipv4('docker0') %>
5
5
  port: 5300
6
6
 
7
7
  upstream:
@@ -12,17 +12,21 @@ dns:
12
12
  - .local
13
13
  - .docker
14
14
 
15
+ setup: |
16
+ etcd.dockerhost.docker <%= interface_ipv4('docker0') %>
17
+
15
18
  spec: |
16
19
  <%= container['Config']['Env'].fetch('SERVICE_NAME', container['Name'][1..-1]) %>.docker
17
20
  <%= container['Config']['Hostname'] %>.docker
18
21
 
19
22
  etcd:
20
23
  server:
21
- host: '127.0.0.1'
24
+ host: <%= interface_ipv4('docker0') %>
22
25
  port: 4001
23
26
 
24
27
  setup: |
25
28
  absent_recursive /skydns/docker
29
+ ensure /skydns/docker/dockerhost/etcd <%= as_json(host: interface_ipv4('docker0'), port: '4001') %>
26
30
 
27
31
  sets:
28
32
  skydns: |
@@ -7,6 +7,7 @@ module DockerBoss::Helpers
7
7
  def self.render_erb(template_str, data)
8
8
  tmpl = ERB.new(template_str)
9
9
  ns = OpenStruct.new(data)
10
+ ns.extend(TemplateHelpers)
10
11
  tmpl.result(ns.instance_eval { binding })
11
12
  end
12
13
 
@@ -41,5 +42,17 @@ module DockerBoss::Helpers
41
42
  def as_json(hash)
42
43
  hash.to_json
43
44
  end
45
+
46
+ def interface_ipv4(iface)
47
+ ipv4 = `ip addr show docker0 | grep -Po 'inet \\K[\\d.]+'`
48
+ raise ArgumentError, "Could not retrieve IPv4 address for interface `#{iface}`" unless $? == 0
49
+ ipv4.chomp
50
+ end
51
+
52
+ def interface_ipv6(iface)
53
+ ipv6 = `ip addr show docker0 | grep -Po 'inet6 \\K[\\da-f:]+'`
54
+ raise ArgumentError, "Could not retrieve IPv6 address for interface `#{iface}`" unless $? == 0
55
+ ipv6.chomp
56
+ end
44
57
  end
45
58
  end
@@ -9,26 +9,39 @@ class DockerBoss::Module::DNS < DockerBoss::Module
9
9
 
10
10
  def initialize(config)
11
11
  @records = {}
12
+ @setup_records = {}
12
13
  @config = config
13
14
  DockerBoss.logger.debug "dns: Set up"
15
+ setup
16
+ end
17
+
18
+ def setup
19
+ setup = DockerBoss::Helpers.render_erb(@config.fetch('setup', ''), {})
20
+ setup.lines.each do |line|
21
+ (name, ip) = line.lstrip.chomp.split(" ", 2)
22
+ @setup_records[name] = ip
23
+ end
14
24
  end
15
25
 
16
26
  def run
17
27
  listen = []
18
- @config['listen'].each do |l|
19
- listen << [:udp, l['host'], l['port'].to_i]
20
- listen << [:tcp, l['host'], l['port'].to_i]
21
- end
22
28
 
23
29
  DockerBoss.logger.debug "dns: Starting DNS server"
24
30
 
31
+ @config['listen'].each do |l|
32
+ host = DockerBoss::Helpers.render_erb(l['host'], {})
33
+ listen << [:udp, host, l['port'].to_i]
34
+ listen << [:tcp, host, l['port'].to_i]
35
+ DockerBoss.logger.debug "dns: Listening on #{host} (port: #{l['port']})"
36
+ end
37
+
25
38
  Thread.new do
26
39
  RubyDNS::run_server(:listen => listen, :ttl => @config['ttl'], :upstream_dns => @config['upstream'], :zones => @config['zones'], :supervisor_class => Server, :manager => self)
27
40
  end
28
41
  end
29
42
 
30
43
  def trigger(containers, trigger_id)
31
- records = {}
44
+ records = @setup_records.clone
32
45
  containers.each do |c|
33
46
  names = DockerBoss::Helpers.render_erb(@config['spec'], :container => c)
34
47
  names.lines.each do |n|
@@ -10,14 +10,16 @@ require 'etcd'
10
10
  class DockerBoss::Module::Etcd < DockerBoss::Module
11
11
  def initialize(config)
12
12
  @config = config
13
- DockerBoss.logger.debug "etcd: Set up to connect to #{@config['server']['host']}, port #{@config['server']['port']}"
14
- @client = ::Etcd.client(host: @config['server']['host'], port: @config['server']['port'])
13
+ @host = DockerBoss::Helpers.render_erb(@config['server']['host'], {})
14
+ DockerBoss.logger.debug "etcd: Set up to connect to #{@host}, port #{@config['server']['port']}"
15
+ @client = ::Etcd.client(host: @host, port: @config['server']['port'])
15
16
  @previous_keys = {}
16
17
  setup
17
18
  end
18
19
 
19
20
  def setup
20
- @config.fetch('setup', '').lines.each do |line|
21
+ setup = DockerBoss::Helpers.render_erb(@config.fetch('setup', ''), {})
22
+ setup.lines.each do |line|
21
23
  (kw, k, v) = line.lstrip.chomp.split(" ", 3)
22
24
  case kw
23
25
  when 'absent'
@@ -1,3 +1,3 @@
1
1
  module DockerBoss
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_boss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Hornung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api