This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
68 lines (61 loc) · 2.22 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
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'vagrant-multi/web_server'
require 'erb'
APP_PORT = 45678
NETWORK_MASK = 24
NETWORK = IPAddr.new('192.168.42.0').mask(NETWORK_MASK)
ENTRY_POINT = NETWORK | IPAddr.new('0.0.0.2')
WEB_SERVERS = VagrantMulti::WebServer.all(count: 3, network: NETWORK, offset: 20, port: APP_PORT)
DB_HOST = NETWORK | IPAddr.new('0.0.0.3')
DB_NAME = 'journaldb'
DB_USER = 'journal-web'
DB_PASSWORD = 'UmpBrgnyOCUOAq9B'
DB_URL = "postgres://#{DB_USER}:#{DB_PASSWORD}@#{DB_HOST}/#{DB_NAME}"
COMMITTISH='master'
def generate_haproxy_config(b = binding)
ERB.new(File.read(File.join(__dir__, 'templates', 'haproxy.cfg.erb')), 0, "%<>").result(b)
end
Vagrant.configure('2') do |config|
config.vm.box = "gyptazy/ubuntu22.04-arm64"
config.vm.provision 'shell', inline: 'ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime'
config.vm.define 'db' do |cfg|
cfg.vm.hostname = 'db'
cfg.vm.network 'private_network', ip: DB_HOST.to_s
cfg.vm.provision 'shell',
path: 'provisioning/install-database',
privileged: true,
env: {
DB_NAME: DB_NAME,
DB_PASSWORD: DB_PASSWORD,
DB_USER: DB_USER,
TRUSTED_NETWORK: "#{NETWORK}/#{NETWORK_MASK}"
}
cfg.vm.post_up_message = "The database is available at #{DB_URL}"
end
WEB_SERVERS.each do |server|
config.vm.define server.name do |cfg|
cfg.vm.hostname = server.name
cfg.vm.network 'private_network', ip: server.ip.to_s
cfg.vm.provision 'shell',
path: 'provisioning/deploy-app',
privileged: false,
env: {
APP_PORT: APP_PORT,
DB_URL: DB_URL,
COMMITTISH: COMMITTISH,
}
cfg.vm.post_up_message = "Application server #{cfg.vm.hostname} is available at #{server.url}."
end
end
config.vm.define 'lb' do |cfg|
cfg.vm.hostname = 'lb'
cfg.vm.network 'private_network', ip: ENTRY_POINT.to_s
cfg.vm.provision 'shell', inline: <<~SCRIPT
export DEBIAN_FRONTEND=noninteractive
apt-get --yes install curl haproxy
echo "#{generate_haproxy_config}" > /etc/haproxy/haproxy.cfg
service haproxy reload
SCRIPT
cfg.vm.post_up_message = "The load balancer is available at http://#{ENTRY_POINT}"
end
end