-
Notifications
You must be signed in to change notification settings - Fork 7
/
Vagrantfile
190 lines (153 loc) · 5.4 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 2.0"
require "yaml"
if ENV['CAC_TRIPPLANNER_MEMORY'].nil?
# OpenTripPlanner needs > 1GB to build and run
CAC_MEMORY_MB = "8192"
else
CAC_MEMORY_MB = ENV['CAC_TRIPPLANNER_MEMORY']
end
if ENV['CAC_TRIPPLANNER_CPU'].nil?
CPUS = "2"
else
CPUS = ENV['CAC_TRIPPLANNER_CPU']
end
def testing?
!ENV["VAGRANT_ENV"].nil? && ENV["VAGRANT_ENV"] == "TEST"
end
# Deserialize Ansible Galaxy installation metadata for a role
def galaxy_install_info(role_name)
role_path = File.join("deployment", "ansible", "roles", role_name)
galaxy_install_info = File.join(role_path, "meta", ".galaxy_install_info")
if (File.directory?(role_path) || File.symlink?(role_path)) && File.exists?(galaxy_install_info)
YAML.load_file(galaxy_install_info)
else
{ install_date: "", version: "0.0.0" }
end
end
# Uses the contents of roles.txt to ensure that ansible-galaxy is run
# if any dependencies are missing
def install_dependent_roles
ansible_directory = File.join("deployment", "ansible")
ansible_roles_spec = File.join(ansible_directory, "roles.yml")
YAML.load_file(ansible_roles_spec).each do |role|
role_name = role["name"] ? role["name"] : role["src"]
role_version = role["version"]
role_path = File.join(ansible_directory, "roles", role_name)
galaxy_metadata = galaxy_install_info(role_name)
if galaxy_metadata["version"] != role_version.strip
unless system("ansible-galaxy install -f -r #{ansible_roles_spec} -p #{File.dirname(role_path)}")
$stderr.puts "\nERROR: An attempt to install Ansible role dependencies failed."
exit(1)
end
break
end
end
end
# Install missing role dependencies based on the contents of roles.txt
if [ "up", "provision" ].include?(ARGV.first)
install_dependent_roles
end
ANSIBLE_INVENTORY_PATH = if testing?
"deployment/ansible/inventory/test"
else
"deployment/ansible/inventory/development"
end
VAGRANT_PROXYCONF_ENDPOINT = ENV["VAGRANT_PROXYCONF_ENDPOINT"]
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-22.04"
# Wire up the proxy if:
#
# - The vagrant-proxyconf Vagrant plugin is installed
# - The user set the VAGRANT_PROXYCONF_ENDPOINT environmental variable
#
if Vagrant.has_plugin?("vagrant-proxyconf") &&
!VAGRANT_PROXYCONF_ENDPOINT.nil?
config.proxy.http = VAGRANT_PROXYCONF_ENDPOINT
config.proxy.https = VAGRANT_PROXYCONF_ENDPOINT
config.proxy.no_proxy = "localhost,127.0.0.1"
end
config.vm.define "database" do |database|
# SSH issues bringing up DB VM with base box 22.04
# Explicitly define downgraded version for use by database until fix
database.vm.box = "bento/ubuntu-20.04"
database.vm.hostname = "database"
database.vm.network "private_network", ip: "192.168.56.25"
database.vm.synced_folder ".", "/vagrant", disabled: true
database.ssh.forward_x11 = true
database.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "deployment/ansible/database.yml"
ansible.inventory_path = ANSIBLE_INVENTORY_PATH
ansible.raw_arguments = ["--timeout=60"]
end
if ENV['CAC_DATABASE_MEMORY'].nil?
DB_MEMORY_MB = "512"
else
DB_MEMORY_MB = ENV['CAC_DATABASE_MEMORY']
end
database.vm.provider :virtualbox do |v|
v.memory = DB_MEMORY_MB
v.cpus = 2
end
end
config.vm.define "app" do |app|
CAC_APP_SHARED_FOLDER_TYPE = ENV.fetch("CAC_APP_SHARED_FOLDER_TYPE", "virtualbox")
if CAC_APP_SHARED_FOLDER_TYPE == "nfs"
if Vagrant::Util::Platform.linux? then
MOUNT_OPTIONS = ['rw', 'tcp', 'nolock', 'actimeo=1']
else
MOUNT_OPTIONS = ['vers=3', 'udp', 'actimeo=1']
end
else
if ENV.has_key?("CAC_APP_MOUNT_OPTIONS")
MOUNT_OPTIONS = ENV.fetch("CAC_APP_MOUNT_OPTIONS").split
else
MOUNT_OPTIONS = ["rw"]
end
end
app.vm.hostname = "app"
app.vm.network "private_network", ip: "192.168.56.24"
app.vm.synced_folder ".", "/opt/app", type: CAC_APP_SHARED_FOLDER_TYPE, mount_options: MOUNT_OPTIONS
# Web
app.vm.network "forwarded_port", guest: 443, host: 8024
# Django Dev
app.vm.network "forwarded_port", guest: 8026, host: 8026
app.ssh.forward_x11 = true
app.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "deployment/ansible/app.yml"
ansible.inventory_path = ANSIBLE_INVENTORY_PATH
ansible.raw_arguments = ["--timeout=60"]
end
if ENV['CAC_APP_MEMORY'].nil?
APP_MEMORY_MB = "1024"
else
APP_MEMORY_MB = ENV['CAC_APP_MEMORY']
end
app.vm.provider :virtualbox do |v|
v.memory = APP_MEMORY_MB
v.cpus = 2
end
end
config.vm.define "otp" do |otp|
otp.vm.hostname = "otp"
otp.vm.network "private_network", ip: "192.168.56.26"
otp.vm.synced_folder ".", "/vagrant", disabled: true
# OpenTripPlanner
otp.vm.network "forwarded_port", guest: 80, host: 9090
otp.ssh.forward_x11 = true
otp.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "deployment/ansible/otp.yml"
ansible.inventory_path = ANSIBLE_INVENTORY_PATH
ansible.raw_arguments = ["--timeout=60"]
end
otp.vm.provider :virtualbox do |v|
v.memory = CAC_MEMORY_MB
v.cpus = CPUS
end
end
end