-
Notifications
You must be signed in to change notification settings - Fork 31
/
Vagrantfile
210 lines (178 loc) · 7.23 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 2.2"
# Install vagrant-disksize to allow resizing the services VM.
unless Vagrant.has_plugin?("vagrant-disksize")
raise Vagrant::Errors::VagrantError.new, "vagrant-disksize plugin is missing. Please install it using 'vagrant plugin install vagrant-disksize' and rerun 'vagrant up'"
end
# We need to stay on Ansible 2.8 because the version_compare filter was removed
# in 2.9.
# https://github.com/ansible/ansible/issues/64174#issuecomment-548639160
ANSIBLE_VERSION = "2.8.*"
if ["up", "provision", "status"].include?(ARGV.first)
require_relative "vagrant/ansible_galaxy_helper"
AnsibleGalaxyHelper.install_dependent_roles("deployment/ansible")
end
ANSIBLE_GROUPS = {
"app-servers" => [ "app" ],
"services" => [ "services" ],
"workers" => [ "worker" ],
"tile-servers" => [ "tiler" ]
}
if !ENV["VAGRANT_ENV"].nil? && ENV["VAGRANT_ENV"] == "TEST"
ANSIBLE_ENV_GROUPS = {
"test:children" => [
"app-servers", "services", "workers", "tile-servers"
]
}
VAGRANT_NETWORK_OPTIONS = { auto_correct: true }
else
ANSIBLE_ENV_GROUPS = {
"development:children" => [
"app-servers", "services", "workers", "tile-servers"
]
}
VAGRANT_NETWORK_OPTIONS = { auto_correct: false }
end
MMW_EXTRA_VARS = {
django_test_database: ENV["MMW_TEST_DB_NAME"] || "test_mmw",
services_ip: ENV["MMW_SERVICES_IP"] || "33.33.34.30",
tiler_host: ENV["MMW_TILER_IP"] || "33.33.34.35",
itsi_secret_key: ENV["MMW_ITSI_SECRET_KEY"],
concord_secret_key: ENV["MMW_CONCORD_SECRET_KEY"],
hydroshare_secret_key: ENV["MMW_HYDROSHARE_SECRET_KEY"],
srat_catchment_api_key: ENV["MMW_SRAT_CATCHMENT_API_KEY"],
tilecache_bucket_name: ENV["MMW_TILECACHE_BUCKET"] || "",
}
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-22.04"
config.vm.define "services" do |services|
services.vm.hostname = "services"
services.vm.network "private_network", ip: ENV["MMW_SERVICES_IP"] || "33.33.34.30"
services.disksize.size = '128GB'
# PostgreSQL
services.vm.network "forwarded_port", **{
guest: 5432,
host: 5432
}.merge(VAGRANT_NETWORK_OPTIONS)
# Redis
services.vm.network "forwarded_port", **{
guest: 6379,
host: 6379
}.merge(VAGRANT_NETWORK_OPTIONS)
services.vm.provider "virtualbox" do |v|
v.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000 ]
v.memory = 4096
v.cpus = 4
end
services.vm.provision "ansible_local" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.install_mode = "pip_args_only"
ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl https://bootstrap.pypa.io/get-pip.py | sudo python3"
ansible.pip_args = "ansible==#{ANSIBLE_VERSION}"
ansible.playbook = "deployment/ansible/services.yml"
ansible.groups = ANSIBLE_GROUPS.merge(ANSIBLE_ENV_GROUPS)
ansible.raw_arguments = ["--timeout=60"]
ansible.extra_vars = MMW_EXTRA_VARS
end
services.vm.provision "shell", path: "scripts/resize-disk.sh"
end
config.vm.define "worker" do |worker|
worker.vm.hostname = "worker"
worker.vm.network "private_network", ip: ENV["MMW_WORKER_IP"] || "33.33.34.20"
worker.vm.synced_folder "src/mmw", "/opt/app"
# Facilitates the sharing of Django media root directories across virtual machines.
worker.vm.synced_folder ".vagrant/machines/app/virtualbox/media", "/tmp/media",
create: true
# Path to RWD data (ex. /media/passport/rwd-nhd)
worker.vm.synced_folder ENV["RWD_DATA"] || "/tmp", "/opt/rwd-data"
# AWS
worker.vm.synced_folder "~/.aws", "/var/lib/mmw/.aws"
# Docker
worker.vm.network "forwarded_port", **{
guest: 2375,
host: 2375
}.merge(VAGRANT_NETWORK_OPTIONS)
# Geoprocessing Service
worker.vm.network "forwarded_port", **{
guest: 8090,
host: 8090
}.merge(VAGRANT_NETWORK_OPTIONS)
worker.vm.provider "virtualbox" do |v|
v.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000 ]
v.memory = 2048
v.cpus = 2
end
worker.vm.provision "ansible_local" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.install_mode = "pip_args_only"
ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl https://bootstrap.pypa.io/get-pip.py | sudo python3"
ansible.pip_args = "ansible==#{ANSIBLE_VERSION}"
ansible.playbook = "deployment/ansible/workers.yml"
ansible.groups = ANSIBLE_GROUPS.merge(ANSIBLE_ENV_GROUPS)
ansible.raw_arguments = ["--timeout=60"]
ansible.extra_vars = MMW_EXTRA_VARS
end
end
config.vm.define "app" do |app|
app.vm.hostname = "app"
app.vm.network "private_network", ip: ENV["MMW_APP_IP"] || "33.33.34.10"
app.vm.synced_folder "src/mmw", "/opt/app"
# Facilitates the sharing of Django media root directories across virtual machines.
app.vm.synced_folder ".vagrant/machines/app/virtualbox/media", "/var/www/mmw/media",
create: true, mount_options: ["dmode=777"]
# Django via Nginx/Gunicorn
app.vm.network "forwarded_port", **{
guest: 80,
host: 8000
}.merge(VAGRANT_NETWORK_OPTIONS)
# Livereload server
app.vm.network "forwarded_port", **{
guest: 35729,
host: 35729,
}.merge(VAGRANT_NETWORK_OPTIONS)
# Testem server
app.vm.network "forwarded_port", **{
guest: 7357,
host: 7357
}.merge(VAGRANT_NETWORK_OPTIONS)
app.ssh.forward_x11 = true
app.vm.provider "virtualbox" do |v|
v.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000 ]
v.memory = 2048
end
app.vm.provision "ansible_local" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.install_mode = "pip_args_only"
ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl https://bootstrap.pypa.io/get-pip.py | sudo python3"
ansible.pip_args = "ansible==#{ANSIBLE_VERSION}"
ansible.playbook = "deployment/ansible/app-servers.yml"
ansible.groups = ANSIBLE_GROUPS.merge(ANSIBLE_ENV_GROUPS)
ansible.raw_arguments = ["--timeout=60"]
ansible.extra_vars = MMW_EXTRA_VARS
end
end
config.vm.define "tiler" do |tiler|
tiler.vm.hostname = "tiler"
tiler.vm.network "private_network", ip: ENV["MMW_TILER_IP"] || "33.33.34.35"
tiler.vm.synced_folder "src/tiler", "/opt/tiler"
# Expose the tiler. Tiler is served by Nginx.
tiler.vm.network "forwarded_port", **{
guest: 80,
host: 4000
}.merge(VAGRANT_NETWORK_OPTIONS)
tiler.vm.provider "virtualbox" do |v|
v.memory = 1024
end
tiler.vm.provision "ansible_local" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.install_mode = "pip_args_only"
ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl https://bootstrap.pypa.io/get-pip.py | sudo python3"
ansible.pip_args = "ansible==#{ANSIBLE_VERSION}"
ansible.playbook = "deployment/ansible/tile-servers.yml"
ansible.groups = ANSIBLE_GROUPS.merge(ANSIBLE_ENV_GROUPS)
ansible.raw_arguments = ["--timeout=60"]
ansible.extra_vars = MMW_EXTRA_VARS
end
end
end