dockerdns 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/dockerdns.gemspec +30 -0
- data/lib/dockerdns.rb +157 -0
- data/lib/dockerdns/version.rb +3 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c30b840df5a1d230c845f7ecb229a039c6a893cc
|
4
|
+
data.tar.gz: 78806661a0c924c20067a86fb61f0b214d9bcd0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1428a61ca624d01a9a497705da5f15ce7d5d456200a6a684cd6d5b993e9fd2ec89c2312928714a6344a83692f9dbbd66a1f3919afad66b3b7af61c2a8d0b36c8
|
7
|
+
data.tar.gz: 371764b01c7d3f09c92703a04e7cbaaf4135559e992c530e6791ce8e1a3ed8b6cec57c2b003a1a491f5117abe78fb9f1443104c305d074595286cecace4583ba
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
sudo: false
|
4
|
+
|
5
|
+
script: "bundle exec rspec spec"
|
6
|
+
|
7
|
+
rvm:
|
8
|
+
- 2.2.1
|
9
|
+
before_install: gem install bundler -v 1.10.6
|
10
|
+
|
11
|
+
addons:
|
12
|
+
code_climate:
|
13
|
+
repo_token: 2f9b2fb5eb3e524f8fe9630902f32cd4f8f5d2ad671815b0289ee720a87b638d
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License:
|
2
|
+
|
3
|
+
Copyright (c) 2006-2014 Data Folk Labs, LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/cschritt/dockerdns.svg)](https://travis-ci.org/cschritt/dockerdns) [![Code Climate](https://codeclimate.com/github/cschritt/dockerdns/badges/gpa.svg)](https://codeclimate.com/github/cschritt/dockerdns) [![Test Coverage](https://codeclimate.com/github/cschritt/dockerdns/badges/coverage.svg)](https://codeclimate.com/github/cschritt/dockerdns/coverage)
|
2
|
+
# Dockerdns
|
3
|
+
This Gem give you the power to monitor the Docker event stream via it's API and send dynamic updates to a DNS server on certain events
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dockerdns'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dockerdns
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cschritt/dockerdns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://github.com/cschritt/dockerdns/blob/master/CODE_OF_CONDUCT.md) code of conduct.
|
27
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dockerdns"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dockerdns.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dockerdns/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dockerdns"
|
8
|
+
spec.version = Dockerdns::VERSION
|
9
|
+
spec.authors = ["Christian Schritt"]
|
10
|
+
spec.email = ["christian.schritt@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Monitor Docker events and dynamically update DNS zones}
|
13
|
+
spec.description = %q{This Gem give you the power to monitor the Docker event stream via it's API and send dynamic updates to a DNS server on certain events}
|
14
|
+
spec.homepage = "https://github.com/cschritt/dockerdns"
|
15
|
+
spec. license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# runtime dependencies
|
22
|
+
spec.add_runtime_dependency "dnsruby", "~> 1.50"
|
23
|
+
spec.add_runtime_dependency "docker-api", "~> 1.23"
|
24
|
+
|
25
|
+
# development dependencies
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
27
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
30
|
+
end
|
data/lib/dockerdns.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'dnsruby'
|
3
|
+
|
4
|
+
class DockerDNS
|
5
|
+
|
6
|
+
#==========================================================================
|
7
|
+
def self.run!(config)
|
8
|
+
DockerDNS.new(config).run!
|
9
|
+
end
|
10
|
+
#==========================================================================
|
11
|
+
|
12
|
+
def initialize(config)
|
13
|
+
@config = config
|
14
|
+
end
|
15
|
+
|
16
|
+
def domain
|
17
|
+
@config["domain"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def reversezone
|
21
|
+
@config["reversezone"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def resolver
|
25
|
+
@resolver ||= Dnsruby::Resolver.new(@config['dnsserver'])
|
26
|
+
end
|
27
|
+
|
28
|
+
def ttl
|
29
|
+
@config["ttl"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def docker_url
|
33
|
+
@config["dockerurl"] || '/var/run/docker.sock'
|
34
|
+
end
|
35
|
+
|
36
|
+
def run!
|
37
|
+
Docker.url = docker_url
|
38
|
+
Docker.options[:read_timeout] = 5
|
39
|
+
begin
|
40
|
+
Docker::Event.stream do |event|
|
41
|
+
case event.status
|
42
|
+
when "create"
|
43
|
+
next
|
44
|
+
when "start"
|
45
|
+
puts "caught event #{event.status} for container id #{event.id}"
|
46
|
+
create_or_update_dns_records!(event.id, domain)
|
47
|
+
when "die", "kill", "stop", "destroy"
|
48
|
+
puts "caught event #{event.status} for container id #{event.id}"
|
49
|
+
delete_dns_records!(event.id)
|
50
|
+
else
|
51
|
+
puts "Ignoring Docker Event #{event.status}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
rescue Docker::Error::TimeoutError, Excon::Errors::SocketError
|
55
|
+
retry
|
56
|
+
rescue StandardError => e
|
57
|
+
puts "Error while streaming events: #{e}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def container_ip(id)
|
62
|
+
Docker::Container.get(id).json["NetworkSettings"]["IPAddress"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def container_name(id)
|
66
|
+
Docker::Container.get(id).json["Config"]["Hostname"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def a_record(fqdn)
|
70
|
+
resolver.answer.first.address.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
def ptr_record(ipAddress)
|
74
|
+
resolver.query(ipAddress, "PTR").answer.first.domainname.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def set_a_record(ipAddress, hostname)
|
78
|
+
record = "#{hostname}.#{domain}"
|
79
|
+
puts "setting a-record #{record}"
|
80
|
+
update = Dnsruby::Update.new(domain)
|
81
|
+
# add record
|
82
|
+
puts "update.add(#{record}, 'A', #{ttl}, #{ipAddress})"
|
83
|
+
update.add(record, 'A', ttl, ipAddress)
|
84
|
+
# send update
|
85
|
+
begin
|
86
|
+
resolver.send_message(update)
|
87
|
+
puts "Update succeeded"
|
88
|
+
rescue Exception => e
|
89
|
+
puts "Update failed: #{e}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def delete_a_record(ipAddress, hostname)
|
94
|
+
record = "#{hostname}.#{domain}"
|
95
|
+
puts "deleting a-record #{record}"
|
96
|
+
update = Dnsruby::Update.new(domain)
|
97
|
+
# delete record
|
98
|
+
puts "update.delete(#{record})"
|
99
|
+
update.delete(record)
|
100
|
+
# send update
|
101
|
+
begin
|
102
|
+
resolver.send_message(update)
|
103
|
+
puts "Update succeeded"
|
104
|
+
rescue Exception => e
|
105
|
+
puts "Update failed: #{e}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_ptr_record(ipAddress, hostname)
|
110
|
+
record = "#{ipAddress.split('.').last}.#{reversezone}"
|
111
|
+
puts "setting ptr-record #{record}"
|
112
|
+
update = Dnsruby::Update.new(reversezone)
|
113
|
+
# add record
|
114
|
+
puts "update.add(#{record}, 'PTR', #{ttl}, #{fqdn})"
|
115
|
+
update.add(record, 'PTR', ttl, fqdn)
|
116
|
+
# send update
|
117
|
+
begin
|
118
|
+
resolver.send_message(update)
|
119
|
+
puts "Update succeeded"
|
120
|
+
rescue Exception => e
|
121
|
+
puts "Update failed: #{e}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def delete_ptr_record(ipAddress, hostname)
|
126
|
+
record = "#{ipAddress.split('.').last}.#{reversezone}"
|
127
|
+
puts "deleting ptr-record #{record}"
|
128
|
+
update = Dnsruby::Update.new(reversezone)
|
129
|
+
# delete record
|
130
|
+
puts "update.delete(#{record})"
|
131
|
+
update.delete(record)
|
132
|
+
# send update
|
133
|
+
begin
|
134
|
+
resolver.send_message(update)
|
135
|
+
puts "Update succeeded"
|
136
|
+
rescue Exception => e
|
137
|
+
puts "Update failed: #{e}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def create_or_update_dns_records!(id)
|
142
|
+
hostname = container_name(id)
|
143
|
+
ipAddress = container_ip(id)
|
144
|
+
set_a_record(ipAddress, hostname)
|
145
|
+
set_ptr_record(ipAddress, hostname)
|
146
|
+
a_record("#{hostname}.#{domain}")
|
147
|
+
ptr_record(ipAddress)
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def delete_dns_records!(id)
|
152
|
+
hostname = container_name(id)
|
153
|
+
ipAddress = a_record("#{hostname}.#{domain}")
|
154
|
+
delete_a_record(ipAddress, hostname)
|
155
|
+
delete_ptr_record(ipAddress, hostname)
|
156
|
+
end
|
157
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dockerdns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Schritt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dnsruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.50'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.50'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: docker-api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.23'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.23'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
description: This Gem give you the power to monitor the Docker event stream via it's
|
98
|
+
API and send dynamic updates to a DNS server on certain events
|
99
|
+
email:
|
100
|
+
- christian.schritt@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- dockerdns.gemspec
|
116
|
+
- lib/dockerdns.rb
|
117
|
+
- lib/dockerdns/version.rb
|
118
|
+
homepage: https://github.com/cschritt/dockerdns
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.5.1
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Monitor Docker events and dynamically update DNS zones
|
142
|
+
test_files: []
|