forked from sandstorm-io/sandstorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
executable file
·130 lines (119 loc) · 4.81 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# We base ourselves off a Debian fork of the official Debian jessie64 base box.
config.vm.box = "sandstorm/debian-jessie64"
# We forward port 6080, the Sandstorm web port, so that developers can
# visit their sandstorm app from their browser as local.sandstorm.io:6080
# (aka 127.0.0.1:6080).
config.vm.network :forwarded_port, guest: 6080, host: 6080
# Create a link-local private address, so that the host can
# use NFS with the Virtualbox guest. Virtualbox/Vagrant handles
# network address translation so outbound network requests still
# work.
config.vm.network :private_network, ip: "169.254.254.2"
# Use a shell script to "provision" the box. This installs Sandstorm using
# the bundled installer.
config.vm.provision "shell",
inline: "cd /vagrant && echo localhost > /etc/hostname && hostname localhost && sudo OVERRIDE_DEFAULT_SERVER_USER=vagrant ./install.sh -d -e > /dev/null && sudo sed --in-place='' --expression='s/^BIND_IP=.*/BIND_IP=0.0.0.0/' /opt/sandstorm/sandstorm.conf && sudo service sandstorm restart && printf '\nYour server is online. It has the dev accounts feature enabled, so anyone can log in.\n\nDetails and customization instructions are available here:\n- https://github.com/sandstorm-io/sandstorm/wiki/Using-the-Vagrantfile\n\nVisit it at:\n http://local.sandstorm.io:6080/'"
# Use NFS for the /vagrant shared directory, for performance and
# compatibility.
config.vm.synced_folder ".", "/vagrant", type: "nfs"
# Calculate the number of CPUs and the amount of RAM the system has,
# in a platform-dependent way; further logic below.
cpus = nil
total_kB_ram = nil
host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
total_kB_ram = `sysctl -n hw.memsize`.to_i / 1024
elsif host =~ /linux/
cpus = `nproc`.to_i
total_kB_ram = `grep MemTotal /proc/meminfo | awk '{print $2}'`.to_i
elsif host =~ /mingw/
# powershell may not be available on Windows XP and Vista, so wrap this in a rescue block
begin
cpus = `powershell -Command "(Get-WmiObject Win32_Processor -Property NumberOfLogicalProcessors | Select-Object -Property NumberOfLogicalProcessors | Measure-Object NumberOfLogicalProcessors -Sum).Sum"`.to_i
total_kB_ram = `powershell -Command "Get-CimInstance -class cim_physicalmemory | % {$_.Capacity}"`.to_i / 1024
rescue
end
end
# Use the same number of CPUs within Vagrant as the system, with 1
# as a default.
#
# Use at least 512MB of RAM, and if the system has more than 2GB of
# RAM, use 1/4 of the system RAM. This seems a reasonable compromise
# between having the Vagrant guest operating system not run out of
# RAM entirely (which it basically would if we went much lower than
# 512MB) and also allowing it to use up a healthily large amount of
# RAM so it can run faster on systems that can afford it.
assign_cpus = nil
assign_ram_mb = nil
if cpus.nil? or cpus.zero?
assign_cpus = 1
else
assign_cpus = cpus
end
if total_kB_ram.nil? or total_kB_ram < 2048000
assign_ram_mb = 512
else
assign_ram_mb = (total_kB_ram / 1024 / 4)
end
# Actually provide the computed CPUs/memory to the backing provider.
config.vm.provider :virtualbox do |vb|
vb.cpus = assign_cpus
vb.memory = assign_ram_mb
end
config.vm.provider :libvirt do |libvirt|
libvirt.cpus = assign_cpus
libvirt.memory = assign_ram_mb
end
end
### If you're on Windows, and you want to SMB share the
### /home/vagrant directory in the guest with your Windows
### machines, run "vagrant ssh" then do the following:
###
### sudo apt-get install samba pwgen
###
### Then sudo nano -w /etc/samba/smb.conf and make it contain the
### following, only remove the ### from the beginning of every line.
###
### [global]
### workgroup = WORKGROUP
### dns proxy = no
### bind interfaces only = no
### syslog only = yes
### syslog = 1
### server role = standalone server
### passdb backend = tdbsam
### obey pam restrictions = yes
### unix password sync = no
### pam password change = no
### map to guest = bad user
### usershare allow guests = no
###
### [vagranthome]
### comment = Vagrant home
### browseable = yes
### create mask = 0750
### directory mask = 0700
### read only = no
### valid users = vagrant
### path = /home/vagrant
###
### Then set a password for the vagrant user on Linux and enable it for
### samba use by running:
###
### pwgen -1 # generate a password
###
### sudo passwd vagrant
### sudo smbpasswd -a vagrant
###
### Then restart the VM via "vagrant reload" and visit
###
### \\169.254.254.2\vagranthome
###
### and log in with username vagrant (and password whatever
### you set above).