-
Notifications
You must be signed in to change notification settings - Fork 12
/
Vagrantfile
229 lines (205 loc) · 8.17 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# To force a specific provider set the VAGRANT_DEFAULT_PROVIDER environment variable.
# Vagrant defaults to virtual box if you have it installed
# eg: VAGRANT_DEFAULT_PROVIDER=libvirt
# eg: VAGRANT_DEFAULT_PROVIDER=virtualbox
# eg: VAGRANT_DEFAULT_PROVIDER=vmware_deskop
# The OS to spin up
# Default: ubuntu/bionic64
# Examples:
# BOX=ubuntu/trusty64
# BOX=ubuntu/xenial64
# BOX=ubuntu/bionic64
# BOX=ubuntu/focal64
# BOX=centos/6
# BOX=centos/7
# BOX=rockylinux/8
#
# # VMWare
# # Below box tested with vmware_fusion provider, vmware tools installed properly
# BOX=bento/centos-7.6
#
# # Libvirt
# # The ubuntu/ boxes aren't built for libvirt, so you'll need to use the generic/ or
# # bento/ boxes.
# # The normal centos/6, centos/7, rockylinux/8 all work fine on libvirt.
# BOX=generic/ubuntu1604
# BOX=generic/ubuntu1804
# BOX=centos/6
# BOX=centos/7
# BOX=rockylinux/8
vm_box = ENV['BOX'] ? ENV['BOX'] : 'ubuntu/bionic64'
# The hostname of the Vagrant VM
# Default: st2vagrant
# Examples:
# VAGRANT_HOSTNAME=st2vagrant-rhel7
# VAGRANT_HOSTNAME=rhel7-testing
#
# Note, we specifically do NOT name this "HOSTNAME" because that is a
# common environment variable and will set the vagrant VM's hostname to the
# same as the hypervisor host running the vagrant VM.
vm_hostname = ENV['VAGRANT_HOSTNAME'] ? ENV['VAGRANT_HOSTNAME'] : 'st2vagrant'
# The IP address to assign to the VM
# Default: 192.168.56.20
# Examples:
# VM_IP=192.168.1.4
vm_ip = ENV['VM_IP'] ? ENV['VM_IP'] : '192.168.56.20'
# The ST2 user
# Default: st2admin
# Example:
# ST2USER=st2user
st2user = ENV['ST2USER'] ? '-u "' + ENV['ST2USER'] + '"': '-u "st2admin"'
# The ST2 user password
# Default: Ch@ngeMe
# Example: ST2PASSWORD=secret-tunnel/secret-tunnel/through-the-mountain/secret-secret-tunnel
st2passwd = ENV['ST2PASSWORD'] ? '-p "' + ENV['ST2PASSWORD'] + '"' : '-p "Ch@ngeMe"'
# Which release channel (stable or unstable to use)
# Default: unstable
# RELEASE=stable
# RELEASE=unstable
release = ENV['RELEASE'] ? '-r "' + ENV['RELEASE'] + '"' : '-r unstable'
# Which release channel (staging or production to use)
# Default: (empty string, eg: production)
# REPO_TYPE=staging
repo_type = ENV['REPO_TYPE'] ? '-t ' + ENV['REPO_TYPE'] : ''
# Which version of the package to install - must be specified in x.y.z format
# or X.Ydev
# Default: (empty string, meaning latest)
# VERSION=3.1dev
# VERSION=3.2.0
version = ENV['VERSION'] ? '-v "' + ENV['VERSION'] + '"' : ''
# Build source - used to install packages from a specific CircleCI build
# Default: Packagecloud
# Examples:
# DEV=st2/5017
# DEV=mistral/1012
# DEV=st2-packages/3021
dev = ENV['DEV'] ? '-d ' + ENV['DEV'] : ''
# The branch of st2-packages or bwc-installer to pull and use
# Default: master
# Examples:
# BRANCH=master
# BRANCH=yum-exclude-nginx
branch = ENV['BRANCH'] ? '-b "' + ENV['BRANCH'] + '"' : ''
# A comma-separated list of synced folder options, specified as key/value pairs
# Option values are interpreted as Ruby code
# Default: (empty)
# Examples:
# SYNCED_FOLDER_OPTIONS=vmware # -> {} (no options)
# SYNCED_FOLDER_OPTIONS='' # -> {nfs:true,mount_options:["nfsvers=3"]} (Virtualbox)
default_sf_options = {}
all_sf_options = ENV['SYNCED_FOLDER_OPTIONS'] == 'vmware' ? [] : ['nfs:true', 'mount_options:["nfsvers=3"]']
all_sf_options.each do |opt|
opt_name, opt_value = opt.split(':')
opt_value = eval(opt_value)
default_sf_options[opt_name.to_sym] = opt_value
end
# A comma-separated list of common folders to sync
# Available common folders:
# . /vagrant
# config /opt/stackstorm/config
# packs_dev /opt/stackstorm/packs_dev
# packs /opt/stackstorm/packs
# datastore_load /opt/stackstorm/datastore_load
#
# Default: ''
# Examples:
# SYNCED_FOLDERS='.'
# SYNCED_FOLDERS='.,config'
# SYNCED_FOLDERS='.,config,packs_dev,packs,datastore_load'
vm_synced_folders = []
all_synced_folders = ENV['SYNCED_FOLDERS'] ? ENV['SYNCED_FOLDERS'].split(',') : []
all_synced_folders_map = {
'.'=> ['/vagrant', disabled: true],
'config'=> ['/opt/stackstorm/config', {}],
'packs_dev'=> ['/opt/stackstorm/packs_dev', {}],
'packs'=> ['/opt/stackstorm/packs', {}],
'datastore_load'=> ['/opt/stackstorm/datastore_load', {}],
}
all_synced_folders.each do |sf|
vm_synced_folder = all_synced_folders_map.fetch(sf, nil)
next if not vm_synced_folder
vm_synced_folders.push [sf, vm_synced_folder[0], default_sf_options.merge(vm_synced_folder[1])]
end
# A comma-separated list of folder pairs/triples to sync
# Each folder pair is specified as host_folder:guest_folder
# Each folder triple is specified as host_folder:guest_folder:shared_folder_options
# Relative host folders are specified relative to this Vagrantfile
# Shared folder options are evaluated as Ruby code
# Default: ''
# Examples:
# CUSTOM_SYNCED_FOLDERS='../st2client.js,../hubot-stackstorm,../st2chatops'
# CUSTOM_SYNCED_FOLDERS='../st2client.js:/home/vagrant/st2client.js,'\
# '../hubot-stackstorm:/home/vagrant/hubot-stackstorm,'\
# '../st2chatops:/home/vagrant/st2chatops,'\
# '../exchange:/home/vagrant/exchange,'\
# '../st2tests:/home/vagrant/st2tests'\
# '../st2tests:/home/vagrant/st2web'
# CUSTOM_SYNCED_FOLDERS='../st2client.js:/home/vagrant/st2client.js:'\
# '../hubot-stackstorm:/home/vagrant/hubot-stackstorm,'
all_custom_synced_folders = ENV['CUSTOM_SYNCED_FOLDERS'] ? ENV['CUSTOM_SYNCED_FOLDERS'].scan(/([^:,]+)(?::([^:,]+))?(?::(?:((?:\{[^:}]+?\})|(?:\[[^:\]]+?\]))))?/) : []
all_custom_synced_folders.each do |sfpair|
host_folder, guest_folder, sf_options = sfpair
guest_folder = guest_folder ? guest_folder : "/home/vagrant/#{File.basename(host_folder)}"
sf_options = sf_options ? eval(sf_options) : {}
vm_synced_folders.push [host_folder, guest_folder, default_sf_options.merge(sf_options)]
end
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
# Minimum Vagrant Version
Vagrant.require_version ">= 2.2.0"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "#{vm_hostname}" do |st2|
# Global Box details
st2.vm.box = "#{vm_box}"
st2.vm.hostname = "#{vm_hostname}"
# Box Specifications
# VirtualBox
st2.vm.provider :virtualbox do |vb|
vb.gui = false # Change to true to launch console
vb.name = "#{vm_hostname}"
vb.memory = 4096
vb.cpus = 2
end
# VMWare Desktop (fusion/workstation)
["vmware_fusion", "vmware_workstation"].each do |provider|
st2.vm.provider provider do |vmw, override|
vmw.gui = false # Change to true to launch console
vmw.vmx["ethernet0.virtualDev"] = "vmxnet3"
vmw.vmx["memsize"] = 4096
vmw.vmx["numvcpus"] = 2
# Do not overwrite pci-slot number (https://www.vagrantup.com/docs/vmware/boxes.html#making-compatible-boxes)
config.vm.provider provider do |vmware|
vmware.whitelist_verified = true
end
end
end
# KVM / libvirt
st2.vm.provider :libvirt do |lv, override|
lv.host = vm_hostname
lv.memory = 4096
lv.cpus = 2
lv.uri = "qemu:///system"
lv.storage_pool_name = "images"
# use a different network than the virtualbox provider so we can run virtualbox
# and libvirt on the same machine
override.vm.network :private_network, ip: "192.168.26.20"
end
vm_synced_folders.each do |host_folder, guest_folder, sf_options|
st2.vm.synced_folder(host_folder, guest_folder, **sf_options)
end
# Configure a private network
st2.vm.network :private_network, ip: "#{vm_ip}"
# Public (bridged) network may come handy for external access to VM (e.g. sensor development)
# See https://www.vagrantup.com/docs/networking/public_network.html
# st2.vm.network "public_network", bridge: 'en0: Wi-Fi (AirPort)'
# Start shell provisioning.
st2.vm.provision "shell" do |s|
s.path = "scripts/install_st2.sh"
s.args = "#{st2user} #{st2passwd} #{release} #{repo_type} #{dev} #{branch} #{version}"
s.privileged = false
end
end
end