Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Local changed to Vagrantfile configuration #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

####################################
# Vagrantfile for DSpace Development
#
#
# WARNING: THIS IS A WORK IN PROGRESS.
#
#
# DO NOT USE IN PRODUCTION. THIS IS FOR DEVELOPMENT/TESTING PURPOSES ONLY.
#
# ONLY TESTED with VirtualBox provider. Your mileage may vary with other providers
####################################

#=====================================================================
# Load settings from our YAML configs (/config/*.yaml)
#
#
# This bit of "magic" is possible cause a Vagrantfile is just Ruby! :)
# It reads some basic configs from our 'default.yaml' and 'local.yaml'
# in order to decide how to start up the Vagrant VM.
Expand All @@ -23,6 +23,7 @@ require "yaml"
# Load up our config files
# First, load 'config/default.yaml'
CONF = YAML.load(File.open("config/default.yaml", File::RDONLY).read)
LOCAL_VAGRANT_FILE = 'Vagrantfile.local.rb'

# Next, load local overrides from 'config/local.yaml'
# If it doesn't exist, no worries. We'll just use the defaults
Expand All @@ -36,8 +37,19 @@ end
# Currently, we require Vagrant 1.6.0 or above.
Vagrant.require_version ">= 1.6.0"

has_local_vagrantfile=false
if File.exists?(LOCAL_VAGRANT_FILE)
has_local_vagrantfile=true
load LOCAL_VAGRANT_FILE
end

# Actual Vagrant configs
Vagrant.configure("2") do |config|

if has_local_vagrantfile == true
dspace_config_initialization(config)
end

# 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.
Expand Down Expand Up @@ -141,17 +153,17 @@ Vagrant.configure("2") do |config|
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"

# 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)
# 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
# (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?
Expand All @@ -165,7 +177,7 @@ Vagrant.configure("2") do |config|
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
end

# Create a '/etc/sudoers.d/root_ssh_agent' file which ensures sudo keeps any SSH_AUTH_SOCK settings
Expand All @@ -177,7 +189,7 @@ Vagrant.configure("2") do |config|
end

# Check if a test SSH connection to GitHub succeeds or fails (on every vagrant up)
# This sets a Puppet Fact named "github_ssh_status" on the VM.
# This sets a Puppet Fact named "github_ssh_status" on the VM.
# That fact is then used by 'setup.pp' to determine whether to connect to a Git Repo via SSH or HTTPS (see setup.pp)
config.vm.provision :shell, :inline => "echo 'Testing SSH connection to GitHub on VM...' && mkdir -p /etc/facter/facts.d/ && ssh -T -q -oStrictHostKeyChecking=no [email protected]; echo github_ssh_status=$? > /etc/facter/facts.d/github_ssh.txt", run: "always"

Expand Down Expand Up @@ -207,7 +219,7 @@ Vagrant.configure("2") do |config|
# Copy our 'hiera.yaml' file over to the global Puppet directory (/etc/puppet) on VM
# This lets us run 'puppet apply' manually on the VM for any minor updates or tests
config.vm.provision :shell, :inline => "cp /vagrant/hiera.yaml /etc/puppet"

# 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")
Expand Down Expand Up @@ -272,7 +284,7 @@ Vagrant.configure("2") do |config|
vb.customize ["modifyvm", :id, "--memory", CONF['vm_memory']]

vb.memory = CONF['vm_memory']
vb.cpus = CONF['vb_cpus']
vb.cpus = CONF['vb_cpus']


if CONF['vb_max_cpu']
Expand Down
42 changes: 42 additions & 0 deletions Vagrantfile.local.rb.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# This function is going to be called at the start of the configuration of the VM
# The parameter config can be used to change the configuration as if the code was inside the Vagrantfile
# You can also access the static methods of the Vagrant class

def dspace_config_initialization(config)

# Automatically install necessary plugins
required_plugins = %w(vagrant-hosts-provisioner vagrant-proxyconf vagrant-vbguest)

plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end

# Configure the forward proxy
config.proxy.http = "http://proxy.domain.com:80/"
config.proxy.https = "http://proxy.domain.com:80/"
config.proxy.no_proxy = "localhost,127.0.0.1,.domain.com"

# Create hosts file entry for the dspace machine
config.vm.provision :hostsupdate, run: 'always' do |host|
host.hostname = 'dspace.desenv.domain.com'
host.manage_guest = true
host.manage_host = true
end

# Auto update disabled due to a bug where the vagrant-vbguest plugin doesn't
# reboot after installing a new version
config.vbguest.auto_update = false

# We might have more than one VM running at the same time, and we still need
# to SSH to them, so we need a permanent port for each.
config.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: true
config.vm.network "forwarded_port", guest: 22, host: 2231, auto_correct: true

end