kontejner 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbaa3f962384589a3f874a95a9562efcded6cf21
4
+ data.tar.gz: f2f96e863e696e2b19ad22699c84e1ddb77996fe
5
+ SHA512:
6
+ metadata.gz: b748acbb71776e0dda218bd42012e613f484264824209f2d690a80d3a7b7a88d8b18c3d0bbf676d0ce366485afcccc2a99b52d9bb8afdefe1468b6fca1c7168e
7
+ data.tar.gz: f3a3d05fffb1bcdf9ac3864266b1bb484692104503f2b69d7f82e2a42dc3e0367d3a342a0f470a986afe62fc5542339ebb635e957b0a76e17ec090ec25358c9a
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .*.swp
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Dockerfile ADDED
@@ -0,0 +1,8 @@
1
+ FROM ubuntu:trusty
2
+
3
+ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 80F70E11F0F0D5F10CB20E62F5DA5F09C3173AA6 \
4
+ && echo 'deb http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu precise main' > /etc/apt/sources.list.d/ruby-ng.list \
5
+ && apt-get -y -q update \
6
+ && apt-get -y -q install git-core ruby2.1 rubygems ruby-switch \
7
+ && ruby-switch --set ruby2.1 \
8
+ && gem install bundler --no-rdoc --no-ri
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.1.2'
4
+ # Specify your gem's dependencies in kontejner.gemspec
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'pry-byebug'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michal Cichra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,8 @@
1
+ REPO=mikz/kontejner
2
+
3
+ all: build
4
+
5
+ build:
6
+ docker build -t $(REPO) --rm .
7
+ push:
8
+ docker push $(REPO)
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Kontejner
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'kontejner'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install kontejner
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/kontejner/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/kontejner ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kontejner'
4
+
5
+ Kontejner::CLI.start
data/kontejner.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kontejner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kontejner'
8
+ spec.version = Kontejner::VERSION
9
+ spec.authors = ['Michal Cichra']
10
+ spec.email = %w[michal@o2h.cz]
11
+ spec.summary = %q{DNS server for Docker}
12
+ spec.description = %q{DNS server for Docker running on Ruby}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w[lib]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
24
+
25
+ spec.add_dependency 'rubydns', '~> 0.8.4'
26
+ spec.add_dependency 'thor', '~> 0.19.1'
27
+ spec.add_dependency 'docker-api', '~> 1.13'
28
+ spec.add_dependency 'activesupport', '~> 4.1.4'
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'thor'
2
+ require 'kontejner'
3
+
4
+ module Kontejner
5
+ class CLI < Thor
6
+ desc 'start', 'start kontejner dns server'
7
+
8
+ method_option :port, default: 53, type: :numeric
9
+ method_option :address, default: '0.0.0.0', type: :string
10
+
11
+ method_option :domain, required: true, type: :string
12
+ method_option :docker, required: true, default: Docker.default_socket_url, type: :string
13
+ method_option :ttl, require: true, type: :numeric, default: 60
14
+
15
+ def start
16
+ server = Kontejner::Server.new(dns_options)
17
+ server.start(server_options)
18
+ end
19
+
20
+ private
21
+
22
+ def dns_options
23
+ { domain: options[:domain], docker: options[:docker], ttl: options[:ttl] }
24
+ end
25
+
26
+ def server_options
27
+ address = options[:address]
28
+ port = options[:port]
29
+
30
+ { listen: [[:tcp, address, port], [:udp, address, port]] }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ require 'docker'
2
+ require 'active_support/cache'
3
+
4
+ module Kontejner
5
+ class Resolver
6
+ def initialize(docker:)
7
+ @connection = Docker::Connection.new(docker, {})
8
+ @cache = ActiveSupport::Cache::MemoryStore.new
9
+ end
10
+
11
+ def resolve(name)
12
+ @cache.fetch(name, expires_in: 60) { fetch(name) }
13
+ rescue Docker::Error::NotFoundError
14
+ end
15
+
16
+ def fetch(name)
17
+ container = Docker::Container.get(name, {}, @connection)
18
+ container.json['NetworkSettings']['IPAddress']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'rubydns'
2
+ require 'kontejner/resolver'
3
+
4
+ module Kontejner
5
+ class Server
6
+ GOOGLE_SERVERS = [ [:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53], [:udp, '8.8.4.4', 53], [:udp, '8.8.4.4', 53] ]
7
+
8
+ IN = Resolv::DNS::Resource::IN
9
+
10
+ def initialize(domain:,docker:,ttl:)
11
+ @upstream = RubyDNS::Resolver.new(GOOGLE_SERVERS)
12
+ @docker = Kontejner::Resolver.new(docker: docker)
13
+
14
+ @dns = RubyDNS::RuleBasedServer.new
15
+ @dns.logger.level = Logger::INFO
16
+
17
+ @dns.match(/(?<subdomain>[^.]+)\.#{domain}$/, IN::A) do |t, match|
18
+ ip = @docker.resolve(match[:subdomain])
19
+
20
+ if ip
21
+ t.respond!(ip, ttl: ttl)
22
+ else
23
+ t.fail! :NoError
24
+ end
25
+ end
26
+
27
+ @dns.otherwise do |q|
28
+ q.passthrough!(@upstream)
29
+ end
30
+ end
31
+
32
+ def start(**options)
33
+ EventMachine.run do
34
+ trap("INT") do
35
+ EventMachine.stop
36
+ end
37
+
38
+ @dns.run(options)
39
+ end
40
+
41
+ @dns.fire(:stop)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Kontejner
2
+ VERSION = "0.0.1"
3
+ end
data/lib/kontejner.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'kontejner/version'
2
+ require 'docker'
3
+
4
+ module Kontejner
5
+ autoload :CLI, 'kontejner/cli'
6
+ autoload :Server, 'kontejner/server'
7
+ autoload :Resolver, 'kontejner/resolver'
8
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'kontejner/cli'
2
+
3
+ describe Kontejner::CLI do
4
+ it { should be }
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'kontejner/resolver'
2
+
3
+ describe Kontejner::Resolver do
4
+ it { expect(described_class).to be }
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'kontejner/server'
2
+
3
+ describe Kontejner::Server do
4
+ it { expect(described_class).to be }
5
+ end
@@ -0,0 +1,74 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # These two settings work together to allow you to limit a spec run
19
+ # to individual examples or groups you care about by tagging them with
20
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
21
+ # get run.
22
+ config.filter_run :focus
23
+ config.run_all_when_everything_filtered = true
24
+
25
+ # Many RSpec users commonly either run the entire suite or an individual
26
+ # file, and it's useful to allow more verbose output when running an
27
+ # individual spec file.
28
+ if config.files_to_run.one?
29
+ # Use the documentation formatter for detailed output,
30
+ # unless a formatter has already been configured
31
+ # (e.g. via a command-line flag).
32
+ config.default_formatter = 'doc'
33
+ end
34
+
35
+ # Print the 10 slowest examples and example groups at the
36
+ # end of the spec run, to help surface which specs are running
37
+ # particularly slow.
38
+ config.profile_examples = 10
39
+
40
+ # Run specs in random order to surface order dependencies. If you find an
41
+ # order dependency and want to debug it, you can fix the order by providing
42
+ # the seed, which is printed after each run.
43
+ # --seed 1234
44
+ config.order = :random
45
+
46
+ # Seed global randomization in this process using the `--seed` CLI option.
47
+ # Setting this allows you to use `--seed` to deterministically reproduce
48
+ # test failures related to randomization by passing the same `--seed` value
49
+ # as the one that triggered the failure.
50
+ Kernel.srand config.seed
51
+
52
+ # rspec-expectations config goes here. You can use an alternate
53
+ # assertion/expectation library such as wrong or the stdlib/minitest
54
+ # assertions if you prefer.
55
+ config.expect_with :rspec do |expectations|
56
+ # Enable only the newer, non-monkey-patching expect syntax.
57
+ # For more details, see:
58
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
+ expectations.syntax = :expect
60
+ end
61
+
62
+ # rspec-mocks config goes here. You can use an alternate test double
63
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
64
+ config.mock_with :rspec do |mocks|
65
+ # Enable only the newer, non-monkey-patching expect syntax.
66
+ # For more details, see:
67
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
+ mocks.syntax = :expect
69
+
70
+ # Prevents you from mocking or stubbing a method that does not exist on
71
+ # a real object. This is generally recommended.
72
+ mocks.verify_partial_doubles = true
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kontejner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michal Cichra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubydns
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.19.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.19.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: docker-api
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.13'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.1.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.1.4
111
+ description: DNS server for Docker running on Ruby
112
+ email:
113
+ - michal@o2h.cz
114
+ executables:
115
+ - kontejner
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - Dockerfile
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - Makefile
125
+ - README.md
126
+ - Rakefile
127
+ - bin/kontejner
128
+ - kontejner.gemspec
129
+ - lib/kontejner.rb
130
+ - lib/kontejner/cli.rb
131
+ - lib/kontejner/resolver.rb
132
+ - lib/kontejner/server.rb
133
+ - lib/kontejner/version.rb
134
+ - spec/cli_spec.rb
135
+ - spec/resolver_spec.rb
136
+ - spec/server_spec.rb
137
+ - spec/spec_helper.rb
138
+ homepage: ''
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.2.2
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: DNS server for Docker
162
+ test_files:
163
+ - spec/cli_spec.rb
164
+ - spec/resolver_spec.rb
165
+ - spec/server_spec.rb
166
+ - spec/spec_helper.rb