-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
253 lines (214 loc) · 8.68 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'csv'
require 'yaml'
Vagrant.require_version ">= 2.2.0"
Vagrant.configure("2") do |config|
# ------------------
# Vagrant VM settings you can change
# ------------------
guest_user_name = "vagrant"
vm_hostname = "local-biocollect-dev"
localhost_domain = "127.0.0.1"
# Set this to your timezone so that times are easy to understand.
timezone_name = 'Australia/Brisbane'
# Ansible is used to provision the virtual machine.
# versions: https://github.com/ansible/ansible/releases
ansible_core_version = '2.16.0'
# Python is used to run ansible and for managing the apps and plugins.
# versions: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
python_version = '3.11'
# Nginx is used as a reverse proxy to provide access to apps.
# versions: https://nginx.org/en/download.html
nginx_version = '1.24.*'
# Docker is used to run containers.
# versions: https://docs.docker.com/engine/release-notes/24.0/
docker_ce_version = '5:24.0.7*'
containerd_version = '1.6*'
# versions: https://docs.docker.com/compose/release-notes/
compose_version = '2.21*'
# Nodejs container is used to populate the js from package.json files.
# versions: https://nodejs.org/en/download/
nodejs_version = '20'
# Mongo container is used as the CAS and Ecodata databases.
# versions: https://hub.docker.com/_/mongo
mongo_version = '5-focal'
# MySQL container is used as the CAS and Userdetails databases.
# versions: https://hub.docker.com/_/mysql
mysql_version = '8.0'
# Elasticsearch container is used by Ecodata for search.
# versions: https://hub.docker.com/_/elasticsearch
elasticsearch_version = '7.17.15'
# Gotenberg pdf service for creating pdf files.
# versions: https://hub.docker.com/r/gotenberg/gotenberg/tags
gotenberg_version = '7'
# Local mail server for testing mail sending.
# versions: https://hub.docker.com/r/maildev/maildev/tags
maildev_version = '2.1.0'
# Local S3-compatible server for testing S3 storage.
# versions: https://hub.docker.com/r/minio/minio/tags
minio_version = 'latest'
# the various ports in use
specified_ports = {
# services
'web_service_port': 8880,
'pdf_service_port': 8083,
'mail_service_http_port': 1080,
'mail_service_smtp_port': 1025,
'objectstore_service_main_port': 9000,
'objectstore_service_console_port': 9001,
'db_ui_service_http_port': 8080,
'mongo_ui_service_http_port': 8081,
'app_status_service_port': 8082,
'mongo_service_port': 27017,
'mysql_service_port': 3306,
'elasticsearch_service_port': 9200,
# apps
'biocollect_http_port': 8900,
'biocollect_debug_port': 5900,
'ecodata_http_port': 8901,
'ecodata_debug_port': 5901,
'cas_http_port': 8902,
'cas_debug_port': 5902,
'userdetails_http_port': 8903,
'userdetails_debug_port': 5903,
'apikey_http_port': 8904,
'apikey_debug_port': 5904,
'alerts_http_port': 8905,
'alerts_debug_port': 5905,
'theme_http_port': 8906,
}
# This refers to the Ubuntu release code name.
ubuntu_release_name = 'focal'
# architecture
vagrant_architecture = ENV['VAGRANT_ARCHITECTURE'] || "amd64"
# Find your local ubuntu mirrors here: https://launchpad.net/ubuntu/+archivemirrors
# Note that if you're using arm64, not every mirror will have the arm64 packages.
# amd64
box_amd64_name = "bento/ubuntu-20.04"
ubuntu_apt_amd64_url = "https://mirror.aarnet.edu.au/pub/ubuntu/archive"
# arm64
box_arm64_name = "bento/ubuntu-20.04-arm64"
ubuntu_apt_arm64_url = "https://mirror.aarnet.edu.au/pub/ubuntu/ports"
# Change the memory and CPU to suit your machine.
# Note that a minimal, mostly usable virtual machine requires at least 6BG and 4 CPUs to run
# CAS, Apikey, Userdetails, Ecodata, and Biocollect.
vagrant_memory = 8192 # in MB
vagrant_cpus = 6
# ------------------
# End settings you can change
# ------------------
# get the additional env vars
additional_env_vars = YAML.load_file('.local/additional-env-vars.yml')
# populate env var values from ENV
additional_env_vars.each { |key, value|
unless ENV[key]
raise "Must set env var '#{key}' (this env var is in .local/additional-env-vars.yml)."
end
additional_env_vars[key] = ENV[key]
}
# set hostname
config.vm.hostname = vm_hostname
# guest dirs
guest_home_dir = "/home/#{guest_user_name}"
guest_src_dir = "#{guest_home_dir}/src"
ansible_venv_dir = "#{guest_home_dir}/ansible-venv"
ansible_collections_dir = "#{guest_home_dir}/ansible-collections"
# guest architecture
# Set the box to use based on the architecture - Ubuntu 20.04 LTS
case vagrant_architecture
when 'arm64'
config.vm.box = box_arm64_name
ubuntu_apt_url = ubuntu_apt_arm64_url
when 'amd64'
config.vm.box = box_amd64_name
ubuntu_apt_url = ubuntu_apt_amd64_url
else
raise "Unsupported architecture '#{vagrant_architecture}'. Please set VAGRANT_ARCHITECTURE to 'arm64' or 'amd64'."
end
# provider settings for virtualbox
config.vm.provider "virtualbox" do |vb|
vb.memory = vagrant_memory
vb.cpus = vagrant_cpus
vb.linked_clone = false
vb.name = vm_hostname
end
# provider settings for vmware
config.vm.provider "vmware_desktop" do |vm|
vm.vmx["memsize"] = vagrant_memory.to_s
vm.vmx["numvcpus"] = vagrant_cpus.to_s
vm.vmx["displayname"] = vm_hostname
vm.gui = false
vm.vmx["ethernet0.pcislotnumber"] = "160"
end
# sync folder - exclude folders using rsync option
rsync_exclude_list = %w[.vagrant/ .git/ .idea/ coverage-html/ __pycache__/ .venv/ node_modules/ .gradle/ out/ target/ build/ build-cache/ coverage/ java-profiler-reports/]
config.vm.synced_folder "./..", guest_src_dir, type: "rsync", rsync__exclude: rsync_exclude_list, group: guest_user_name, owner: guest_user_name, create: true
# ensure there is a vagrant directory at the root, this is needed by some boxes
config.vm.provision "vagrant_user_dir", type: "shell", inline: <<-SHELL
if [[ ! -d "/vagrant" ]]; then
sudo mkdir -p "/vagrant"
sudo chown "#{guest_user_name}:#{guest_user_name}" "/vagrant"
fi
SHELL
# prepare to run ansible
config.vm.provision "prepare_ansible", type: "shell", path: "vm/prepare.sh",
env: {
'FILE_OWNER': guest_user_name,
'HOME_DIR': guest_home_dir,
'SRC_DIR': guest_src_dir,
'APT_URL': ubuntu_apt_url,
'ANSIBLE_VENV_DIR': ansible_venv_dir,
'ANSIBLE_COLLECTIONS_DIR': ansible_collections_dir,
'VAGRANT_ARCHITECTURE': vagrant_architecture,
'UBUNTU_RELEASE': ubuntu_release_name,
'PYTHON_VERSION': python_version,
'ANSIBLE_VERSION': ansible_core_version,
}
# run the ansible provisioning
config.vm.provision "run_ansible", type: "ansible_local" do |ans|
ans.compatibility_mode = "2.0"
ans.verbose = false
ans.install = false
ans.playbook_command = "#{ansible_venv_dir}/bin/ansible-playbook"
ans.config_file = "#{guest_src_dir}/local-biocollect-dev/vm/ansible/ansible.cfg"
ans.playbook = "#{guest_src_dir}/local-biocollect-dev/vm/ansible/playbook.yml"
ans.extra_vars = {
# core
'guest_user_name': guest_user_name,
'guest_home_dir': guest_home_dir,
'guest_src_dir': guest_src_dir,
'apt_url': ubuntu_apt_url,
'ansible_venv_dir': ansible_venv_dir,
'ansible_collections_dir': ansible_collections_dir,
'vagrant_architecture': vagrant_architecture,
'ubuntu_release': ubuntu_release_name,
'timezone_name': timezone_name,
'specified_ports': specified_ports,
'additional_env_vars': additional_env_vars,
'specified_versions': {
'ansible_core': ansible_core_version,
'python': python_version,
'nginx': nginx_version,
'nodejs': nodejs_version,
'mongo': mongo_version,
'mysql': mysql_version,
'elasticsearch': elasticsearch_version,
'docker_ce': docker_ce_version,
'containerd': containerd_version,
'compose': compose_version,
'gotenberg': gotenberg_version,
'maildev': maildev_version,
'minio': minio_version,
}
}
end
# forwarded ports - third party apps
config.vm.network "forwarded_port", guest: specified_ports[:web_service_port], host: specified_ports[:web_service_port], host_ip: localhost_domain
# forward the debug ports
specified_ports.each { |key, value|
if key.to_s.include? '_debug_'
config.vm.network "forwarded_port", guest: value, host: value, host_ip: localhost_domain
end
}
end