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

Commit

Permalink
Add routes on vm start depending on vagrant-triggers (https://github.…
Browse files Browse the repository at this point in the history
  • Loading branch information
jverdeyen committed Jul 12, 2016
1 parent 76e5688 commit 92131e8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $vm_cpus = 8

$docker_version = "1.11.2"
$vm_ip_address = "172.17.8.101"
$docker_net = "172.17.0.0"

def vm_gui
$vb_gui.nil? ? $vm_gui : $vb_gui
Expand Down Expand Up @@ -57,7 +58,7 @@ Vagrant.configure("2") do |config|
config.vbguest.auto_update = false
end

# Adjusting datetime before provisioning.
# Adjusting datetime before provisioning.
config.vm.provision :shell, run: "always" do |sh|
sh.inline = "sntp -4sSc pool.ntp.org; date"
end
Expand All @@ -70,7 +71,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "/etc/init.d/docker restart #{$docker_version}", privileged: true

config.vm.provision "docker" do |d|
d.pull_images "ailispaw/dnsdock:.12.1.1-alpine"
d.pull_images "ailispaw/dnsdock:1.12.1.1-alpine"
d.run "ailispaw/dnsdock",
args: "-v /var/run/docker.sock:/var/run/docker.sock -p 0.0.0.0:53:53/udp",
restart: "always",
Expand All @@ -84,12 +85,28 @@ Vagrant.configure("2") do |config|
restart: "always",
daemonize: true
end

config.vm.provision :shell do |sh|
sh.inline = <<-EOT
echo "nameserver 127.0.0.1" > /etc/resolv.conf.head
dhcpcd -x eth0 && dhcpcd eth0
EOT
end


if Vagrant.has_plugin?("vagrant-triggers") then
config.trigger.after [:up, :resume] do
info "Setup route to vm ip."
run <<-EOT
sh -c "sudo route -n add -net #{$docker_net} #{$vm_ip_address}"
EOT
end

config.trigger.after [:destroy, :suspend, :halt] do
info "Remove route to vm ip."
run <<-EOT
sh -c "sudo route -n delete -net #{$docker_net} #{$vm_ip_address}"
EOT
end
end

end

0 comments on commit 92131e8

Please sign in to comment.