Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

Commit

Permalink
Issue #71 Making sure correct host IP is used for DNS redirect on guest
Browse files Browse the repository at this point in the history
- Adding integration test
  • Loading branch information
hferentschik committed Sep 4, 2018
1 parent 705f274 commit e10f684
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
32 changes: 32 additions & 0 deletions features/docker_provider.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Feature: Landrush with Docker provider
Landrush should work with Docker provider

Scenario: Booting box with Docker provider
Given a file named "Vagrantfile" with:
"""
Vagrant.configure(2) do |config|
config.vm.provider "docker" do |d|
# https://github.com/tknerr/vagrant-docker-baseimages
d.image = "tknerr/baseimage-ubuntu:18.04"
d.has_ssh = true
d.privileged = true
end
config.vm.provision "shell", inline: 'apt-get install -y net-tools dnsutils'
config.landrush.enabled = true
config.vm.hostname = "foo.vagrant.test"
config.landrush.host 'static1.example.com', '1.2.3.4'
config.landrush.host 'static2.example.com', '2.3.4.5'
end
"""
When I successfully run `bundle exec vagrant up`
Then Landrush is running

When I successfully run `bundle exec vagrant ssh -- dig +noall +answer +nocomments static1.example.com`
Then stdout from "bundle exec vagrant ssh -- dig +noall +answer +nocomments static1.example.com" should match /.*1\.2\.3\.4/

When I successfully run `bundle exec vagrant landrush stop`
Then Landrush is not running

1 change: 1 addition & 0 deletions lib/landrush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
require 'landrush/store'
require 'landrush/version'
require 'landrush-ip'
require 'socket'
3 changes: 3 additions & 0 deletions lib/landrush/action/redirect_dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def _target_host
_gateway_for_ip(machine.guest.capability(:configured_dns_servers).first)
when :parallels then
machine.provider.capability(:host_address)
else
# As a fallthrough default use the first non loopback IP. This IP should be reachable from the guest as well
Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/landrush/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class Plugin < Vagrant.plugin('2')
# Hooks for VirtualBox and HyperV providers
hook.before(VagrantPlugins::ProviderVirtualBox::Action::Network, pre_boot_actions)
hook.before(VagrantPlugins::HyperV::Action::WaitForIPAddress, pre_boot_actions)
hook.after(VagrantPlugins::DockerProvider::Action::Start, pre_boot_actions)
hook.after(Vagrant::Action::Builtin::WaitForCommunicator, post_boot_actions)

# Hooks for Docker provider
hook.after(VagrantPlugins::DockerProvider::Action::Start, pre_boot_actions)

# Hooks for Libvirt provider
if defined?(VagrantPlugins::ProviderLibvirt)
hook.after(VagrantPlugins::ProviderLibvirt::Action::CreateNetworks, pre_boot_actions)
Expand Down

0 comments on commit e10f684

Please sign in to comment.