forked from magfest/reggie-formula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
265 lines (220 loc) · 9.84 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
# -*- mode: ruby -*-
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
VAGRANTFILE_API_VERSION = '2'
Vagrant.require_version '>= 2'
$set_environment_variables = <<SCRIPT
tee "/etc/profile.d/myvars.sh" > "/dev/null" <<EOF
# reggie vars
export EVENT_NAME=#{ENV['EVENT_NAME']}
export EVENT_YEAR=#{ENV['EVENT_YEAR']}
# VAGRANT environment variables.
export IS_VAGRANT_WINDOWS=#{ENV['IS_VAGRANT_WINDOWS']}
EOF
SCRIPT
if Vagrant::Util::Platform.windows?
ENV['SYNC_FOLDER'] = '/home/vagrant/init' #edit to reggie-formula after first boot
else
ENV['SYNC_FOLDER'] = ENV['SYNC_FOLDER'] || '/home/vagrant/reggie-formula'
end
ENV['EVENT_NAME'] = ENV['EVENT_NAME'] || 'super'
ENV['EVENT_YEAR'] = ENV['EVENT_YEAR'] || '2022'
if Vagrant::Util::Platform.windows?
ENV['IS_VAGRANT_WINDOWS'] = 'true'
else
ENV['IS_VAGRANT_WINDOWS'] = 'false'
end
Vagrant.configure("2") do |config|
# config.vm.box = "hashicorp/bionic64"
# config.vm.box_version = "1.0.282"
#orginal box below compaible box above
config.vm.box = 'bento/ubuntu-18.04'
config.vm.hostname = 'localhost'
config.vm.network :forwarded_port, guest: 8000, host: 8000 # haproxy http proxy
config.vm.network :forwarded_port, guest: 4443, host: 4443 # haproxy https proxy
config.vm.network :forwarded_port, guest: 8282, host: 8282 # cherrypy backend
config.vm.network :forwarded_port, guest: 8089, host: 8089 # locust performance testing (not turned on by default)
config.vm.provision "shell", inline: $set_environment_variables, run: "always"
config.trigger.before :provision do |init|
init.info = "Bringing up your Vagrant guest machine!"
config.vm.synced_folder ".", ENV['SYNC_FOLDER'] , create: true
###########################################
# COMMENT OUT LINE AFTER FIRST RUN #
###########################################
# config.vm.synced_folder ".", "/home/vagrant/init", , create: true
###########################################
### UNCOMMENT AFTER FIRST RUN ###
###########################################
# config.vm.synced_folder ".", "/home/vagrant/reggie-formula", create: true
##########################################
# END EDITS #
##########################################
####################################################################################
##### SHELL SCRIPT TO STOP BOX IF PROVISIONED AND REGGIE IS NOT HOST EDITABLE #####
####################################################################################
config.vm.provision "shell", run: "always", env: {
'SYNC_FOLDER'=>ENV['SYNC_FOLDER']
},
inline:"
if [ -d /home/vagrant/reggie-formula ] || [ -d /home/vagrant/init ] ; then
echo '$SYNC_FOLDER IS INVALID '
exit
fi
if [ ! -d /home/vagrant/reggie-formula ] ; then
echo '########################################################'
echo '# Setting up reggie-formula #'
echo '########################################################'
mkdir /home/vagrant/reggie-formula
cp -ar /home/vagrant/init/* /home/vagrant/reggie-formula
chown -R vagrant:vagrant reggie-formula
else
echo '########################################################'
echo '# reggie-formula already exists, YAY #'
echo '########################################################'
fi
###########################################
# COMMENT OUT SECTION AFTER FIRST RUN #
###########################################
if [ -d /home/vagrant/reggie-formula/reggie_install ] && [ -d /home/vagrant/init/reggie ] ; then
echo '########################################################'
echo '# Edit vagrantfile and comment out FIRST RUN. #'
echo '# Also, uncomment AFTER FIRST RUN LINE #'
echo '########################################################'
halt
exit 2
fi
"
end
# No good can come from updating plugins.
# Plus, this makes creating Vagrant instances MUCH faster.
if Vagrant.has_plugin?('vagrant-vbguest')
config.vbguest.auto_update = false
end
# This is the most amazing module ever, it caches anything you download with apt-get!
# To install it: vagrant plugin install vagrant-cachier
if Vagrant.has_plugin?('vagrant-cachier')
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
config.cache.scope = :box
end
config.vm.provider :virtualbox do |vb|
vb.memory = 1536
vb.cpus = 2
if Vagrant::Util::Platform.windows?
# don't use colons (:) or parens in windows filenames, will cause vagrant up to fail
vb.name = 'reggie %s %s %s' % [ENV['EVENT_NAME'], ENV['EVENT_YEAR'], Time.now.strftime('%Y-%m-%d %s')]
else
vb.name = 'reggie (%s %s) %s' % [ENV['EVENT_NAME'], ENV['EVENT_YEAR'], Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')]
end
# Allow symlinks to be created in /home/vagrant/reggie-formula.
# Modify "home_vagrant_reggie-formula" to be different if you change the path.
# NOTE: requires Vagrant to be run as administrator for this to work.
# vb.customize ['setextradata', :id, 'VBoxInternal2/SharedFoldersEnableSymlinksCreate/home_vagrant_reggie-formula', '1']
# config.vm.synced_folder '/host/path', '/guest/path', type: "smb", mount_options: ['mfsymlink']
#This option may be globally disabled with an environment variable:
# VAGRANT_DISABLE_SMBMFSYMLINKS=1
end
config.vm.provision :shell, env: {
'EVENT_NAME'=>ENV['EVENT_NAME'],
'EVENT_YEAR'=>ENV['EVENT_YEAR'],
'IS_VAGRANT_WINDOWS'=>ENV['IS_VAGRANT_WINDOWS']
}, inline: "
set -e
# Upgrade all packages to the latest version - this is VERY SLOW on Windows, so Windows users are advised to comment this out
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
sudo -E apt-get -qy update
sudo -E apt-get -qy -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' upgrade
sudo -E apt-get -qy autoclean
# Install some prerequisites
sudo -E apt-get -qy install libssh-dev python-git swapspace python3-pygit2
# Create a sparse checkout of the infrastructure repo with only the reggie_config and reggie_state dirs
if [ ! -d '/home/vagrant/reggie-formula/infrastructure/.git' ]; then
git init /home/vagrant/reggie-formula/infrastructure
cd /home/vagrant/reggie-formula/infrastructure
git remote add origin https://github.com/magfest/infrastructure.git
git config core.sparsecheckout true
echo '/docs/*' >> .git/info/sparse-checkout
echo '/reggie_config/*' >> .git/info/sparse-checkout
echo '/reggie_state/*' >> .git/info/sparse-checkout
echo '/README.md' >> .git/info/sparse-checkout
git pull --depth=1 origin master
git branch --set-upstream-to=origin/master master
fi
# Set up event grains
mkdir -p /etc/salt
cat > /etc/salt/grains <<ENDGRAINS
event_name: ${EVENT_NAME}
event_year: ${EVENT_YEAR}
is_vagrant_windows: ${IS_VAGRANT_WINDOWS}
ENDGRAINS
"
config.vm.provision :salt do |salt|
salt.install_master = true
salt.install_type = 'git'
salt.install_args = 'v2019.2'
salt.seed_master = {reggie: 'vagrant/vagrant/files/reggie.pub'}
salt.master_config = 'vagrant/vagrant/files/salt_master.yaml'
salt.minion_config = 'vagrant/vagrant/files/salt_minion.yaml'
salt.minion_id = 'reggie'
salt.minion_key = 'vagrant/vagrant/files/reggie.pem'
salt.minion_pub = 'vagrant/vagrant/files/reggie.pub'
salt.run_highstate = false
salt.orchestrations = ['orchestration.vagrant_up']
salt.colorize = true
salt.log_level = 'info'
salt.verbose = true
end
config.vm.provision "shell",
inline: "
echo '########################################################'
echo '########## COPYING INSTALL TO HOST ##########'
echo '########################################################'
cp -au /home/vagrant/reggie-formula/* /home/vagrant/init
echo '########################################################'
echo '########## PLEASE RESTART VAGRANT ##########'
echo '########################################################'
echo '########################################################'
echo '########## halting VAGRANT ##########'
echo '########################################################'
exit
"
config.vm.provision :shell, run: "always", env: {
'EVENT_NAME'=>ENV['EVENT_NAME'],
'EVENT_YEAR'=>ENV['EVENT_YEAR'],
'IS_VAGRANT_WINDOWS'=>ENV['IS_VAGRANT_WINDOWS'],
'SYNC_FOLDER'=>ENV['SYNC_FOLDER']
}, :path => 'post.sh'
# config.vm.post_up_message = "
# All done!
# event_name: #{ENV["EVENT_NAME"]}
# event_year: #{ENV["EVENT_YEAR"]}
#
# To login to your new development machine run:
# vagrant ssh
#
# The machine is configured using salt (minion id is 'reggie'):
# sudo salt reggie state.apply
#
# Shortcut aliases have been installed for you:
# alias run_server='reggie-formula/reggie_install/env/bin/python reggie-formula/reggie_install/run_server.py'
#
# The reggie virtualenv has been added to your path, along with a custom python startup:
# export PYTHONSTARTUP=\"/home/vagrant/.pythonstartup.py\"
# export PATH=\"reggie-formula/reggie_install/env/bin:$PATH\"
#
# The following services have been installed with systemd:
# reggie
# +- reggie-web
# +- reggie-worker
# +- reggie-scheduler
#
# You can access the web interface at:
# https://localhost:4443
# Username: [email protected]
# Password: magfest
#
#"
#config.vm.provision "shell", run: "always", do |s|
#s.path = "post.sh"
#end
end