aboutsummaryrefslogtreecommitdiffstats
path: root/Vagrantfile
diff options
context:
space:
mode:
authorSam Pearson <sam@sgp.me.uk>2018-10-08 16:37:14 +0100
committerSam Pearson <sam@sgp.me.uk>2018-10-11 13:56:57 +0100
commitadf5b624149698a1da056b294f6ed6d85a868434 (patch)
tree8c9b5a2cfb22a8218a2479e8be282a0a0b08918a /Vagrantfile
parentedf96c8e2a0cabf4acef2b5ce7805ca0ef038b2a (diff)
[Vagrant] Improve provisioning for mySociety base box
- When using the official box, just run `script/update` at startup as the latest release (0.0.3) has everything fully pre-installed; - Ensure `/home/vagrant/.cpanm` is owned by vagant user; - When using the official box, always run the provisioner that checks and bind mounts the local pre-built Perl modules when starting as these would previously have been missing after a `halt` and `up`; - When using any other box, just run the full install process. [skip ci]
Diffstat (limited to 'Vagrantfile')
-rw-r--r--Vagrantfile66
1 files changed, 48 insertions, 18 deletions
diff --git a/Vagrantfile b/Vagrantfile
index c2faf4d6a..6873ace46 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -1,6 +1,10 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
+# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
+VAGRANTFILE_API_VERSION = "2"
+
+# Provide for a `--base-box` option to permit overriding the box used
require 'getoptlong'
opts = GetoptLong.new(
[ '--base-box', GetoptLong::OPTIONAL_ARGUMENT ]
@@ -14,23 +18,26 @@ opts.each do |opt, arg|
end
end
-$setup = <<-EOS
+# This ensures pre-built modules are available in the correct place.
+$mount_modules = <<-EOS
+ [ ! -e /home/vagrant/fixmystreet/local ] && mkdir /home/vagrant/fixmystreet/local
+ if ! mount | grep -q /home/vagrant/fixmystreet/local 2>/dev/null ; then
+ echo "Mounting pre-built perl modules from /usr/share/fixmystreet/local"
+ mount -o bind /usr/share/fixmystreet/local /home/vagrant/fixmystreet/local
+ chown -R vagrant:vagrant /home/vagrant/fixmystreet/local
+ fi
+EOS
+
+# This installs FMS from scratch, for use with non-mySociety boxes.
+$full_setup = <<-EOS
BASEBOX=$1
# To prevent "dpkg-preconfigure: unable to re-open stdin: No such file or directory" warnings
export DEBIAN_FRONTEND=noninteractive
# Make sure git submodules are checked out!
echo "Checking submodules exist/up to date"
- if [ ! "$BASEBOX" = "mysociety/fixmystreet" ]; then
- # Don't assume git is installed.
- apt-get -qq install -y git >/dev/null
- fi
+ apt-get -qq install -y git >/dev/null
cd fixmystreet
git submodule --quiet update --init --recursive --rebase
- if [ "$BASEBOX" = "mysociety/fixmystreet" ]; then
- [ ! -e /home/vagrant/fixmystreet/local ] && mkdir /home/vagrant/fixmystreet/local
- mount -o bind /usr/share/fixmystreet/local /home/vagrant/fixmystreet/local
- chown -R vagrant:vagrant /home/vagrant/fixmystreet/local
- fi
cd commonlib
git config core.worktree "../../../commonlib"
echo "gitdir: ../.git/modules/commonlib" > .git
@@ -38,7 +45,26 @@ $setup = <<-EOS
# Fetch and run install script
wget -O install-site.sh --no-verbose https://github.com/mysociety/commonlib/raw/master/bin/install-site.sh
sh install-site.sh --dev fixmystreet vagrant 127.0.0.1.xip.io
- SUCCESS=$?
+ if [ $? -eq 0 ]; then
+ touch /tmp/success
+ else
+ rm -f /tmp/success 2>/dev/null
+ fi
+EOS
+
+# This just runs our update script, used on our offical box.
+$update = <<-EOS
+ chown -R vagrant:vagrant /home/vagrant/.cpanm
+ su vagrant -c '/home/vagrant/fixmystreet/script/update ; exit $?'
+ if [ $? -eq 0 ]; then
+ touch /tmp/success
+ else
+ rm -f /tmp/success 2>/dev/null
+ fi
+EOS
+
+# This will ensure that bits of config are set right.
+$configure = <<-EOS
# Even if it failed somehow, we might as well update the port if possible
if [ -e fixmystreet/conf/general.yml ]; then
# We want to be on port 3000 for development
@@ -46,7 +72,7 @@ $setup = <<-EOS
fi
# Create a superuser for the admin
su vagrant -c 'fixmystreet/bin/createsuperuser superuser@example.org password'
- if [ $SUCCESS -eq 0 ]; then
+ if [ -e /tmp/success ]; then
# All done
echo "****************"
echo "You can now ssh into your vagrant box: vagrant ssh"
@@ -60,9 +86,6 @@ $setup = <<-EOS
fi
EOS
-# 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|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
@@ -80,11 +103,18 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder ".", "/home/vagrant/fixmystreet", :owner => "vagrant", :group => "vagrant"
- config.vm.provision "shell" do |s|
- s.inline = $setup
- s.args = "#{baseBox}"
+ # When using the mySociety box, just mount the local perl modules and run `script/update`
+ # For any other box, just run the full setup process.
+ if "#{baseBox}" == "mysociety/fixmystreet"
+ config.vm.provision "shell", run: "always", inline: $mount_modules
+ config.vm.provision "shell", run: "always", inline: $update
+ else
+ config.vm.provision "shell", inline: $full_setup
end
+ # Run the configuration steps on all boxes.
+ config.vm.provision "shell", inline: $configure
+
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"