Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Vagrant and Rails with shared folders on a Windows host

Julie Allinson edited this page Nov 13, 2017 · 9 revisions

The default (VirtualBox) shared folders in vagrant are slow. So trying to use shared folders for rails development in vagrant can be painful, like think waiting minutes for a small test suite to run.

NFS is much faster.

NFS isn't supported on windows. Except it is with https://github.com/winnfsd/vagrant-winnfsd

# Install
vagrant plugin install vagrant-winnfsd

# Edit Vagrantfile
# A private dhcp network is required for NFS to work (on Windows hosts, at least)
config.vm.network "private_network", type: "dhcp"

# add ', nfs:true' to each shared folder

BUT ... NFS is case-insensitive. This means that anything going into your shared folder that might depend on case-sensitivity can cause errors. For rails, this can cause errors like so:

Errno::EEXIST at / File exists @ dir_s_mkdir - tmp/cache/assets/sprockets/v3.0/Pd

This isn't likely to be a problem for files YOU create, but it will inevitably happen anywhere where lots of files are automatically created with UUIDs. Examples include sprockets files in the rails tmp directory and fcrepo files.

Solution - set the RAILS_TMP directory to be outside of the shared folder

First set ENV['RAILS_TMP'] (eg. in .env or .rbenv-vars or directly with export - however you normally set environment variables):

RAILS_TMP=/path/outside/shared/folder

Then configure this in config/application.rb or config/environments/development.rb:

  config.assets.configure do |env|
    env.cache = Sprockets::Cache::FileStore.new(
        File.join(ENV['RAILS_TMP'], 'cache/assets')
    )
  end if ENV['RAILS_TMP']

via: https://stackoverflow.com/questions/35077463/change-temporary-directory-in-rails-4

Fcrepo wrapper and Solr wrapper

The same problem can arise with Fedora's storage. Remember you can configure the location to be outside of ./tmp with .fcrepo_wrapper and .solr_wrapper and then run with the supplied configs, eg.:

fcrepo_wrapper --config ~/.fcrepo_wrapper
solr_wrapper --config ~/.solr_wrapper

Databases

I have seen problems with the db on the nfs mount.

Edit config/database.yml to relocate the development and test databases.

Testing with engine cart

I added some methods into spec/lib/generators/test_app_generator.rb to setup the RAILS_TMP variable and folder. They only run on vagrant because they check that the USER env is vagrant.

Clone this wiki locally