This repository has been archived by the owner on May 24, 2024. It is now read-only.
forked from Zerpet/piv-go-gpdb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Vagrantfile
101 lines (81 loc) · 2.8 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Includes
require "ipaddr"
# Developer options
@developer_mode = ENV['DEVELOPER_MODE'] || false
@go_path = ENV['GOPATH'] ||""
# EVN PIVNET DEFAULTS
@pivnet_token = ENV['UAA_API_TOKEN'] || ""
# EVN VM DEFAULTS
@vm_os = ENV['VM_OS'] || "bento/centos-7.5"
@vm_cpus = ENV['VM_CPUS'] || 2
@vm_memory = ENV['VM_MEMORY'] || 4096
# ENV APPLICATION DEFAULTS
@subnet = ENV['GO_GPDB_SUBNET'] || "192.168.99.100"
@hostname = ENV['GO_GPDB_HOSTNAME'] || "gpdb"
@segments = ENV['GO_GPDB_SEGMENTS'].to_i || 0
@standby = ENV['GO_GPDB_STANDBY'] || false
# Define a Template for Building All Our VMs.
def build_vm( config, hostname, ip )
config.vm.define hostname do |node|
node.vm.hostname = hostname
node.vm.network :private_network, :ip => ip
node.vm.provision :hosts do |provisioner|
provisioner.autoconfigure = true
provisioner.sync_hosts = true
provisioner.add_localhost_hostnames = false
end
node.vm.provider :virtualbox do |vb|
vb.name = hostname
vb.gui = false
vb.cpus = @vm_cpus
vb.memory = @vm_memory
end
end
end
# All Vagrant configuration is done below.
Vagrant.configure("2") do |config|
# Share the project folder if the developer mode is on
if (@developer_mode == 'true')
config.vm.synced_folder "#{@go_path}", "/gpdb"
end
@ip = IPAddr.new @subnet
config.vm.box = @vm_os
# If "vagrant ssh", login As gpadmin, without hacking the vagrant profile
if ARGV[0] == "ssh"
config.ssh.username = 'gpadmin'
end
# If the token is empty and we are deploying, prompt for a token...
if (@pivnet_token.to_s.empty?) && (ARGV[0] == 'up')
puts "","UAA_API_TOKEN Environment Variable Not Found..."
puts "A NULL entry will deploy, but a token is required for authentication.",""
print "UAA API TOKEN: "
@pivnet_token = STDIN.gets.chomp
end
puts "","UAA_API_TOKEN: #{@pivnet_token}"
puts "Master Hostname: #{@hostname}-m"
puts "Master IP: #{@ip}",""
# Master Node:
build_vm( config, "#{@hostname}-m", "#{@ip}" )
# Create standby host is asked
if (@standby == 'true')
@ip = @ip.succ
puts "Standby Hostname: #{@hostname}-s"
puts "Standby IP: #{@ip}",""
build_vm( config, "#{@hostname}-s", "#{@ip}")
end
if (ARGV[0] == 'up')
puts "Segments Hosts: #{@segments}"
end
# Segment Nodes:
(1..@segments).each do |i|
@ip = @ip.succ
puts "[#{i}] Segment Hostname: #{@hostname}-#{i}"
puts "[#{i}] Segment IP: #{@ip}",""
build_vm( config, "#{@hostname}-#{i}", "#{@ip}")
end
# Prepare the host that was provisioned
config.vm.provision :shell, path: 'scripts/os.prep.sh', :args => ["#{@pivnet_token}", "#{@segments}"]
config.vm.provision :shell, path: 'scripts/go.build.sh', :args => ["#{@developer_mode}"]
end