This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vagrantfile
119 lines (98 loc) · 4.41 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require 'yaml'
Vagrant.require_version ">= 2.1.0"
# Load settings from vagrant.yml or vagrant.yml.dist
current_dir = File.dirname(File.expand_path(__FILE__))
if File.file?("#{current_dir}/vagrant.yaml")
config_file = YAML.load_file("#{current_dir}/vagrant.yaml")
else
config_file = YAML.load_file("#{current_dir}/vagrant.yaml.dist")
end
settings = config_file['settings']
$vm_gui = settings['vm']['gui']
$vm_memory = settings['vm']['memory']
$vm_cpus = settings['vm']['cpus']
$vm_disk = settings['vm']['disk']
$vm_ip_address = settings['vm']['ip']
$docker_version = settings['docker']['version']
$docker_net = settings['docker']['network']
def vm_gui
$vb_gui.nil? ? $vm_gui : $vb_gui
end
def vm_memory
$vb_memory.nil? ? $vm_memory : $vb_memory
end
def vm_cpus
$vb_cpus.nil? ? $vm_cpus : $vb_cpus
end
# A dummy plugin for Barge to set hostname and network correctly at the very first `vagrant up`
module VagrantPlugins
module GuestLinux
class Plugin < Vagrant.plugin("2")
guest_capability("linux", "change_host_name") { Cap::ChangeHostName }
guest_capability("linux", "configure_networks") { Cap::ConfigureNetworks }
end
end
end
Vagrant.configure("2") do |config|
config.vm.box = "ailispaw/barge"
config.disksize.size = $vm_disk
config.vm.network :private_network, ip: "#{$vm_ip_address}"
config.vm.synced_folder ENV['HOME'], ENV['HOME'], id: "home", :nfs => true, :mount_options => ['noatime,soft,nolock,vers=3,udp,proto=udp,udp,rsize=8192,wsize=8192,namlen=255,timeo=10,retrans=3,nfsvers=3,actimeo=1']
config.vm.guest = :linux
config.vm.provider :virtualbox do |vb|
vb.check_guest_additions = false
vb.functional_vboxsf = false
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
vb.gui = vm_gui
vb.memory = vm_memory
vb.cpus = vm_cpus
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.network "forwarded_port", guest: 2375, host: 2375, auto_correct: true
config.vm.network "forwarded_port", guest: 9000, host: 9000, auto_correct: true
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
# Adjusting datetime before provisioning.
config.vm.provision :shell, run: "always" do |sh|
sh.inline = "sntp -4sSc pool.ntp.org; date"
end
config.vm.provision "file", source: "./docker", destination: '/tmp/docker'
config.vm.provision "shell", inline: "mv /tmp/docker /etc/default/docker", privileged: true
config.vm.provision "shell", inline: "mkdir -p /home/bargee/cronjobs", privileged: false
config.vm.provision "file", source: "./cronjobs/date.sh", destination: '/home/bargee/cronjobs/date.sh'
config.vm.provision "file", source: "./cronjobs/dnsdock.sh", destination: '/home/bargee/cronjobs/dnsdock.sh'
config.vm.provision "file", source: "./crontab", destination: '/home/bargee/crontab'
config.vm.provision "shell", inline: "cd /home/bargee/cronjobs; chmod 755 *.sh", privileged: true
config.vm.provision "shell", inline: "cd /home/bargee; cat crontab | crontab -; crontab -l", privileged: true
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:1.16.4"
d.post_install_provision "shell", inline:"docker rm -f dnsdock || true"
d.run "dnsdock",
image: "ailispaw/dnsdock:1.16.4",
args: "-v /var/run/docker.sock:/var/run/docker.sock -p 0.0.0.0:53:53/udp",
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
config.trigger.after [:up, :resume] do |trigger|
trigger.info = "Setup route to vm ip #{$docker_net} -> #{$vm_ip_address}!"
trigger.run = {inline: "sudo route -n add -net #{$docker_net} #{$vm_ip_address}"}
trigger.info = "Update vm.max_map_count!"
trigger.run_remote = {inline: "sudo sysctl -w vm.max_map_count=262144"}
end
config.trigger.after [:destroy, :suspend, :halt] do |trigger|
trigger.info = "Remove route to vm ip!"
trigger.run = {inline: "sudo route -n delete -net #{$docker_net} #{$vm_ip_address}"}
end
end