-
Notifications
You must be signed in to change notification settings - Fork 4
/
Vagrantfile
167 lines (135 loc) · 6.04 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Vagrant.require_version ">= 1.6.0"
#------------------------------------------------------------------------------
# Variables:
#------------------------------------------------------------------------------
$cluster_id = ENV['KATO_CLUSTER_ID'] || 'vagrant-kato'
$node_cpus = ENV['KATO_NODE_CPUS'] || 2
$node_memory = ENV['KATO_NODE_MEMORY'] || 4096
$kato_version = ENV['KATO_VERSION'] || 'v0.1.1'
$coreos_channel = ENV['KATO_COREOS_CHANNEL'] || 'alpha'
$coreos_version = ENV['KATO_COREOS_VERSION'] || 'current'
$monitoring = ENV['KATO_MONITORING'] || false
$domain = ENV['KATO_DOMAIN'] || 'cell-1.dc-1.kato'
$ip_address = ENV['KATO_IP_ADDRESS'] || '172.17.8.11'
$tmp_path = ENV['KATO_TMP_PATH'] || "/tmp/kato"
$code_path = ENV['KATO_CODE_PATH'] || "~/git/"
$ca_cert_path = ENV['KATO_CA_CERT_PATH']
$certs_path = ENV['KATO_CERTS_PATH']
#------------------------------------------------------------------------------
# URLs:
#------------------------------------------------------------------------------
$katoctl_url = "https://github.com/katosys/kato/releases/download/%s/katoctl-%s-%s"
$box_url = "https://storage.googleapis.com/%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json"
#------------------------------------------------------------------------------
# Install plugins:
#------------------------------------------------------------------------------
required_plugins = %w(vagrant-ignition)
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end
#------------------------------------------------------------------------------
# Forge the katoctl command:
#------------------------------------------------------------------------------
if ARGV[0].eql?('up')
Dir.mkdir $tmp_path unless File.exists?($tmp_path)
if !File.file?($tmp_path + "/katoctl")
print "Downloading katoctl...\n"
cmd = "wget -q " + $katoctl_url + " -O " + $tmp_path + "/katoctl"
system cmd % [ $kato_version, `uname`.tr("\n",'').downcase, `uname -m`.tr("\n",'') ]
if !system "chmod +x " + $tmp_path + "/katoctl"
print "Ops! Where is katoctl?\n"
exit
end
end
$katoctl = $tmp_path + "/katoctl udata " +
"--roles quorum,master,worker " +
"--rexray-storage-driver virtualbox " +
"--rexray-endpoint-ip 172.17.8.1 " +
"--iaas-provider vagrant-virtualbox " +
"--cluster-state new " +
"--quorum-count 1 " +
"--master-count 1 " +
"--host-name %s " +
"--cluster-id %s " +
"--domain %s " +
"--host-id %s "
if $monitoring
$katoctl = $katoctl + "--prometheus "
end
end
#------------------------------------------------------------------------------
# Configure:
#------------------------------------------------------------------------------
Vagrant.configure("2") do |config|
config.ssh.forward_agent = true
config.ssh.insert_key = false
config.vm.box = "coreos-%s" % $coreos_channel
config.vm.box_url = $box_url % [$coreos_channel, $coreos_version]
config.ignition.enabled = true
if ARGV[0].eql?('up')
config.vm.provider :virtualbox do |vb|
vb.customize ["setproperty", "websrvauthlibrary", "null"]
vb.check_guest_additions = false
vb.functional_vboxsf = false
if `pgrep vboxwebsrv` == ''
`vboxwebsrv -H 0.0.0.0 -b`
end
end
end
#------------------------------------------------------------------------------
# Start the all-in-one instance:
#------------------------------------------------------------------------------
config.vm.define "kato-1" do |conf|
conf.vm.hostname = "kato-1.%s" % $domain
config.ignition.hostname = "kato-1.%s" % $domain
config.ignition.drive_root = $tmp_path
config.ignition.drive_name = "ignition"
conf.vm.provider :virtualbox do |vb|
vb.gui = false
vb.name = "kato-1.%s" % $domain
vb.memory = $node_memory
vb.cpus = $node_cpus
vb.customize ["modifyvm", :id, "--macaddress1", "auto" ]
config.ignition.config_obj = vb
if `VBoxManage showvminfo #{vb.name} 2>/dev/null | grep SATA` == ''
vb.customize ["storagectl", :id, "--name", "SATA", "--add", "sata"]
end
end
conf.vm.network :private_network, ip: $ip_address
config.ignition.ip = $ip_address
# Purge /etc/hosts records:
if ARGV[0].eql?('destroy') || ARGV[0].eql?('halt') || ARGV[0].eql?('up')
system "sudo sed -i.bak '/%s quorum-1.%s/d' /etc/hosts" % [ $ip_address, $domain ]
system "sudo sed -i.bak '/%s master-1.%s/d' /etc/hosts" % [ $ip_address, $domain ]
system "sudo sed -i.bak '/%s worker-1.%s/d' /etc/hosts" % [ $ip_address, $domain ]
end
if ARGV[0].eql?('up')
# Add /etc/hosts records:
system 'sudo bash -c "echo %s quorum-1.%s quorum-1 >> /etc/hosts"' % [ $ip_address, $domain ]
system 'sudo bash -c "echo %s master-1.%s master-1 >> /etc/hosts"' % [ $ip_address, $domain ]
system 'sudo bash -c "echo %s worker-1.%s worker-1 >> /etc/hosts"' % [ $ip_address, $domain ]
conf.vm.synced_folder $code_path, "/code", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
if $ca_cert_path
cmd = $katoctl + " --ca-cert-path %s > " + $tmp_path + "/user_data_kato-1"
system cmd % [ 'kato', $cluster_id, $domain, 1, $ca_cert_path ]
else
cmd = $katoctl + " > " + $tmp_path + "/user_data_kato-1"
system cmd % [ 'kato', $cluster_id, $domain, 1 ]
end
if $certs_path
conf.vm.provision :file, :source => $certs_path, :destination => "/tmp/certs.tar.bz2"
conf.vm.provision :shell, :inline => "mkdir /etc/certs; mv /tmp/certs.tar.bz2 /etc/certs", :privileged => true
end
if File.exist?($tmp_path + "/user_data_kato-1")
config.ignition.path = $tmp_path + "/user_data_kato-1"
end
end
end
end
# vi: set ft=ruby :