I previously shared my experience using PuPHPet to host a Linux VM on my Windows computer for MEAN stack development. Since then I’ve made some improvements to the startup script I use to overcome Windows’s 260 character path limit, which npm and bower easily exceed.
Here’s the latest script (and another nod to the GitHub discussion that started it):
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 |
#!/bin/bash BASE_FOLDER="/var/tmp/windows-path-limit-fix/" create() { # Generate a unique but predictable directory by hashing the folder mount point # From http://stackoverflow.com/a/1602389 name=`echo $1 | md5sum | cut -f1 -d" "` destination="$BASE_FOLDER$name" # Skip setup if the folder already exists if [ ! -d "$destination" ]; then echo "Creating mount destination: $destination" eval "mkdir -p $destination" eval "chown -R www-data:www-data $destination" eval "chmod 775 $destination" fi if [ -d "$1" ]; then echo "Transferring files from $1 to $destination" rsync -Lr --inplace $1/ $destination/ else echo "Creating mount target: $1" eval "mkdir -p $1" fi echo "mounting $destination at $1" eval "mount -o bind $destination $1" } if [ ! "$1" -o -z "$1" ]; then echo "You must specify a folder mount point (recommend an absolute path)" else create $1 fi |
And the updated method for calling it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
config.vm.provision :shell, :path => 'puphpet/shell/install-ruby.sh' config.vm.provision :shell, :path => 'puphpet/shell/install-puppet.sh' config.vm.provision :shell, run: 'always' do |s| s.path = 'puphpet/shell/windows-path-limit-fix.sh' s.args = '/vagrant/node_modules' end config.vm.provision :shell, run: 'always' do |s| s.path = 'puphpet/shell/windows-path-limit-fix.sh' s.args = '/vagrant/.bower-tmp' end config.vm.provision :puppet do |puppet| puppet.facter = { 'ssh_username' => "#{ssh_username}", 'provisioner_type' => ENV['VAGRANT_DEFAULT_PROVIDER'], 'vm_target_key' => 'vagrantfile-local', } |
While the old script got the job done, it had many inconveniences. The new version makes several improvements:
- Temporary files are stored in /var/tmp instead of /tmp , meaning they persist after the VM is restarted.
- Building on that, the temporary directory name is now a hash of the mount point instead of choosing a new name every time. This allows us to detect when the directory is already present then remount it.
- The updated provisioner syntax in the Vagrantfile causes the script to run during vagrant reload in addition to the usual vagrant up .
These updates avoid repeated setup of the mounted directories. No more npm install after every reload!