-
Notifications
You must be signed in to change notification settings - Fork 0
Vagrant and Rails with shared folders on a Windows host
The default (VirtualBox) shared folders in vagrant are slow. So trying to use shared folders for rails development in vagrant can be painful, 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
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 directory - 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.cache_limit = 50.megabytes
config.assets.configure do |env|
env.cache = Sprockets::Cache::FileStore.new(
File.join(ENV['RAILS_TMP'], 'cache/assets'),
config.assets.cache_limit,
env.logger
)
end
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 folders. Remember you can configure the location to be outside of ./tmp with .fcrepo_wrapper (and .solr_wrapper for solr).
Testing with engine cart
(If using .rbenv-vars) Add .rbenv-vars into spec/test_app_templates, containing
RAILS_TMP:~/tmp
Add this into your spec/lib/generators/test_app_generator.rb
def configure_tmp_directory
# Don't do this on travis
if `hostname`.include? 'localhost'
copy_file '.rbenv-vars', '.rbenv-vars'
run 'rbenv vars'
run 'mkdir ~/tmp'
injection = "\n # Relocate RAILS_TMP to ~/tmp"
injection += "\n config.assets.configure do |env|"
injection += "\n env.cache = Sprockets::Cache::FileStore.new("
injection += "\n ENV['RAILS_TMP'] + '/cache/assets',"
injection += "\n env.logger"
injection += "\n )"
injection += "\n end"
inject_into_file 'config/environments/test.rb', after: '# Settings specified here will take precedence over those in config/application.rb.' do
injection
end
inject_into_file 'config/environments/development.rb', after: '# Settings specified here will take precedence over those in config/application.rb.' do
injection
end
end
end