forked from DSpace/vagrant-dspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
217 lines (180 loc) · 10.9 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
####################################
# Vagrantfile for DSpace Development
#
# WARNING: THIS IS A WORK IN PROGRESS. IT DOES NOT YET FULLY INSTALL DSPACE VIA VAGRANT!
#
# DO NOT USE IN PRODUCTION. THIS IS FOR DEVELOPMENT/TESTING PURPOSES ONLY.
#
# Currently, this config only sets up the following via Vagrant
# * Setup SSH Key Forwarding (from local machine to Vagrant VM)
# * Setup basic Git settings (email & username) on VM
# * Install Java, Maven, Ant on VM
# * Checkout DSpace source code from GitHub to VM
#
# ONLY TESTED with VirtualBox provider. Your mileage may vary with other providers
####################################
#======================================================
# QUICK SETTINGS
# Feel free to tweak for your development environment.
#======================================================
# General Settings
#------------------
# Version of Java to install on VM (valid values: 7 or 6)
java = "7"
# Virtual Box Quick Settings
# (Additional options are in the :virtualbox provider settings below.)
#--------------------------
# Name of the VM created in VirtualBox (Also the name of the subfolder in ~/VirtualBox VMs/ where this VM is normally kept)
vb_name = "dspace-dev"
# How much memory to provide to VirtualBox (in MB)
# Provide 2GB of memory by default
vb_memory = 2048
####################################
# Actual Vagrant configs
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
# BEGIN Vagrant-Cachier configuration ####################################
# check for the presence of the Vagrant-Cachier plugin before attempting
# these configurations
if Vagrant.has_plugin?('vagrant-cachier')
# Use a vagrant-cachier cache if one is detected
config.cache.auto_detect = true
# and lets specifically use the apt cache (note, this is a Debian-ism)
config.cache.enable :apt
end
# END Vagrant-Cachie configuration #######################################
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://github.com/DSpace/vagrantbox-ubuntu/releases/download/v1.1/precise64.box"
# Hostname for virtual machine
config.vm.hostname = "dspace.vagrant.dev"
# configure a private network and set this guest's IP to 192.168.50.2
config.vm.network "private_network", ip: "192.168.50.2"
# BEGIN Landrush configuration ###########################################
if Vagrant.has_plugin?('landrush')
config.landrush.enable
end
# END Landrush configuration ###########################################
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 8080 on the VM.
config.vm.network :forwarded_port, guest: 8080, host: 8080,
auto_correct: true
# If a port collision occurs (i.e. port 8080 on local machine is in use),
# then tell Vagrant to use the next available port between 8081 and 8100
config.vm.usable_port_range = 8081..8100
# name this machine
config.vm.define :dspace do |t|
end
# Turn on SSH forwarding (so that 'vagrant ssh' has access to your local SSH keys, and you can use your local SSH keys to access GitHub, etc.)
config.ssh.forward_agent = true
# THIS NEXT PART IS TOTAL HACK (only necessary for running Vagrant on Windows)
# Windows currently doesn't support SSH Forwarding when running Vagrant's "Provisioning scripts"
# (e.g. all the "config.vm.provision" commands below). Although running "vagrant ssh" (from Windows commandline)
# will work for SSH Forwarding once the VM has started up, "config.vm.provision" commands in this Vagrantfile DO NOT.
# Supposedly there's a bug in 'net-ssh' gem (used by Vagrant) which causes SSH forwarding to fail on Windows only
# See: https://github.com/mitchellh/vagrant/issues/1735
# https://github.com/mitchellh/vagrant/issues/1404
# See also underlying 'net-ssh' bug: https://github.com/net-ssh/net-ssh/issues/55
#
# Therefore, we have to "hack it" and manually sync our SSH keys to the Vagrant VM & copy them over to the 'root' user account
# (as 'root' is the account that runs all Vagrant "config.vm.provision" scripts below). This all means 'root' should be able
# to connect to GitHub as YOU! Once this Windows bug is fixed, we should be able to just remove these lines and everything
# should work via the "config.ssh.forward_agent=true" setting.
# ONLY do this hack/workaround if the local OS is Windows.
if Vagrant::Util::Platform.windows?
# MORE SECURE HACK. You MUST have a ~/.ssh/github_rsa (GitHub specific) SSH key to copy to VM
# (ensures we are not just copying all your local SSH keys to a VM)
if File.exists?(File.join(Dir.home, ".ssh", "github_rsa"))
# Read local machine's GitHub SSH Key (~/.ssh/github_rsa)
github_ssh_key = File.read(File.join(Dir.home, ".ssh", "github_rsa"))
# Copy it to VM as the /root/.ssh/id_rsa key
config.vm.provision :shell, :inline => "echo 'Windows-specific: Copying local GitHub SSH Key to VM for provisioning...' && mkdir -p /root/.ssh && echo '#{github_ssh_key}' > /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa"
else
# Else, throw a Vagrant Error. Cannot successfully startup on Windows without a GitHub SSH Key!
raise Vagrant::Errors::VagrantError, "\n\nERROR: GitHub SSH Key not found at ~/.ssh/github_rsa (required for 'vagrant-dspace' on Windows).\nYou can generate this key manually OR by installing GitHub for Windows (http://windows.github.com/)\n\n"
end
end
####
# Provisioning Scripts
# These scripts run in the order in which they appear, and setup the virtual machine (VM) for us.
####
# Create a '/etc/sudoers.d/root_ssh_agent' file which ensures sudo keeps any SSH_AUTH_SOCK settings
# This allows sudo commands (like "sudo ssh git@github.com") to have access to local SSH keys (via SSH Forwarding)
# See: https://github.com/mitchellh/vagrant/issues/1303
config.vm.provision :shell do |shell|
shell.inline = "touch $1 && chmod 0440 $1 && echo $2 > $1"
shell.args = %q{/etc/sudoers.d/root_ssh_agent "Defaults env_keep += \"SSH_AUTH_SOCK\""}
end
# Shell script to set apt sources.list to something appropriate (close to
# you, and actually up, via apt-spy2
config.vm.provision :shell, :inline => "echo ' > > > running apt-spy-2-bootstrap.sh, do not worry if it shows an error, it will be OK, there is a fallback.'"
config.vm.provision :shell, :path => "apt-spy-2-bootstrap.sh"
# Shell script to initialize latest Puppet on VM
# Borrowed from https://github.com/hashicorp/puppet-bootstrap/
config.vm.provision :shell, :path => "puppet-bootstrap-ubuntu.sh"
# This shell provisioner installs librarian-puppet and runs it to install
# puppet modules. This has to be done before the puppet provisioning so that
# the modules are available when puppet tries to parse its manifests.
config.vm.provision :shell, :path => "librarian-puppet-bootstrap.sh"
# Call our Puppet initialization script
config.vm.provision :shell, :inline => "echo ' > > > beginning puppet provisioning, this will appear to hang...'"
config.vm.provision :shell, :inline => "echo ' > > > PATIENCE! output is only shown after each step completes...'"
# display the local.yaml file, if it exists, to give us a chance to back out
# before waiting for this vagrant up to complete
if File.exists?("config/local.yaml")
config.vm.provision :shell, :inline => "echo ' > > > using the following local.yaml data, if this is not correct, control-c now...'"
config.vm.provision :shell, :inline => "echo '---BEGIN local.yaml ---' && cat /vagrant/config/local.yaml && echo '--- END local.yaml -----'"
end
config.vm.provision :puppet do |puppet|
# Set some custom "facts" for Puppet manifest(s)/modules to use.
puppet.facter = {
"vagrant" => "1",
"fqdn" => "vagrant-dspace",
"java_version" => "#{java}", # version of Java (used by 'dspace-init.pp')
}
puppet.manifests_path = "."
puppet.manifest_file = "dspace-init.pp"
puppet.module_path = "modules"
puppet.options = "--verbose"
puppet.hiera_config_path = "hiera.yaml"
end
# Check if ~/.gitconfig exists locally
# If so, copy basic Git Config settings to Vagrant VM
if File.exists?(File.join(Dir.home, ".gitconfig"))
git_name = `git config user.name` # find locally set git name
git_email = `git config user.email` # find locally set git email
# set git name for 'vagrant' user on VM
config.vm.provision :shell, :inline => "echo 'Saving local git username to VM...' && sudo -i -u vagrant git config --global user.name '#{git_name.chomp}'"
# set git email for 'vagrant' user on VM
config.vm.provision :shell, :inline => "echo 'Saving local git email to VM...' && sudo -i -u vagrant git config --global user.email '#{git_email.chomp}'"
end
if File.exists?("config/local-bootstrap.sh")
config.vm.provision :shell, :inline => "echo ' > > > running config/local_bootstrap.sh'"
config.vm.provision :shell, :path => "config/local-bootstrap.sh"
end
#############################################
# Customized provider settings for VirtualBox
# Many of these settings use VirtualBox's
# 'VBoxManage' tool: http://www.virtualbox.org/manual/ch08.html
#############################################
config.vm.provider :virtualbox do |vb|
# Name of the VM created in VirtualBox (Also the name of the subfolder in ~/VirtualBox VMs/ where this VM is kept)
vb.name = vb_name
# Use VBoxManage to provide Virtual Machine with extra memory (default is only 300MB)
vb.customize ["modifyvm", :id, "--memory", vb_memory]
# Use VBoxManage to ensure Virtual Machine only has access to 50% of host CPU
#vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
# This allows symlinks to be created within the /vagrant root directory,
# which is something librarian-puppet needs to be able to do. This might
# be enabled by default depending on what version of VirtualBox is used.
# Borrowed from https://github.com/purple52/librarian-puppet-vagrant/
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
end