-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVagrantfile
More file actions
792 lines (673 loc) · 26.3 KB
/
Vagrantfile
File metadata and controls
792 lines (673 loc) · 26.3 KB
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# -*- mode: ruby -*-
# vi: set ft=ruby :
# =============================================================================
# IACT DevBox - Vagrant Configuration (Multi-Machine)
# MariaDB 11.4 LTS + PostgreSQL 16 + Adminer 4.8.1 Development Environment
# =============================================================================
# Architecture: 3 separate VMs with Host-Only networking
# - MariaDB VM: 192.168.56.10:3306
# - PostgreSQL VM: 192.168.56.11:5432
# - Adminer VM: 192.168.56.12:80/443
# =============================================================================
VAGRANTFILE_API_VERSION = "2"
# =============================================================================
# COLOR CODES FOR TERMINAL OUTPUT
# =============================================================================
red = "\033[0;31m"
green = "\033[0;32m"
yellow = "\033[0;33m"
blue = "\033[0;34m"
creset = "\033[0m"
# Directory paths
vagrant_dir = File.expand_path(File.dirname(__FILE__))
# =============================================================================
# PLUGIN AUTO-INSTALLATION (vagrant-goodhosts for adminer.devbox domain)
# =============================================================================
unless Vagrant.has_plugin?('vagrant-goodhosts')
puts ""
puts "#{yellow}╔═══════════════════════════════════════════════════════════════════╗#{creset}"
puts "#{yellow}║ Installing required plugin: vagrant-goodhosts ║#{creset}"
puts "#{yellow}╚═══════════════════════════════════════════════════════════════════╝#{creset}"
puts ""
puts "#{blue}This plugin automatically manages your hosts file for adminer.devbox#{creset}"
puts ""
# Check if local gem file exists (for offline installation)
if File.file?(File.join(vagrant_dir, 'vagrant-goodhosts.gem'))
puts "#{blue}Installing from local gem file...#{creset}"
system('vagrant plugin install ' + File.join(vagrant_dir, 'vagrant-goodhosts.gem'))
File.delete(File.join(vagrant_dir, 'vagrant-goodhosts.gem'))
puts ""
puts "#{green}✓ vagrant-goodhosts plugin installed from local gem#{creset}"
puts "#{yellow}Please run 'vagrant up' again to continue.#{creset}"
puts ""
exit
else
# Install from RubyGems
puts "#{blue}Installing from RubyGems...#{creset}"
unless system('vagrant plugin install vagrant-goodhosts')
puts ""
puts "#{red}✗ Failed to install vagrant-goodhosts plugin#{creset}"
puts "#{yellow}You can install it manually with: vagrant plugin install vagrant-goodhosts#{creset}"
puts ""
exit 1
end
puts ""
puts "#{green}✓ vagrant-goodhosts plugin installed successfully#{creset}"
puts "#{yellow}Please run 'vagrant up' again to continue.#{creset}"
puts ""
exit
end
end
# Disable vbguest auto-update if plugin is installed (causes issues for some users)
if Vagrant.has_plugin?('vagrant-vbguest')
puts "#{blue}ℹ vagrant-vbguest detected - auto_update will be disabled#{creset}"
end
puts "#{green}✓ All required plugins are installed#{creset}"
puts ""
# =============================================================================
# CONFIGURATION VARIABLES - SINGLE SOURCE OF TRUTH
# =============================================================================
# Network Configuration - Host-Only Network
MARIADB_IP = "192.168.56.10"
POSTGRES_IP = "192.168.56.11"
ADMINER_IP = "192.168.56.12"
# Adminer Domain (.devbox TLD for IACT DevBox)
ADMINER_DOMAIN = "adminer.devbox"
# Database Ports
MARIADB_PORT = "3306"
POSTGRES_PORT = "5432"
ADMINER_HTTP_PORT = "80"
ADMINER_HTTPS_PORT = "443"
# MariaDB Configuration
MARIADB_VERSION = "11.4"
DB_MARIADB_NAME = "ivr_legacy"
DB_MARIADB_USER = "django_user"
DB_MARIADB_PASSWORD = "django_pass"
DB_MARIADB_ROOT_PASSWORD = "rootpass123"
DB_CHARSET = "utf8mb4"
DB_COLLATION = "utf8mb4_unicode_ci"
# PostgreSQL Configuration
POSTGRES_VERSION = "16"
DB_POSTGRES_NAME = "iact_analytics"
DB_POSTGRES_USER = "django_user"
DB_POSTGRES_PASSWORD = "django_pass"
POSTGRES_PASSWORD = "postgrespass123"
# Adminer Configuration
ADMINER_VERSION = "4.8.1"
SWAP_SIZE = "1G"
# SSL Configuration
SSL_DAYS = "365"
SSL_COUNTRY = "MX"
SSL_STATE = "Estado"
SSL_CITY = "Ciudad"
SSL_ORG = "IACT DevBox"
SSL_OU = "Development"
SSL_CN = ADMINER_DOMAIN
# =============================================================================
# HELPER FUNCTIONS
# =============================================================================
# =============================================================================
# DISPLAY CONFIGURATION SUMMARY
# =============================================================================
puts "=" * 70
puts " IACT DevBox Multi-Machine Configuration"
puts "=" * 70
puts ""
puts "Architecture: 3 VMs with Host-Only Network (192.168.56.0/24)"
puts ""
puts "VM 1 - MariaDB:"
puts " Name: iact-mariadb"
puts " IP: #{MARIADB_IP}:#{MARIADB_PORT}"
puts " Version: MariaDB #{MARIADB_VERSION}"
puts " Database: #{DB_MARIADB_NAME}"
puts " Memory: 2048 MB"
puts " CPUs: 1"
puts ""
puts "VM 2 - PostgreSQL:"
puts " Name: iact-postgres"
puts " IP: #{POSTGRES_IP}:#{POSTGRES_PORT}"
puts " Version: PostgreSQL #{POSTGRES_VERSION}"
puts " Database: #{DB_POSTGRES_NAME}"
puts " Memory: 2048 MB"
puts " CPUs: 1"
puts ""
puts "VM 3 - Adminer:"
puts " Name: iact-adminer"
puts " IP: #{ADMINER_IP}:#{ADMINER_HTTP_PORT}/#{ADMINER_HTTPS_PORT}"
puts " Domain: #{ADMINER_DOMAIN}"
puts " URLs: http://#{ADMINER_DOMAIN}"
puts " https://#{ADMINER_DOMAIN}"
puts " Version: Adminer #{ADMINER_VERSION}"
puts " Memory: 1024 MB"
puts " CPUs: 1"
puts ""
puts "Commands:"
puts " Start all: vagrant up"
puts " Start one: vagrant up mariadb|postgresql|adminer"
puts " SSH: vagrant ssh mariadb|postgresql|adminer"
puts " Stop all: vagrant halt"
puts " Destroy all: vagrant destroy"
puts "=" * 70
puts ""
# =============================================================================
# APT CACHE OPTIMIZATION
# =============================================================================
def local_cache(box_name)
begin
cache_dir = File.join(File.expand_path('~/.vagrant.d'), 'cache', 'apt', box_name)
FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
return cache_dir if File.writable?(cache_dir)
rescue => e
puts "WARNING: APT cache disabled: #{e.message}"
end
nil
end
# =============================================================================
# VAGRANT MULTI-MACHINE CONFIGURATION
# =============================================================================
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# ===========================================================================
# GLOBAL TRIGGERS - Execute before/after vagrant commands
# ===========================================================================
# Trigger: Before 'vagrant up' - Check Host-Only network status
config.trigger.before :up do |trigger|
trigger.name = "Network Setup Check"
trigger.info = "Checking Host-Only network configuration..."
trigger.ruby do |env, machine|
puts ""
puts "=" * 70
puts " NETWORK CONFIGURATION CHECK"
puts "=" * 70
puts ""
# Verificar si existen interfaces Host-Only
begin
if Vagrant::Util::Platform.windows?
result = `VBoxManage list hostonlyifs 2>NUL`
else
result = `VBoxManage list hostonlyifs 2>/dev/null`
end
rescue => e
result = ""
end
if result.nil? || result.empty?
# Solo avisamos, Vagrant creará la red automáticamente al detectar
# la configuración "private_network" en las VMs.
puts "[INFO] No Host-Only network detected. Vagrant will create one."
else
puts "[OK] Host-Only network environment is ready."
puts " Vagrant will auto-assign the IPs to the correct adapter."
end
puts ""
puts "=" * 70
puts ""
end
end
# Trigger: After successful 'vagrant up'
config.trigger.after :up do |trigger|
trigger.name = "Post-Up Summary"
trigger.info = "VMs are ready!"
trigger.only_on = "adminer" # Only show once (after last VM)
trigger.ruby do |env, machine|
puts ""
puts "=" * 70
puts " [OK] ALL VMs READY"
puts "=" * 70
puts ""
puts "Quick Test:"
puts " ping #{MARIADB_IP}"
puts " ping #{POSTGRES_IP}"
puts " ping #{ADMINER_IP}"
puts ""
puts "Connect:"
puts " mysql -h #{MARIADB_IP} -u root -p'#{DB_MARIADB_ROOT_PASSWORD}'"
puts " psql -h #{POSTGRES_IP} -U postgres"
puts " http://#{ADMINER_IP}"
puts ""
puts "Logs:"
puts " ./logs/"
puts ""
puts "=" * 70
puts ""
end
end
# Trigger: After successful 'vagrant up'
config.trigger.after :up do |trigger|
trigger.name = "Post-Up Summary"
trigger.info = "VMs are ready!"
trigger.only_on = "adminer" # Only show once (after last VM)
trigger.ruby do |env, machine|
puts ""
puts "=" * 70
puts " [OK] ALL VMs READY"
puts "=" * 70
puts ""
puts "Quick Test:"
puts " ping #{MARIADB_IP}"
puts " ping #{POSTGRES_IP}"
puts " ping #{ADMINER_IP}"
puts ""
puts "Connect:"
puts " mysql -h #{MARIADB_IP} -u root -p'#{DB_MARIADB_ROOT_PASSWORD}'"
puts " psql -h #{POSTGRES_IP} -U postgres"
puts " http://#{ADMINER_IP}"
puts ""
puts "Logs:"
puts " ./logs/"
puts ""
puts "=" * 70
puts ""
end
end
# ===========================================================================
# VM 1: MARIADB (192.168.56.10)
# ===========================================================================
config.vm.define "mariadb", primary: true do |mariadb|
# Base box
mariadb.vm.box = "ubuntu/focal64"
mariadb.vm.box_check_update = true
# Hostname
mariadb.vm.hostname = "iact-mariadb"
# Disable vbguest auto-update if plugin is installed
if Vagrant.has_plugin?("vagrant-vbguest")
mariadb.vbguest.auto_update = false
end
# SSH configuration
mariadb.ssh.forward_agent = true
mariadb.ssh.insert_key = true
mariadb.ssh.connect_timeout = 120
# -----------------------------------------------------------------------
# Network - Host-Only with static IP (FORMA ESTÁNDAR)
# -----------------------------------------------------------------------
# Al eliminar el parámetro 'name', evitamos conflictos de adaptadores duplicados.
mariadb.vm.network "private_network", ip: MARIADB_IP, netmask: "255.255.255.0"
# SSH Port Forwarding
mariadb.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", auto_correct: true
# Synced folders
cache_dir = local_cache(mariadb.vm.box)
if cache_dir
mariadb.vm.synced_folder cache_dir, "/var/cache/apt/archives/",
create: true,
mount_options: ["dmode=755,fmode=644"]
end
mariadb.vm.synced_folder ".", "/vagrant",
create: true,
mount_options: [
"dmode=755,fmode=644",
"iocharset=utf8",
"ttl=1"
]
# VirtualBox provider configuration for MariaDB
mariadb.vm.provider "virtualbox" do |vb|
vb.name = "iact-mariadb"
vb.memory = 2048
vb.cpus = 1
vb.gui = false
vb.linked_clone = true
# Performance optimizations
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["modifyvm", :id, "--vram", "12"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.customize ["modifyvm", :id, "--rtcuseutc", "on"]
# Red y Conectividad (Crucial para VirtualBox 7.x)
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
vb.customize ["modifyvm", :id, "--cableconnected2", "on"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
# Provisioning - MariaDB VM
mariadb.vm.provision "shell", inline: <<-SHELL
set -euo pipefail
echo ""
echo "=================================================="
echo " MariaDB VM Provisioning"
echo "=================================================="
echo ""
# Export ALL configuration variables
export MARIADB_VERSION="#{MARIADB_VERSION}"
export DB_NAME="#{DB_MARIADB_NAME}"
export DB_CHARSET="#{DB_CHARSET}"
export DB_COLLATION="#{DB_COLLATION}"
export DB_USER="#{DB_MARIADB_USER}"
export DB_PASSWORD="#{DB_MARIADB_PASSWORD}"
export DB_ROOT_PASSWORD="#{DB_MARIADB_ROOT_PASSWORD}"
export MARIADB_IP="#{MARIADB_IP}"
export MARIADB_PORT="#{MARIADB_PORT}"
# Create logs directory
mkdir -p /vagrant/logs
# Make scripts executable
find /vagrant/provisioners -name "*.sh" -exec chmod +x {} \\;
find /vagrant/utils -name "*.sh" -exec chmod +x {} \\;
echo "[OK] Scripts prepared"
echo ""
# Execute bootstrap script
cd /vagrant
echo "Executing MariaDB bootstrap..."
if bash provisioners/mariadb/bootstrap.sh; then
echo "[OK] MariaDB provisioning completed"
else
echo "[ERROR] MariaDB provisioning failed"
exit 1
fi
echo ""
echo "=================================================="
echo " [OK] MariaDB VM Ready"
echo "=================================================="
echo ""
echo "MariaDB accessible at: #{MARIADB_IP}:#{MARIADB_PORT}"
echo " Database: #{DB_MARIADB_NAME}"
echo " User: #{DB_MARIADB_USER}"
echo ""
SHELL
end
# ===========================================================================
# VM 2: POSTGRESQL (192.168.56.11)
# ===========================================================================
config.vm.define "postgresql" do |postgresql|
# Base box
postgresql.vm.box = "ubuntu/focal64"
postgresql.vm.box_check_update = true
# Hostname
postgresql.vm.hostname = "iact-postgres"
# Disable vbguest auto-update if plugin is installed
if Vagrant.has_plugin?("vagrant-vbguest")
postgresql.vbguest.auto_update = false
end
# SSH configuration
postgresql.ssh.forward_agent = true
postgresql.ssh.insert_key = true
postgresql.ssh.connect_timeout = 120
# -----------------------------------------------------------------------
# Network - Host-Only with static IP (FORMA ESTÁNDAR)
# -----------------------------------------------------------------------
# Simplificado para evitar conflictos de nombres de adaptadores
postgresql.vm.network "private_network", ip: POSTGRES_IP, netmask: "255.255.255.0"
# SSH Port Forwarding
postgresql.vm.network "forwarded_port", guest: 22, host: 2200, id: "ssh", auto_correct: true
# Synced folders
cache_dir = local_cache(postgresql.vm.box)
if cache_dir
postgresql.vm.synced_folder cache_dir, "/var/cache/apt/archives/",
create: true,
mount_options: ["dmode=755,fmode=644"]
end
postgresql.vm.synced_folder ".", "/vagrant",
create: true,
mount_options: [
"dmode=755,fmode=644",
"iocharset=utf8",
"ttl=1"
]
# VirtualBox provider configuration for PostgreSQL
postgresql.vm.provider "virtualbox" do |vb|
vb.name = "iact-postgres"
vb.memory = 2048
vb.cpus = 1
vb.gui = false
vb.linked_clone = true
# Performance optimizations
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["modifyvm", :id, "--vram", "12"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.customize ["modifyvm", :id, "--rtcuseutc", "on"]
# Red y Conectividad (Cambiado de 82540EM a virtio y añadido cableconnected2)
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
vb.customize ["modifyvm", :id, "--cableconnected2", "on"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
# Provisioning - PostgreSQL VM
postgresql.vm.provision "shell", inline: <<-SHELL
set -euo pipefail
echo ""
echo "=================================================="
echo " PostgreSQL VM Provisioning"
echo "=================================================="
echo ""
# Export ALL configuration variables
export POSTGRES_VERSION="#{POSTGRES_VERSION}"
export DB_NAME="#{DB_POSTGRES_NAME}"
export DB_USER="#{DB_POSTGRES_USER}"
export DB_PASSWORD="#{DB_POSTGRES_PASSWORD}"
export POSTGRES_PASSWORD="#{POSTGRES_PASSWORD}"
export POSTGRES_IP="#{POSTGRES_IP}"
export POSTGRES_PORT="#{POSTGRES_PORT}"
# Create logs directory
mkdir -p /vagrant/logs
# Make scripts executable
find /vagrant/provisioners -name "*.sh" -exec chmod +x {} \\;
find /vagrant/utils -name "*.sh" -exec chmod +x {} \\;
echo "[OK] Scripts prepared"
echo ""
# Execute bootstrap script
cd /vagrant
echo "Executing PostgreSQL bootstrap..."
if bash provisioners/postgres/bootstrap.sh; then
echo "[OK] PostgreSQL provisioning completed"
else
echo "[ERROR] PostgreSQL provisioning failed"
exit 1
fi
echo ""
echo "=================================================="
echo " [OK] PostgreSQL VM Ready"
echo "=================================================="
echo ""
echo "PostgreSQL accessible at: #{POSTGRES_IP}:#{POSTGRES_PORT}"
echo " Database: #{DB_POSTGRES_NAME}"
echo " User: #{DB_POSTGRES_USER}"
echo ""
SHELL
end
# ===========================================================================
# VM 3: ADMINER (192.168.56.12)
# ===========================================================================
config.vm.define "adminer" do |adminer|
# Base box
adminer.vm.box = "ubuntu/focal64"
adminer.vm.box_check_update = true
# Hostname
adminer.vm.hostname = ADMINER_DOMAIN
# Disable vbguest auto-update if plugin is installed
if Vagrant.has_plugin?("vagrant-vbguest")
adminer.vbguest.auto_update = false
end
# SSH configuration
adminer.ssh.forward_agent = true
adminer.ssh.insert_key = true
adminer.ssh.connect_timeout = 120
# SSH Port Forwarding
adminer.vm.network "forwarded_port", guest: 22, host: 2201, id: "ssh", auto_correct: true
# -------------------------------------------------------------------------
# vagrant-goodhosts - Automatic hosts file management for adminer.devbox
# -------------------------------------------------------------------------
if Vagrant.has_plugin?('vagrant-goodhosts')
adminer.goodhosts.aliases = [
ADMINER_DOMAIN, # adminer.devbox
"www.#{ADMINER_DOMAIN}" # www.adminer.devbox
]
end
# -----------------------------------------------------------------------
# Network - Host-Only with static IP (FORMA ESTÁNDAR)
# -----------------------------------------------------------------------
# Eliminamos la dependencia de 'adapter_name' para evitar el error de timeout
adminer.vm.network "private_network", ip: ADMINER_IP, netmask: "255.255.255.0"
# Synced folders
cache_dir = local_cache(adminer.vm.box)
if cache_dir
adminer.vm.synced_folder cache_dir, "/var/cache/apt/archives/",
create: true,
mount_options: ["dmode=755,fmode=644"]
end
adminer.vm.synced_folder ".", "/vagrant",
create: true,
mount_options: [
"dmode=755,fmode=644",
"iocharset=utf8",
"ttl=1"
]
# VirtualBox provider configuration for Adminer
adminer.vm.provider "virtualbox" do |vb|
vb.name = "iact-adminer"
vb.memory = 1024
vb.cpus = 1
vb.gui = false
vb.linked_clone = true
# Performance optimizations
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["modifyvm", :id, "--vram", "12"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.customize ["modifyvm", :id, "--rtcuseutc", "on"]
# Red y Conectividad (Cambiado de 82540EM a virtio y añadido cableconnected2)
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
vb.customize ["modifyvm", :id, "--cableconnected2", "on"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
# Provisioning - Adminer VM
adminer.vm.provision "shell", inline: <<-SHELL
set -euo pipefail
echo ""
echo "=================================================="
echo " Adminer VM Provisioning"
echo "=================================================="
echo ""
# Export ALL configuration variables
export ADMINER_VERSION="#{ADMINER_VERSION}"
export ADMINER_IP="#{ADMINER_IP}"
export ADMINER_HTTP_PORT="#{ADMINER_HTTP_PORT}"
export ADMINER_HTTPS_PORT="#{ADMINER_HTTPS_PORT}"
export SWAP_SIZE="#{SWAP_SIZE}"
export MARIADB_IP="#{MARIADB_IP}"
export POSTGRES_IP="#{POSTGRES_IP}"
# SSL Configuration
export SSL_DAYS="#{SSL_DAYS}"
export SSL_COUNTRY="#{SSL_COUNTRY}"
export SSL_STATE="#{SSL_STATE}"
export SSL_CITY="#{SSL_CITY}"
export SSL_ORG="#{SSL_ORG}"
export SSL_OU="#{SSL_OU}"
export SSL_CN="#{SSL_CN}"
# Create logs directory
mkdir -p /vagrant/logs
# Make scripts executable
find /vagrant/provisioners -name "*.sh" -exec chmod +x {} \\;
find /vagrant/utils -name "*.sh" -exec chmod +x {} \\;
echo "[OK] Scripts prepared"
echo ""
# Execute bootstrap script
cd /vagrant
echo "Executing Adminer bootstrap..."
if bash provisioners/adminer/bootstrap.sh; then
echo "[OK] Adminer provisioning completed"
else
echo "[ERROR] Adminer provisioning failed"
exit 1
fi
echo ""
echo "=================================================="
echo " [OK] Adminer VM Ready"
echo "=================================================="
echo ""
echo "Adminer accessible at:"
echo " HTTP: http://#{ADMINER_IP}"
echo " HTTPS: https://#{ADMINER_IP}"
echo ""
echo "Connects to:"
echo " MariaDB: #{MARIADB_IP}:#{MARIADB_PORT}"
echo " PostgreSQL: #{POSTGRES_IP}:#{POSTGRES_PORT}"
echo ""
SHELL
end
# ===========================================================================
# POST-UP MESSAGE
# ===========================================================================
config.vm.post_up_message = <<-MESSAGE
========================================================================
IACT DevBox Multi-Machine Ready!
========================================================================
ARCHITECTURE: 3 VMs with Host-Only Network (192.168.56.0/24)
VM 1 - MARIADB:
IP: #{MARIADB_IP}
Port: #{MARIADB_PORT}
Database: #{DB_MARIADB_NAME}
User: #{DB_MARIADB_USER}
Password: #{DB_MARIADB_PASSWORD}
SSH: vagrant ssh mariadb
VM 2 - POSTGRESQL:
IP: #{POSTGRES_IP}
Port: #{POSTGRES_PORT}
Database: #{DB_POSTGRES_NAME}
User: #{DB_POSTGRES_USER}
Password: #{DB_POSTGRES_PASSWORD}
SSH: vagrant ssh postgresql
VM 3 - ADMINER:
IP: #{ADMINER_IP}
HTTP: http://#{ADMINER_IP}
HTTPS: https://#{ADMINER_IP}
SSH: vagrant ssh adminer
CONNECTION FROM HOST:
MariaDB:
mysql -h #{MARIADB_IP} -u root -p'#{DB_MARIADB_ROOT_PASSWORD}'
mysql -h #{MARIADB_IP} -u #{DB_MARIADB_USER} -p'#{DB_MARIADB_PASSWORD}' #{DB_MARIADB_NAME}
PostgreSQL:
PGPASSWORD='#{POSTGRES_PASSWORD}' psql -h #{POSTGRES_IP} -U postgres
PGPASSWORD='#{DB_POSTGRES_PASSWORD}' psql -h #{POSTGRES_IP} -U #{DB_POSTGRES_USER} -d #{DB_POSTGRES_NAME}
Adminer:
Open in browser: http://#{ADMINER_IP}
DJANGO SETTINGS:
DATABASES = {
'legacy': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '#{DB_MARIADB_NAME}',
'USER': '#{DB_MARIADB_USER}',
'PASSWORD': '#{DB_MARIADB_PASSWORD}',
'HOST': '#{MARIADB_IP}',
'PORT': '#{MARIADB_PORT}',
},
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '#{DB_POSTGRES_NAME}',
'USER': '#{DB_POSTGRES_USER}',
'PASSWORD': '#{DB_POSTGRES_PASSWORD}',
'HOST': '#{POSTGRES_IP}',
'PORT': '#{POSTGRES_PORT}',
}
}
VM MANAGEMENT:
Start all: vagrant up
Start one: vagrant up mariadb|postgresql|adminer
Stop all: vagrant halt
Stop one: vagrant halt mariadb|postgresql|adminer
SSH: vagrant ssh mariadb|postgresql|adminer
Destroy all: vagrant destroy
Status: vagrant status
VERIFICATION:
ping #{MARIADB_IP}
ping #{POSTGRES_IP}
ping #{ADMINER_IP}
mysql -h #{MARIADB_IP} -u root -p'#{DB_MARIADB_ROOT_PASSWORD}' -e "SELECT 1;"
PGPASSWORD='#{POSTGRES_PASSWORD}' psql -h #{POSTGRES_IP} -U postgres -c "SELECT 1;"
curl -I http://#{ADMINER_IP}
LOGS:
/vagrant/logs/
TROUBLESHOOTING (Windows):
If you get VERR_INTNET_FLT_IF_NOT_FOUND error:
1. Win+R → ncpa.cpl → Disable/Enable VirtualBox Host-Only adapter
2. See docs/TROUBLESHOOTING.md for more solutions
SECURITY NOTE:
- Each service runs on its own isolated VM
- Accessible from host machine only (192.168.56.0/24)
- NOT accessible from external networks
- Default passwords are for DEVELOPMENT ONLY!
========================================================================
MESSAGE
end