forked from SUSE/scf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
224 lines (194 loc) · 7.92 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
# Create port forward mappings
# These are not normally required, since all access happens on the
# 192.168.77.77 IP address
#
# config.vm.network "forwarded_port", guest: 80, host: 80
# config.vm.network "forwarded_port", guest: 443, host: 443
# config.vm.network "forwarded_port", guest: 4443, host: 4443
# config.vm.network "forwarded_port", guest: 8501, host: 8501
vm_memory = ENV.fetch('VM_MEMORY', 10 * 1024).to_i
vm_cpus = ENV.fetch('VM_CPUS', 4).to_i
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.77.77"
config.vm.provider "virtualbox" do |vb, override|
# Need to shorten the URL for Windows' sake
override.vm.box = "https://cf-opensusefs2.s3.amazonaws.com/vagrant/scf-virtualbox-v2.0.4.box"
# Customize the amount of memory on the VM:
vb.memory = vm_memory.to_s
vb.cpus = vm_cpus
# If you need to debug stuff
# vb.gui = true
vb.customize ['modifyvm', :id, '--paravirtprovider', 'minimal']
# https://github.com/mitchellh/vagrant/issues/351
override.vm.synced_folder ".fissile/.bosh", "/home/vagrant/.bosh", type: "nfs"
override.vm.synced_folder ".", "/home/vagrant/scf", type: "nfs"
end
# Currently not built for vmware_fusion
# config.vm.provider "vmware_fusion" do |vb, override|
# override.vm.box="https://cf-opensusefs2.s3.amazonaws.com/vagrant/scf-vmware-v2.0.4.box"
#
# # Customize the amount of memory on the VM:
# vb.memory = vm_memory.to_s
# vb.cpus = vm_cpus
# # If you need to debug stuff
# # vb.gui = true
#
# # `vmrun getGuestIPAddress` often returns the address of the docker0 bridge instead of eth0 :(
# vb.enable_vmrun_ip_lookup = false
#
# # Disable default synced folder
# config.vm.synced_folder ".", "/vagrant", disabled: true
#
# # Enable HGFS
# vb.vmx["isolation.tools.hgfs.disable"] = "FALSE"
#
# # Must be equal to the total number of shares
# vb.vmx["sharedFolder.maxnum"] = "2"
#
# # Configure shared folders
# VMwareHacks.configure_shares(vb)
# end
# Currently not built for vmware_workstation
# config.vm.provider "vmware_workstation" do |vb, override|
# override.vm.box="https://cf-opensusefs2.s3.amazonaws.com/vagrant/scf-vmware-v2.0.4.box"
#
# # Customize the amount of memory on the VM:
# vb.memory = vm_memory.to_s
# vb.cpus = vm_cpus
# # If you need to debug stuff
# # vb.gui = true
#
# # Disable default synced folder
# config.vm.synced_folder ".", "/vagrant", disabled: true
#
# # Enable HGFS
# vb.vmx["isolation.tools.hgfs.disable"] = "FALSE"
#
# # Must be equal to the total number of shares
# vb.vmx["sharedFolder.maxnum"] = "2"
#
# # Configure shared folders
# VMwareHacks.configure_shares(vb)
# end
config.vm.provider "libvirt" do |libvirt, override|
override.vm.box = "https://cf-opensusefs2.s3.amazonaws.com/vagrant/scf-libvirt-v2.0.4.box"
libvirt.driver = "kvm"
# Allow downloading boxes from sites with self-signed certs
libvirt.memory = vm_memory
libvirt.cpus = vm_cpus
override.vm.synced_folder ".fissile/.bosh", "/home/vagrant/.bosh", type: "nfs"
override.vm.synced_folder ".", "/home/vagrant/scf", type: "nfs"
end
# We can't run the VMware specific mounting in a provider override,
# because as documentation states, ordering is outside in:
# https://www.vagrantup.com/docs/provisioning/basic_usage.html
#
# This would mean that mounting the shared folders would always be the last
# thing done, when we need it to be the first
config.vm.provision "shell", privileged: false, inline: <<-SCRIPT
# Only run if we're on Workstation or Fusion
if sudo dmidecode -s system-product-name | grep -qi vmware; then
echo "Waiting for mounts to be available ..."
retries=1
mounts_available="no"
until [ "$mounts_available" == "yes" ] || [ "$retries" -gt 120 ]; do
sleep 1
retries=$((retries+1))
if [ -d "/mnt/hgfs/scf/src" ]; then
mounts_available="yes"
fi
done
if hash vmhgfs-fuse 2>/dev/null; then
echo "Mounts available after ${retries} seconds."
if [ ! -d "/home/vagrant/scf" ]; then
echo "Sharing directories in the VMware world ..."
mkdir -p /home/vagrant/scf
mkdir -p /home/vagrant/.bosh
sudo vmhgfs-fuse .host:scf /home/vagrant/scf -o allow_other
sudo vmhgfs-fuse .host:bosh /home/vagrant/.bosh -o allow_other
fi
else
>&2 echo "Timed out waiting for mounts load after ${retries} seconds."
exit 1
fi
fi
SCRIPT
config.vm.provision "shell", privileged: true, env: ENV.select { |e|
%w(http_proxy https_proxy no_proxy).include? e.downcase
}, inline: <<-SHELL
set -e
for var in no_proxy http_proxy https_proxy NO_PROXY HTTP_PROXY HTTPS_PROXY ; do
if test -n "${!var}" ; then
echo "${var}=${!var}" | tee -a /etc/environment
fi
done
echo Proxy setup of the host, saved ...
SHELL
# set up direnv so we can pick up fissile configuration
config.vm.provision "shell", privileged: false, inline: <<-SHELL
set -o errexit -o nounset
mkdir -p ${HOME}/bin
wget -O ${HOME}/bin/direnv --no-verbose \
https://github.com/direnv/direnv/releases/download/v2.11.3/direnv.linux-amd64
chmod a+x ${HOME}/bin/direnv
echo 'eval "$(${HOME}/bin/direnv hook bash)"' >> ${HOME}/.bashrc
ln -s ${HOME}/scf/bin/dev/vagrant-envrc ${HOME}/.envrc
${HOME}/bin/direnv allow ${HOME}
${HOME}/bin/direnv allow ${HOME}/scf
SHELL
config.vm.provision "shell", privileged: false, inline: <<-SHELL
set -e
# Get proxy configuration here
source /etc/environment
export no_proxy http_proxy https_proxy NO_PROXY HTTP_PROXY HTTPS_PROXY
# Install development tools
(
cd "${HOME}/scf"
${HOME}/bin/direnv exec ${HOME}/scf/bin/dev/install_tools.sh
)
SHELL
config.vm.provision "shell", privileged: false, inline: <<-SHELL
set -e
echo 'if test -e /mnt/hgfs ; then /mnt/hgfs/scf/bin/dev/setup_vmware_mounts.sh ; fi' >> .profile
echo 'export PATH=$PATH:/home/vagrant/scf/output/bin/' >> .profile
echo 'export PATH=$PATH:/home/vagrant/scf/container-host-files/opt/hcf/bin/' >> .profile
echo 'test -f /home/vagrant/scf/personal-setup && . /home/vagrant/scf/personal-setup' >> .profile
direnv exec /home/vagrant/scf make -C /home/vagrant/scf copy-compile-cache
echo -e "\n\nAll done - you can \e[1;96mvagrant ssh\e[0m\n\n"
SHELL
end
module VMwareHacks
# Here we manually define the shared folder for VMware-based providers
def VMwareHacks.configure_shares(vb)
current_dir = File.dirname(__FILE__)
bosh_cache = File.join(current_dir, '.fissile/.bosh')
# share . in the box
vb.vmx["sharedFolder0.present"] = "TRUE"
vb.vmx["sharedFolder0.enabled"] = "TRUE"
vb.vmx["sharedFolder0.readAccess"] = "TRUE"
vb.vmx["sharedFolder0.writeAccess"] = "TRUE"
vb.vmx["sharedFolder0.hostPath"] = current_dir
vb.vmx["sharedFolder0.guestName"] = "scf"
vb.vmx["sharedFolder0.expiration"] = "never"
vb.vmx["sharedfolder0.followSymlinks"] = "TRUE"
# share .fissile/.bosh in the box
vb.vmx["sharedFolder1.present"] = "TRUE"
vb.vmx["sharedFolder1.enabled"] = "TRUE"
vb.vmx["sharedFolder1.readAccess"] = "TRUE"
vb.vmx["sharedFolder1.writeAccess"] = "TRUE"
vb.vmx["sharedFolder1.hostPath"] = bosh_cache
vb.vmx["sharedFolder1.guestName"] = "bosh"
vb.vmx["sharedFolder1.expiration"] = "never"
vb.vmx["sharedfolder1.followSymlinks"] = "TRUE"
end
end