-
Notifications
You must be signed in to change notification settings - Fork 74
/
Vagrantfile
309 lines (264 loc) · 11.3 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Allowing stuff to be set during "vagrant up"
# E.g.
# To use NFS, have 12CPU and 24Gb RAM
# NFSSHARE=true VBCPU=12 VBRAM=24576 vagrant up
$nfsShare = ENV['NFSSHARE']
if $nfsShare.nil?
$nfsShare = false
else
# for windows use WINNFS=true NFSSHARE=true vagrant up
# also, make sure to install the winnfsd plugin: vagrant plugin install vagrant-winnfsd
$winNfs = ENV['WINNFS']
if $winNfs.nil?
$winNfs = false
puts '## Using NFS for file syncing'
else
puts '## Using Windows NFS options for file syncing'
end
end
$rsyncShare = ENV['RSYNCSHARE']
if $rsyncShare.nil?
$rsyncShare = false
else
puts '## Using RSYNC for file syncing'
end
$fouoShare = ENV['FOUOSHARE']
if $fouoShare.nil?
$fouoShare = false
else
puts '## Mounting /fouo on the VM'
end
$vbCpu = ENV['VBCPU']
if $vbCpu.nil?
$vbCpu = 4
else
puts "## Allocating #{$vbCpu} CPU cores to the VM"
end
$vbRam = ENV['VBRAM']
if $vbRam.nil?
$vbRam = 10240
else
puts "## Allocating #{$vbRam} RAM to the VM"
end
# This is only for RPM installs!
# For commandline only Hootenanny, set COREONLY to "yes". The default is a full install - core, services, UI etc
# E.g. COREONLY="yes" vagrant up hoot_centos7_rpm
$coreOnly = ENV['COREONLY']
if $coreOnly.nil?
$coreOnly = "no"
else
puts "## Installing commandline Hootenanny"
end
# Decide if we install the release version or the nightly development version
$nightly = ENV['NIGHTLY']
if $nightly.nil?
$nightly = "yes"
else
puts "## Installing from the nightly RPMs"
end
# By default, don't try to add software repos in the VM's
# Not sure if this needs to be able to be triggered from the commandline
$addRepos = "no"
# Hootenanny port mapping
# If this is set, the VM will not forward any ports to the host
$disableForwarding = ENV['DISABLE_VAGRANT_FORWARDING']
$tomcatPort = ENV['TOMCAT_PORT']
if $tomcatPort.nil?
$tomcatPort = 8888
end
$tomcatSslPort = ENV['TOMCAT_SSL_PORT']
if $tomcatSslPort.nil?
$tomcatSslPort = 8443
end
$transPort = ENV['NODEJS_PORT']
if $transPort.nil?
$transPort = 8094
end
$mergePort = ENV['P2P_PORT']
if $mergePort.nil?
$mergePort = 8096
end
$nodeExportPort = ENV['NODE_EXPORT_PORT']
if $nodeExportPort.nil?
$nodeExportPort = 8101
end
$yumUpdate = ENV['YUMUPDATE']
if $yumUpdate.nil?
$yumUpdate = "no"
end
$isAWS = false
Vagrant.configure(2) do |config|
def aws_provider(config, os, vbox)
# AWS Provider. Set environment variables for values below to use
config.vm.provider :aws do |aws, override|
$isAWS = true;
override.nfs.functional = false
if vbox == "hoot"
aws.region_config ENV['AWS_DEFAULT_REGION'], :ami => ENV['AWS_HOOT_AMI_ID']
elsif vbox == "minimal"
aws.region_config ENV['AWS_DEFAULT_REGION'], :ami => ENV['AWS_MINIMAL_AMI_ID']
end
aws.subnet_id = ENV['AWS_SUBNET_ID']
if ENV.key?('AWS_KEYPAIR_NAME')
aws.keypair_name = ENV['AWS_KEYPAIR_NAME']
end
if ENV.key?('AWS_SECURITY_GROUP')
$security_grp = ENV['AWS_SECURITY_GROUP']
if $security_grp.is_a?(String) and $security_grp.include? ',' and $security_grp.split(',').length > 0
aws.security_groups = $security_grp.split(',')
else
aws.security_groups = $security_grp
end
end
aws.instance_type = ENV.fetch('AWS_INSTANCE_TYPE', 'm5.2xlarge')
aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 64 }]
aws.tags = {
'Name' => ENV.fetch('AWS_INSTANCE_NAME_TAG', "jenkins-hootenanny-#{os.downcase}"),
'URL' => ENV.fetch('AWS_INSTANCE_URL_TAG', 'https://github.com/ngageoint/hootenanny'),
'env' => ENV.fetch('HOOT_AWS_ENV_TAG', 'testing'),
'use' => ENV.fetch('HOOT_AWS_USE_TAG', 'Jenkins'),
'group' => ENV.fetch('HOOT_AWS_GROUP_TAG', 'devops')
}
if ENV.key?('JOB_NAME')
aws.tags['JobName'] = ENV['JOB_NAME']
end
if ENV.key?('BUILD_NUMBER')
aws.tags['BuildNumber'] = ENV['BUILD_NUMBER']
end
# Copy over predownloaded packages if they are found
override.vm.provision 'software', type: 'shell', run: 'always', :inline => '( [ -d /home/vagrant/hoot/software ] && cp /home/vagrant/hoot/software/* /home/vagrant ) || true'
# Setting up provisioners for AWS, in the correct order, depending on the OS platform.
if os == 'CentOS7'
override.vm.provision "hoot", type: "shell", :privileged => false, :path => "VagrantProvisionCentOS7.sh", :env => {"ADDREPOS" => $addRepos, "YUMUPDATE" => $yumUpdate}
# override.vm.provision 'hoot', type: 'shell', :privileged => false, :path => 'VagrantProvisionCentOS7.sh'
tomcat_script = 'sudo systemctl restart tomcat8'
end
override.vm.provision 'build', type: 'shell', :privileged => false, :path => 'VagrantBuild.sh'
override.vm.provision 'EGD', type: 'shell', :privileged => false, :inline => '([ -f ~/ActivateEGDplugin.sh ] && sudo -u tomcat ~/ActivateEGDplugin.sh /var/lib/tomcat8) || true'
override.vm.provision 'tomcat', type: 'shell', :privileged => false, :inline => tomcat_script, run: 'always'
# TODO: Why is node-export only on CentOS?
if os.start_with?('CentOS')
override.vm.provision 'export', type: 'shell', :privileged => false, :inline => 'sudo systemctl restart node-export'
end
end
end
def mount_shares(config)
# sharing of the hosts hoot folder and optionally the fouo folder with or without nfs
if $nfsShare
config.vm.network "private_network", ip: "192.168.33.10"
if $winNfs
config.vm.synced_folder ".", "/home/vagrant/hoot", type: "nfs", mount_options: %w{rw,async,fsc,nolock,vers=3,udp,rsize=32768,wsize=32768,hard,noatime,actimeo=2}
else
config.vm.synced_folder ".", "/home/vagrant/hoot", type: "nfs", mount_options: ['vers=4'], nfs_version: 4
end
if $fouoShare
if $winNfs
config.vm.synced_folder "/fouo", "/fouo", type: "nfs", mount_options: %w{rw,async,fsc,nolock,vers=3,udp,rsize=32768,wsize=32768,hard,noatime,actimeo=2}
else
config.vm.synced_folder "/fouo", "/fouo", type: "nfs"
end
end
elsif $rsyncShare
config.vm.synced_folder ".", "/home/vagrant/hoot", type: "rsync", rsync__exclude: ['.vagrant/', '.git/']
if $fouoShare
config.vm.synced_folder "/fouo", "/fouo", type: "rsync"
end
else
# Use sshfs sharing if available, otherwise default sharing
if Vagrant.has_plugin?("vagrant-sshfs")
config.vm.synced_folder ".", "/home/vagrant/hoot", type: "sshfs", sshfs_opts_append: "-o nonempty"
if $fouoShare
config.vm.synced_folder "/fouo", "/fouo", type: "sshfs", sshfs_opts_append: "-o nonempty"
end
else
if !$isAWS
puts '## Warning: you are not using sshfs. Please run \'vagrant plugin install vagrant-sshfs\' to enable sshfs.'
end
config.vm.synced_folder ".", "/home/vagrant/hoot"
if $fouoShare
config.vm.synced_folder "/fouo", "/fouo"
end
end
end
end
def set_provisioners(config)
config.vm.provision "hoot", type: "shell", :privileged => false, :path => "VagrantProvisionCentOS7.sh", :env => {"ADDREPOS" => $addRepos, "YUMUPDATE" => $yumUpdate}
config.vm.provision "build", type: "shell", :privileged => false, :path => "VagrantBuild.sh"
config.vm.provision "tomcat", type: "shell", :privileged => false, :inline => "sudo systemctl restart tomcat8", run: "always"
config.vm.provision "export", type: "shell", :privileged => false, :inline => "sudo systemctl restart node-export", run: "always"
config.vm.provision "valgrind", type: "shell", :privileged => false, :path => "scripts/valgrind/valgrind_install.sh"
end
def set_forwarding(config)
if $disableForwarding.nil?
config.vm.network "forwarded_port", guest: 8080, host: $tomcatPort # Tomcat service
config.vm.network "forwarded_port", guest: 8443, host: $tomcatSslPort # Tomcat SSL service
config.vm.network "forwarded_port", guest: 8094, host: $transPort # NodeJS Translation service
config.vm.network "forwarded_port", guest: 8096, host: $mergePort # NodeJS Merge service
config.vm.network "forwarded_port", guest: 8101, host: $nodeExportPort # NodeJS export service
end
end
# Centos7 Hootenanny box from RPM's
config.vm.define "hoot_centos7_rpm", autostart: false do |hoot_centos7_rpm|
hoot_centos7_rpm.vm.box = "hoot/centos7-minimal"
hoot_centos7_rpm.vm.hostname = "hoot-centos7-rpm"
set_forwarding(hoot_centos7_rpm)
mount_shares(hoot_centos7_rpm)
# NOTE: For commandline only Hootenanny, set COREONLY to "yes"
hoot_centos7_rpm.vm.provision "hootrpm", type: "shell", :privileged => false, :path => "VagrantProvisionCentOS7Rpm.sh", :env => {"HOOT_HOME" => "/home/vagrant/hoot", "YUMUPDATE" => $yumUpdate, "COREONLY" => $coreOnly, "NIGHTLY" => $nightly}
hoot_centos7_rpm.vm.provision "updatehoot", type: "shell", :privileged => false, :path => "scripts/yum/update-hoot.sh", run: "never", :env => {"HOOT_HOME" => "/home/vagrant/hoot"}
end
# Centos7 box - Preprovisioned for compiling hootenanny
config.vm.define "default", primary: true do |hoot_centos7_prov|
hoot_centos7_prov.vm.box = "hoot/centos7-hoot"
hoot_centos7_prov.vm.hostname = "centos7-hoot"
set_forwarding(hoot_centos7_prov)
mount_shares(hoot_centos7_prov)
set_provisioners(hoot_centos7_prov)
aws_provider(hoot_centos7_prov, 'CentOS7', 'hoot')
end
# Centos7 box - not preprovisioned
config.vm.define "hoot_centos7", autostart: false do |hoot_centos7|
hoot_centos7.vm.box = "hoot/centos7-minimal"
hoot_centos7.vm.hostname = "hoot-centos"
set_forwarding(hoot_centos7)
mount_shares(hoot_centos7)
# We do want to add repos and update this box
# NOTE: This change applies to every target AFTER this one as well.
$addRepos = "yes"
$yumUpdate = "yes"
set_provisioners(hoot_centos7)
aws_provider(hoot_centos7, 'CentOS7', 'minimal')
end
config.vm.define "dockercentos7.2", autostart: false do |dockcentos72|
dockcentos72.ssh.insert_key = false
dockcentos72.vm.provider "docker" do |d|
d.image = "local/centos7.2vagrant"
d.create_args = ['-td','--privileged','--shm-size','1g']
d.has_ssh = true
end
dockcentos72.vm.synced_folder ".", "/home/vagrant/hoot"
# Stop the default vagrant rsyncing
config.vm.synced_folder '.', '/home/vagrant/sync', disabled: true
dockcentos72.vm.provision "hoot", type: "shell", :privileged => false, :path => "VagrantProvisionCentOS7.sh"
dockcentos72.vm.provision "build", type: "shell", :privileged => false, :path => "VagrantBuild.sh"
dockcentos72.vm.provision "tomcat", type: "shell", :privileged => false, :inline => "sudo systemctl restart tomcat8", run: "always"
dockcentos72.vm.provision "export", type: "shell", :privileged => false, :inline => "sudo systemctl restart node-export", run: "always"
end
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
config.vm.provider "virtualbox" do |vb|
# Customize the amount of memory on the VM:
vb.memory = $vbRam
vb.cpus = $vbCpu
end
end
# Allow local overrides of vagrant settings
if File.exists?('VagrantfileLocal')
load 'VagrantfileLocal'
else
if File.exists?('VagrantfileLocal.vbox')
load 'VagrantfileLocal.vbox'
end
end