-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
529 lines (441 loc) Β· 13.5 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# BSG
BOX_IMAGE = "bento/ubuntu-17.04"
# https://www.vagrantup.com/docs/provisioning/basic_usage.html
# sudo nano /etc/hosts
# Update your hosts file
# 192.168.99.21 redis.local
# connect with medis with ip address 192.168.99.21 (port 7777)
# 192.168.99.22 bsg-monitor.local
# 192.168.99.23 bsg-map.local
# 192.168.99.101 bs01.local
# 192.168.99.102 bs02.local
# 192.168.99.103 bs03.local
# 192.168.99.104 bs04.local
# 192.168.99.105 bs05.local
# 192.168.99.106 bs06.local
# 192.168.99.107 bs07.local
# 192.168.99.201 r01.local
# 192.168.99.202 r02.local
# 192.168.99.203 r03.local
# 192.168.99.204 r04.local
# 192.168.99.205 r05.local
# 192.168.99.206 r06.local
# 192.168.99.207 r07.local
# 192.168.99.208 r08.local
# 192.168.99.209 r09.local
# 192.168.99.210 faker-raider.local
Vagrant.configure("2") do |config|
config.vm.box = BOX_IMAGE
# ===========================
# Redis server
# ===========================
config.vm.define "redis" do |node|
node.vm.hostname = "redis.local"
node.vm.network "private_network", ip: "192.168.99.21"
node.vm.network :forwarded_port, guest: 7777, host: 7777
node.vm.provider "virtualbox" do |vb|
vb.memory = 256
vb.cpus = 1
vb.name = "redis"
end
config.vm.provision "shell", inline: "echo hello"
node.vm.provision "setup", type: "shell", inline: <<-SHELL
echo "π Installing Redis..."
apt-get install redis-server -y
SHELL
# vagrant up redis --provision-with start
node.vm.provision "start", type: "shell", inline: <<-SHELL
rm dump.rdb
nohup redis-server --port 7777 --protected-mode no > /dev/null 2>&1 &
echo "π bye! πππ"
SHELL
end # end of config - Redis Server
# ===========================
# BaseStars microservices
# ===========================
basestars=[
{
:name => "bs01",
:hostname => "bs01.local",
:ip => "192.168.99.101",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8081,
:color => "FF5733"
},
{
:name => "bs02",
:hostname => "bs02.local",
:ip => "192.168.99.102",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8082,
:color => "339FFF"
},
{
:name => "bs03",
:hostname => "bs03.local",
:ip => "192.168.99.103",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8083,
:color => "46FF33"
},
{
:name => "bs04",
:hostname => "bs04.local",
:ip => "192.168.99.104",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8084,
:color => "FF33F0"
},
{
:name => "bs05",
:hostname => "bs05.local",
:ip => "192.168.99.105",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8085,
:color => "edab38"
},
{
:name => "bs06",
:hostname => "bs06.local",
:ip => "192.168.99.106",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8086,
:color => "9e37dd"
},
{
:name => "bs07",
:hostname => "bs07.local",
:ip => "192.168.99.107",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 8087,
:color => "3dedea"
}
]
# vagrant up bs01 --provision
# vagrant up bs02 --provision
# vagrant up bs03 --provision
# vagrant up bs04 --provision
basestars.each do |basestar|
config.vm.define basestar[:name] do |node|
node.vm.box = basestar[:box]
node.vm.hostname = basestar[:hostname]
node.vm.network "private_network", ip: basestar[:ip]
node.vm.network :forwarded_port, guest: basestar[:guest_port], host: basestar[:host_port]
node.vm.provider "virtualbox" do |vb|
vb.memory = basestar[:ram]
vb.cpus = basestar[:cpu]
vb.name = basestar[:name]
end
node.vm.provision "setup", type: "shell", inline: <<-SHELL
echo "π Installing Java..."
apt-get update -y
apt-get install openjdk-8-jdk -y
apt-get install maven -y
SHELL
# vagrant up bs02 --provision-with file
node.vm.provision "file", source: "../basestar", destination: "$HOME/basestar"
# do the same thing with a git clone
node.vm.provision "build", type: "shell", inline: <<-SHELL
echo "π Building BaseStar..."
cd basestar
mvn clean package
SHELL
node.vm.provision "run", type: "shell", inline: <<-SHELL
echo "π running BaseStar..."
export PORT=#{basestar[:guest_port]}
export SERVICE_PORT=#{basestar[:guest_port]}
export COLOR=#{basestar[:color]}
export REDIS_RECORDS_KEY="bsg-the-plan"
export SERVICE_NAME=#{basestar[:name]}
#export SERVICE_HOST=#{basestar[:hostname]}
export SERVICE_HOST=#{basestar[:ip]}
export SERVICE_ROOT="/api"
export REDIS_PORT=7777
export REDIS_HOST="192.168.99.21"
#export REDIS_PASSWORD=
cd basestar
nohup java -jar target/basestar-1.0-SNAPSHOT-fat.jar &
echo "π BaseStar listening on http://#{basestar[:hostname]}:#{basestar[:guest_port]} ..."
SHELL
end # end config
end # end basestars
# ===========================
# WebApp
# ===========================
# ---------------------------
# BSG Monitor
# ---------------------------
config.vm.define "bsg-monitor" do |node|
node.vm.hostname = "bsg-monitor.local"
node.vm.network "private_network", ip: "192.168.99.22"
node.vm.network :forwarded_port, guest: 8080, host: 9090
node.vm.provider "virtualbox" do |vb|
vb.memory = 1024
vb.cpus = 1
vb.name = "bsg-monitor"
end
node.vm.provision "setup", type: "shell", inline: <<-SHELL
echo "π Installing Java..."
apt-get update -y
apt-get install openjdk-8-jdk -y
#apt-get install maven -y
## Scala
wget https://downloads.lightbend.com/scala/2.12.4/scala-2.12.4.deb
dpkg -i scala-2.12.4.deb
apt-get update
apt-get install scala
## SBT
wget https://dl.bintray.com/sbt/debian/sbt-0.13.16.deb
dpkg -i sbt-0.13.16.deb
apt-get update
apt-get install sbt
SHELL
node.vm.provision "file", source: "../bsg-monitor", destination: "$HOME/bsg-monitor"
node.vm.provision "build", type: "shell", inline: <<-SHELL
echo "π Building BSG Monitor..."
cd bsg-monitor
sbt compile
SHELL
node.vm.provision "run", type: "shell", inline: <<-SHELL
echo "π Building and running BSG Monitor..."
export PORT=8080
export SERVICE_PORT=8080
export REDIS_RECORDS_KEY="bsg-the-plan"
export REDIS_PORT=7777
export REDIS_HOST="192.168.99.21" # add to a variable
#export REDIS_PASSWORD=
cd bsg-monitor
nohup sbt run &
echo "π Bsg-Monitor listening on http://bsg-monitor.local:8080 ..."
SHELL
end # end of config - BSG Monitor
# ---------------------------
# BSG Map
# ---------------------------
config.vm.define "bsg-map" do |node|
node.vm.hostname = "bsg-map.local"
node.vm.network "private_network", ip: "192.168.99.23"
node.vm.network :forwarded_port, guest: 8080, host: 9091
node.vm.provider "virtualbox" do |vb|
vb.memory = 256
vb.cpus = 1
vb.name = "bsg-map"
end
node.vm.provision "setup", type: "shell", inline: <<-SHELL
echo "π Installing nodejs..."
apt-get update -y
curl -sL https://deb.nodesource.com/setup_7.x | sudo bash -
apt-get install nodejs -y
SHELL
node.vm.provision "file", source: "../bsg-map", destination: "$HOME/bsg-map"
node.vm.provision "build", type: "shell", inline: <<-SHELL
echo "π Building BSG Msp..."
cd bsg-map
npm install
SHELL
node.vm.provision "run", type: "shell", inline: <<-SHELL
echo "π Running BSG Map..."
cd bsg-map
export PORT=8080
#export RAIDERS_SERVICE=http://bsg-monitor.local:8080/api/raiders
export RAIDERS_SERVICE=http://192.168.99.22:8080/api/raiders
nohup npm start > /dev/null 2>&1 &
echo "π Bsg-Map listening on http://bsg-map.local:8080 ..."
SHELL
end # end of config - BSG Map
# ===========================
# Raiders microservices
# ===========================
raiders=[
{
:name => "r01",
:hostname => "r01.local",
:ip => "192.168.99.201",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7071
},
{
:name => "r02",
:hostname => "r02.local",
:ip => "192.168.99.202",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7072
},
{
:name => "r03",
:hostname => "r03.local",
:ip => "192.168.99.203",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7073
},
{
:name => "r04",
:hostname => "r04.local",
:ip => "192.168.99.204",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7074
},
{
:name => "r05",
:hostname => "r05.local",
:ip => "192.168.99.205",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7075
},
{
:name => "r06",
:hostname => "r06.local",
:ip => "192.168.99.206",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7076
},
{
:name => "r07",
:hostname => "r07.local",
:ip => "192.168.99.207",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7077
},
{
:name => "r08",
:hostname => "r08.local",
:ip => "192.168.99.208",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7078
},
{
:name => "r09",
:hostname => "r09.local",
:ip => "192.168.99.209",
:box => BOX_IMAGE,
:ram => 256,
:cpu => 1,
:guest_port => 8080,
:host_port => 7079
},
]
raiders.each do |raider|
config.vm.define raider[:name] do |node|
node.vm.box = raider[:box]
node.vm.hostname = raider[:hostname]
node.vm.network "private_network", ip: raider[:ip]
node.vm.network :forwarded_port, guest: raider[:guest_port], host: raider[:host_port]
node.vm.provider "virtualbox" do |vb|
vb.memory = raider[:ram]
vb.cpus = raider[:cpu]
vb.name = raider[:name]
end
node.vm.provision "setup", type: "shell", inline: <<-SHELL
echo "π Installing Java..."
apt-get update -y
apt-get install openjdk-8-jdk -y
apt-get install maven -y
SHELL
node.vm.provision "file", source: "../k-raider", destination: "$HOME/k-raider"
# do the same thing with a git clone
node.vm.provision "build", type: "shell", inline: <<-SHELL
echo "π Building Raider..."
cd k-raider
mvn clean package
SHELL
node.vm.provision "run", type: "shell", inline: <<-SHELL
echo "π running Raider..."
export PORT=#{raider[:guest_port]}
export SERVICE_PORT=#{raider[:guest_port]}
export COLOR=#{raider[:color]}
export REDIS_RECORDS_KEY="bsg-the-plan"
export SERVICE_NAME=#{raider[:name]}
#export SERVICE_HOST=#{raider[:hostname]}
export SERVICE_HOST=#{raider[:ip]}
export SERVICE_ROOT="/api"
export REDIS_PORT=7777
export REDIS_HOST="192.168.99.21"
#export REDIS_PASSWORD=
cd k-raider
nohup java -jar target/k-raider-1.0-SNAPSHOT-fat.jar &
echo "π Raider listening on http://#{raider[:hostname]}:#{raider[:guest_port]} ..."
SHELL
end # end config
end # end raiders
# ===========================
# Fake raider
# ===========================
config.vm.define "fake-raider" do |node|
node.vm.hostname = "fake-raider.local"
node.vm.network "private_network", ip: "192.168.99.210"
node.vm.network :forwarded_port, guest: 8080, host: 9300
node.vm.provider "virtualbox" do |vb|
vb.memory = 256
vb.cpus = 1
vb.name = "fake-raider"
end
node.vm.provision "setup", type: "shell", inline: <<-SHELL
echo "π Installing nodejs..."
apt-get update -y
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
apt-get install nodejs -y
SHELL
node.vm.provision "file", source: "../fake-raider", destination: "$HOME/fake-raider"
node.vm.provision "build", type: "shell", inline: <<-SHELL
echo "π Building Fake Raider..."
cd fake-raider
npm install
SHELL
node.vm.provision "run", type: "shell", inline: <<-SHELL
echo "π Running Fake Raider..."
cd fake-raider
export PORT=8080
export ENDPOINT="http://192.168.99.210:8080/api"
export HOST="192.168.99.210"
export DISCOVERY="http://192.168.99.22:8080/discovery"
#node index.js
nohup node index.js > /dev/null 2>&1 &
echo "π Faker raider listening on http://192.168.99.210:8080/api ..."
SHELL
end # end of config - fake raider
end