vagrant-dns 2.0.0 → 2.1.0

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: b99205f3d200b610ee3b9c0fd3e3f3c84e99377a
4
- data.tar.gz: e1677768a2c0117a10f8f5caf58ab9359124643b
3
+ metadata.gz: 63885c6803289a7e6e199a44dbf761fb10683e90
4
+ data.tar.gz: d96529364b2f27a2f0237610dc02cdc69ca5745a
5
5
  SHA512:
6
- metadata.gz: 43bcb3a01c66b768ab75003f4add646658e7fb6e4c15e552a22ce6ddf85ce034c8738f96a8c3093e603f0dd963151a8fc578ff16ef73e81c5e471125d645df3a
7
- data.tar.gz: 4492147711e59b16309206707b3eabcad0d92ca3b94392344e5bed70ce7703e37b705c4e7df5e896f7e494d86446db57545adacc962eb0a9d90b324cf8594082
6
+ metadata.gz: b85c14d3d21603561ce7e9179182e3702c31e89d98cb8deae725fa6c513730089da2fb964dc2f69842e7667797941826fd7a97b6bf03deb0f9da24edf7f035b4
7
+ data.tar.gz: 82c123e1d400655805226e8ad62604ce0f5c3a6886517d81ea00f18a209f63b12a6e388a0e265be9a4eab51cc82af38f3af462d3117d5c3fc3041f28b7512c6b
@@ -1,14 +1,35 @@
1
- # 2.0.0
1
+ ## 2.1.0
2
+
3
+ ### Breaking, internal changes:
4
+
5
+ * The version moved from `Vagrant::DNS::VERSION` to `VagrantDNS::VERSION`, removing an accidental highjack of the `Vagrant` namespace.
6
+ * The `VagrantDNS::RestartMiddleware` got split up into `VagrantDNS::Middlewares::ConfigUp`, `VagrantDNS::Middlewares::ConfigDown` and `VagrantDNS::Middlewares::Restart`
7
+
8
+ ### Fixes:
9
+
10
+ * Fixes cli short argument `-S` for `--stop` (collided with `--start`'s `-s`)
11
+
12
+ ### New Feautres:
13
+
14
+ * Adds new cli command `--status` to display process running status and PID
15
+ * Adds new cli command `--list` to display current (persisted) config
16
+ * Adds auto-cleanup: Removes registered dns pattern from config when destroying the box. It will, however, be re-created when some box in the project get's re/started or one of vagrant dns `--instal`, `--start` or `--restart` is executed.
17
+
18
+ ### Changes:
19
+
20
+ * The cli command `--stop` no longer re-builds configuration.
21
+
22
+ ## 2.0.0
2
23
 
3
24
  * Upgrades RubyDNS to `2.0` release
4
25
 
5
- # 2.0.0.rc1
26
+ ## 2.0.0.rc1
6
27
 
7
28
  * Upgrades RubyDNS to `2.0.0.pre.rc2`, which removes it's dependency on `celluloid`/`celluloid-dns` 🎉
8
29
  * Requires Vagrant >= 1.9.6 which ships with ruby 2.3.4 (RubyDNS requires ruby >= 2.2.6)
9
30
  * Development note: Upgraded to vagrant-share HEAD (d558861f)
10
31
 
11
- # 1.1.0
32
+ ## 1.1.0
12
33
 
13
34
  * Fixes handling of networks without static IP, such as DHCP. [GH-37], [GH-39], [GH-50]
14
35
  * Add support for boxes with `public_network` and static IP.
@@ -16,12 +37,12 @@
16
37
  * Log messages will now be tagged with the related box (vm) and `[vagrant-dns]`
17
38
  * Develepment targets Vagrant 1.9.3
18
39
 
19
- # 1.0.0
40
+ ## 1.0.0
20
41
 
21
42
  * 🎉Release as 1.0 [GH-34]
22
43
  * Fixes compatibility to Vagrant 1.7.4 by using RubyDNS ~> 1.0.2 [GH-38]
23
44
 
24
- # 0.6.0
45
+ ## 0.6.0
25
46
 
26
47
  This is a intermediate release towards v1.0.0
27
48
 
@@ -32,16 +53,16 @@ This is a intermediate release towards v1.0.0
32
53
  * Add acceptance test using vagrant-spec
33
54
  * Moved sample `Vagrantfile` into `/testdrive` which also contains a small wrapper script `bin/vagrant` to move "vagrant home" into a sandbox.
34
55
 
35
- # 0.5.0
56
+ ## 0.5.0
36
57
 
37
58
  * Use `osascript` to install system files, which require root privileges. [GH-18], [GH-22]
38
59
  * internal cleanups (@ringods)
39
60
 
40
- # v0.4.1
61
+ ## v0.4.1
41
62
 
42
63
  * Fixes an issue with not configured private networks [GH-21], [GH-19]
43
64
 
44
- # v0.4.0
65
+ ## v0.4.0
45
66
 
46
67
  **This version is not compatible to vagrant < 1.2**
47
68
 
@@ -50,33 +71,33 @@ This is a intermediate release towards v1.0.0
50
71
  * Fixes an issue where user-space files got created as root [GH-12]
51
72
  * Adds command line option `--purge` which deletes the created config file (not only the system symlink to it) [GH-3]
52
73
 
53
- # v0.3.0
74
+ ## v0.3.0
54
75
 
55
76
  * Using RubyDNS ~> 0.5.3
56
77
 
57
- # v0.2.5
78
+ ## v0.2.5
58
79
 
59
80
  * Using RubyDNS 0.4.x
60
81
 
61
- # v0.2.4
82
+ ## v0.2.4
62
83
 
63
84
  * Enable passthrough in DNS service. Helpful if you insist to hook a standard tld like .io.
64
85
 
65
- # v0.2.3
86
+ ## v0.2.3
66
87
 
67
88
  * Remove unneeded iteraton in installers/mac.rb. (thanks to JonathanTron for reporting)
68
89
  * Fix crash when no tld option was given.
69
90
 
70
- # v0.2.2
91
+ ## v0.2.2
71
92
 
72
93
  * Default to 127.0.0.1 when no network option is given
73
94
  * Warn if no default pattern is configured because TLD is given, but no host_name
74
95
 
75
- # v0.2.1
96
+ ## v0.2.1
76
97
 
77
98
  * Fix a crash when /etc/resolver is not present
78
99
 
79
- # v0.2.0
100
+ ## v0.2.0
80
101
 
81
102
  * Deactivate ipv6 support (was broken anyways)
82
103
  * Add multiple patterns support
@@ -86,7 +107,7 @@ This is a intermediate release towards v1.0.0
86
107
  * Uses one central server now
87
108
  * The DNS server is now reconfigured on every run
88
109
 
89
- # v0.1.0
110
+ ## v0.1.0
90
111
 
91
112
  * Initial Release
92
113
  * Support for A and AAAA configuration
@@ -0,0 +1,23 @@
1
+ # Development Guidelines
2
+
3
+ TODO: Expand this section :)
4
+
5
+ The `Gemfile` uses two environment variables, `TEST_RUBY_VERSION` and `TEST_VAGRANT_VERSION` to control which version of ruby and vagrant are used during local development.
6
+
7
+ ## Running Acceptance Tests
8
+
9
+ This project uses `vagrant-spec` to run acceptance tests.
10
+ See `test/acceptance/dns` for spec files and `test/acceptance/skeletons/*` for Vagrantfiles.
11
+ See `tasks/acceptance.rake` for the basic setup of vagrant-spec. This file also defines which base box is used.
12
+ Specs will take quite some time and run in GUI mode (due to some weirdness either in vagrant-spec and/or VirtualBox) which will render your machine basically unusable.
13
+
14
+ ```bash
15
+ # List available tasks:
16
+ bundle exec rake -D acceptance
17
+
18
+ # Setup specs (download box artifacts)
19
+ bundle exec rake acceptance:setup:virtualbox
20
+
21
+ # Run tests
22
+ rake acceptance:virtualbox
23
+ ```
data/README.md CHANGED
@@ -87,6 +87,22 @@ $ vagrant dns --stop
87
87
 
88
88
  The DNS server will start automatically once the first VM is started.
89
89
 
90
+ You can list the currently configured dns patterns using:
91
+
92
+ ```bash
93
+ $ vagrant dns --list
94
+ ```
95
+
96
+ (Keep in mind, that it's not guaranteed that the running server uses exactly this configuration - for example, when manually editing it.)
97
+ The output looks somewhat like this:
98
+
99
+ ```
100
+ /^.*mysite.dev$/ => 33.33.33.60
101
+ /^.*myothersite.dev$/ => 33.33.33.60
102
+ ```
103
+
104
+ Where the first part of each line is a [regular expression](https://ruby-doc.org/core-2.3.0/Regexp.html) and the second part is the mapped IPv4. (` => ` is just a separator)
105
+
90
106
  ## VM options
91
107
 
92
108
  * `vm.dns.tld`: Set the tld for the given virtual machine. No default.
@@ -98,10 +114,34 @@ The DNS server will start automatically once the first VM is started.
98
114
  * `VagrantDNS::Config.listen`: an Array of Arrays describing interfaces to bind to. Defaults to `[[:udp, "127.0.0.1", 5300]]`.
99
115
  * `VagrantDNS::Config.auto_run`: (re)start and reconfigure the server every time a machine is started. On by default.
100
116
 
117
+ ## Using custom domains from inside the VM (VirtualBox only)
118
+
119
+ If you need to be able to resolve custom domains managed by this plugin from inside your virtual machine, add the following
120
+ setting to your `Vagrantfile`:
121
+
122
+ ```ruby
123
+ Vagrant.configure(2) do |config|
124
+ # ...
125
+ config.vm.provider "virtualbox" do |vm_config, override|
126
+ vm_config.customize [
127
+ "modifyvm", :id,
128
+ "--natdnshostresolver1", "on",
129
+ # some systems also need this:
130
+ # "--natdnshostresolver2", "on"
131
+ ]
132
+ end
133
+ end
134
+ ```
135
+
136
+ By default, the Virtualbox NAT engine offers the same DNS servers to the guest that are configured on the host. With the above
137
+ setting, however, the NAT engine will act as a DNS proxy
138
+ (see [Virtualbox docs](https://www.virtualbox.org/manual/ch09.html#nat-adv-dns)). That way, queries for your custom domains
139
+ from inside the guest will also be handled by the DNS server run by the plugin.
140
+
101
141
  ## Issues
102
142
 
103
143
  * `A` records only
104
144
  * No IPv6 support
105
145
  * OS X only (please read: [Platform
106
146
  Support](https://github.com/BerlinVagrant/vagrant-dns/blob/master/PLATFORM_SUPPORT.md) before ranting about this).
107
- * Not visible inside the box
147
+ * Not automatically visible inside the box (special configuration of your guest system or provider needed)
@@ -3,8 +3,10 @@ require "vagrant-dns/config"
3
3
 
4
4
  require "vagrant-dns/service"
5
5
  require "vagrant-dns/installers/mac"
6
- require "vagrant-dns/restart_middleware"
7
6
  require "vagrant-dns/configurator"
7
+ require "vagrant-dns/middlewares/config_up"
8
+ require "vagrant-dns/middlewares/config_down"
9
+ require "vagrant-dns/middlewares/restart"
8
10
 
9
11
  module VagrantDNS
10
12
 
@@ -23,10 +25,15 @@ module VagrantDNS
23
25
 
24
26
  %w{up reload}.each do |action|
25
27
  action_hook(:restart_host_dns, "machine_action_#{action}".to_sym) do |hook|
26
- hook.append VagrantDNS::RestartMiddleware
28
+ hook.append VagrantDNS::Middlewares::ConfigUp
29
+ hook.append VagrantDNS::Middlewares::Restart
27
30
  end
28
31
  end
29
32
 
33
+ action_hook(:remove_dns_config, :machine_action_destroy) do |hook|
34
+ hook.append VagrantDNS::Middlewares::ConfigDown
35
+ hook.append VagrantDNS::Middlewares::Restart
36
+ end
30
37
  end
31
38
 
32
39
  end
@@ -11,35 +11,56 @@ module VagrantDNS
11
11
  def execute
12
12
  options = {}
13
13
  opts = OptionParser.new do |opts|
14
- opts.banner = "Usage: vagrant dns [vm-name] [-i|--install] [-u|--uninstall] [--with-sudo] [--pruge] [-s|--start] [-S|--stop] [-r|--restart] [-o|--ontop]"
14
+ opts.banner = "Usage: vagrant dns [vm-name] [-i|--install] [-u|--uninstall] [--with-sudo] [--pruge] [-s|--start] [-S|--stop] [-r|--restart] [--status] [-l|--list] [-o|--ontop]"
15
15
  opts.separator ""
16
16
 
17
17
  opts.on("--install", "-i", "Install DNS config for machine domain") do
18
18
  options[:install] = true
19
+ options[:build_config] = true
20
+ options[:manage_installation] = true
19
21
  end
20
22
 
21
23
  opts.on("--uninstall", "-u", "Uninstall DNS config for machine domain") do
22
24
  options[:uninstall] = true
23
- end
24
-
25
- opts.on("--with-sudo", "In conjunction with `--install`, `--uninstall`, `--purge`: Run using `sudo` instead of `osascript`. Useful for automated scripts running as sudoer.") do
26
- options[:installer_opts] = { exec_style: :sudo }
25
+ options[:build_config] = false
26
+ options[:manage_installation] = true
27
+ options[:stop] = true
27
28
  end
28
29
 
29
30
  opts.on("--purge", "Uninstall DNS config and remove DNS configurations of all machines.") do
30
31
  options[:purge] = true
32
+ options[:build_config] = false
33
+ options[:manage_installation] = true
34
+ options[:stop] = true
31
35
  end
32
36
 
33
37
  opts.on("--start", "-s", "Start the DNS service") do
34
38
  options[:start] = true
39
+ options[:build_config] = true
35
40
  end
36
41
 
37
- opts.on("--stop", "-s", "Stop the DNS service") do
42
+ opts.on("--stop", "-S", "Stop the DNS service") do
38
43
  options[:stop] = true
44
+ options[:build_config] = false
39
45
  end
40
46
 
41
47
  opts.on("--restart", "-r", "Restart the DNS service") do
42
48
  options[:restart] = true
49
+ options[:build_config] = true
50
+ end
51
+
52
+ opts.on("--status", "Show DNS service running status and PID.") do
53
+ options[:status] = true
54
+ options[:build_config] = false
55
+ end
56
+
57
+ opts.on("--list", "-l", "Show the current DNS service config. This works in conjunction with --start --stop --restart --status.") do
58
+ options[:show_config] = true
59
+ options[:build_config] = false
60
+ end
61
+
62
+ opts.on("--with-sudo", "In conjunction with `--install`, `--uninstall`, `--purge`: Run using `sudo` instead of `osascript`. Useful for automated scripts running as sudoer.") do
63
+ options[:installer_opts] = { exec_style: :sudo }
43
64
  end
44
65
 
45
66
  opts.on("--ontop", "-o", "Start the DNS service on top. Debugging only, this blocks Vagrant!") do
@@ -52,15 +73,10 @@ module VagrantDNS
52
73
 
53
74
  vms = argv unless argv.empty?
54
75
 
55
- if options[:uninstall] || options[:purge]
56
- manage_service(vms, options.merge(stop: true))
57
- manage_installation(vms, options)
58
- else
59
- build_config(vms, options)
60
- manage_service(vms, options)
61
- manage_installation(vms, options) if options[:install]
62
- end
63
-
76
+ build_config(vms, options) if options[:build_config]
77
+ manage_service(vms, options)
78
+ manage_installation(vms, options) if options[:manage_installation]
79
+ show_config(vms, options) if options[:show_config]
64
80
  end
65
81
 
66
82
  protected
@@ -91,11 +107,18 @@ module VagrantDNS
91
107
  service.stop!
92
108
  elsif options[:restart]
93
109
  service.restart! :ontop => options[:ontop]
110
+ elsif options[:status]
111
+ service.status!
94
112
  end
95
113
  end
96
114
 
115
+ def show_config(vms, options)
116
+ service = VagrantDNS::Service.new(tmp_path)
117
+ service.show_config
118
+ end
119
+
97
120
  def build_config(vms, options)
98
- with_target_vms(vms) { |vm| VagrantDNS::Configurator.new(vm, tmp_path).run! }
121
+ with_target_vms(vms) { |vm| VagrantDNS::Configurator.new(vm, tmp_path).up! }
99
122
  end
100
123
 
101
124
  def tmp_path
@@ -10,12 +10,16 @@ module VagrantDNS
10
10
  @tmp_path = tmp_path
11
11
  end
12
12
 
13
- def run!
13
+ def up!
14
14
  regenerate_resolvers!
15
15
  ensure_deamon_env!
16
16
  register_patterns!
17
17
  end
18
18
 
19
+ def down!
20
+ unregister_patterns!
21
+ end
22
+
19
23
  private
20
24
  def regenerate_resolvers!
21
25
  FileUtils.mkdir_p(resolver_folder)
@@ -67,6 +71,33 @@ module VagrantDNS
67
71
  File.open(config_file, "w") { |f| f << YAML.dump(registry) }
68
72
  end
69
73
 
74
+ def unregister_patterns!
75
+ opts = dns_options(vm)
76
+
77
+ patterns = opts[:patterns] || default_patterns(opts)
78
+ if patterns.empty?
79
+ vm.ui.warn '[vagrant-dns] TLD but no host_name given. No patterns will be removed.'
80
+ return
81
+ end
82
+
83
+ registry = YAML.load(File.read(config_file)) if File.exists?(config_file)
84
+ unless registry
85
+ vm.ui.warn '[vagrant-dns] Configuration file does not exists. No patterns will be removed.'
86
+ return
87
+ end
88
+
89
+ patterns.each do |p|
90
+ p = p.source if p.respond_to? :source # Regexp#to_s is unusable
91
+ if (ip = registry.delete(p))
92
+ vm.ui.info "[vagrant-dns] Removing pattern: #{p} for ip: #{ip}"
93
+ else
94
+ vm.ui.info "[vagrant-dns] Pattern: #{p} was not in config."
95
+ end
96
+ end
97
+
98
+ File.open(config_file, "w") { |f| f << YAML.dump(registry) }
99
+ end
100
+
70
101
  def dns_options(vm)
71
102
  dns_options = vm.config.dns.to_hash
72
103
  dns_options[:host_name] = vm.config.vm.hostname
@@ -0,0 +1,20 @@
1
+ module VagrantDNS
2
+ module Middlewares
3
+ class ConfigDown
4
+ def initialize(app, env)
5
+ @app = app
6
+ @env = env
7
+ end
8
+
9
+ def call(env)
10
+ @env = env
11
+ vm = env[:machine]
12
+ if VagrantDNS::Config.auto_run
13
+ tmp_path = File.join(vm.env.tmp_path, "dns")
14
+ VagrantDNS::Configurator.new(vm, tmp_path).down!
15
+ end
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantDNS
2
+ module Middlewares
3
+ class ConfigUp
4
+ def initialize(app, env)
5
+ @app = app
6
+ @env = env
7
+ end
8
+
9
+ def call(env)
10
+ @env = env
11
+ vm = env[:machine]
12
+ if VagrantDNS::Config.auto_run
13
+ tmp_path = File.join(vm.env.tmp_path, "dns")
14
+ VagrantDNS::Configurator.new(vm, tmp_path).up!
15
+ end
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantDNS
2
+ module Middlewares
3
+ class Restart
4
+ def initialize(app, env)
5
+ @app = app
6
+ @env = env
7
+ end
8
+
9
+ def call(env)
10
+ @env = env
11
+ vm = env[:machine]
12
+ if VagrantDNS::Config.auto_run
13
+ tmp_path = File.join(vm.env.tmp_path, "dns")
14
+ VagrantDNS::Service.new(tmp_path).restart!
15
+ env[:ui].info "Restarted DNS Service"
16
+ end
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -22,6 +22,11 @@ module VagrantDNS
22
22
  run!(run_options)
23
23
  end
24
24
 
25
+ def status!
26
+ run_options = {:ARGV => ["status"]}.merge(runopts)
27
+ run!(run_options)
28
+ end
29
+
25
30
  def run!(run_options)
26
31
  Daemons.run_proc("vagrant-dns", run_options) do
27
32
  require 'rubydns'
@@ -52,6 +57,17 @@ module VagrantDNS
52
57
  start!(start_opts)
53
58
  end
54
59
 
60
+ def show_config
61
+ registry = YAML.load(File.read(config_file)) if File.exists?(config_file)
62
+ if registry && registry.any?
63
+ registry.each do |pattern, ip|
64
+ puts format("%s => %s", Regexp.new(pattern).inspect, ip)
65
+ end
66
+ else
67
+ puts "Configuration missing or empty."
68
+ end
69
+ end
70
+
55
71
  def runopts
56
72
  daemon_dir = File.join(tmp_path, "daemon")
57
73
  {
@@ -1,5 +1,3 @@
1
- module Vagrant
2
- module Dns
3
- VERSION = "2.0.0"
4
- end
1
+ module VagrantDNS
2
+ VERSION = "2.1.0"
5
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "vagrant-dns"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = Vagrant::Dns::VERSION
16
+ gem.version = VagrantDNS::VERSION
17
17
 
18
18
  gem.required_ruby_version = '>= 2.2.6'
19
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Gilcher
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-19 00:00:00.000000000 Z
12
+ date: 2018-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
@@ -75,7 +75,9 @@ files:
75
75
  - lib/vagrant-dns/config.rb
76
76
  - lib/vagrant-dns/configurator.rb
77
77
  - lib/vagrant-dns/installers/mac.rb
78
- - lib/vagrant-dns/restart_middleware.rb
78
+ - lib/vagrant-dns/middlewares/config_down.rb
79
+ - lib/vagrant-dns/middlewares/config_up.rb
80
+ - lib/vagrant-dns/middlewares/restart.rb
79
81
  - lib/vagrant-dns/service.rb
80
82
  - lib/vagrant-dns/version.rb
81
83
  - tasks/acceptance.rake
@@ -1,21 +0,0 @@
1
- module VagrantDNS
2
- class RestartMiddleware
3
- def initialize(app, env)
4
- @app = app
5
- @env = env
6
- end
7
-
8
- def call(env)
9
- @env = env
10
- vm = env[:machine]
11
- if VagrantDNS::Config.auto_run
12
- tmp_path = File.join(vm.env.tmp_path, "dns")
13
- VagrantDNS::Configurator.new(vm, tmp_path).run!
14
- VagrantDNS::Service.new(tmp_path).restart!
15
- env[:ui].info "Restarted DNS Service"
16
- end
17
-
18
- @app.call(env)
19
- end
20
- end
21
- end