简体   繁体   中英

Why do I have to run bundle install every time I vagrant ssh into my vagrant box

I'm using a Vagrant file from late last year with a brand new rails project and for some reason, every time I vagrant ssh into the box, it can't find a certain gem and I have to run bundle install .

Below is my Vagrantfile, any help would be appreciated. Thanks!

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "eyefodder/precise64-utf8"
  config.vm.host_name = 'myproj'

  config.vm.network :forwarded_port, guest: 3000, host: 3000
  # config.vm.network :forwarded_port, id: 'ssh', guest: 22, host: 2222

  config.vm.synced_folder "./puppet", "/etc/puppet"
  config.vm.synced_folder 'dotfiles', '/dotfiles'
  config.vm.synced_folder '../reports', '/reports'
  config.vm.synced_folder "../", "/app", type: "rsync", rsync__exclude: [".git/", "ops/*", "reports/",  "tmp/", "log/", ".#*"]

  config.vm.provider 'virtualbox' do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
    vb.name = 'myproj'
  end

  config.vm.provision 'shell', path: 'install_apt_packages.sh'
  config.vm.provision 'shell', path: 'build_ruby_from_source.sh'
  config.vm.provision 'shell', path: 'install_puppet_modules.sh'
  config.vm.provision "puppet" do |puppet|
    puppet.module_path = 'puppet/modules'
    puppet.hiera_config_path = "puppet/hiera.yaml"
    puppet.working_directory = "/etc/puppet"
    puppet.environment_path = "puppet/environments"
    puppet.environment = "dev"
  end

  config.trigger.before [:up, :reload], :stdout => true do
    run "mkdir -p ../reports"
    run "mkdir -p ../public/uploads"
    run "sh ./setup_guest_bash_profile.sh"
  end
end

Edit

Also seems whenever I kill my rails server I have to run bundle install again in order to start it up or view a rails console

rsync is a default type with the specific property

The rsync synced folder does a one-time one-way sync from the machine running to the machine being started by Vagrant.

so the changes are not reflected (in somewhat) real time, you need to force your system to sync again the files

make the change in your Vagrantfile

  config.vm.synced_folder "../", "/app", type: "rsync", rsync__exclude: [".git/", "ops/*", "reports/",  "tmp/", "log/", ".#*"], rsync_auto: true

and then after you have vagrant up you will need to run

$ vagrant rsync-auto

so vagrant will force rsync to sync your files when there's some change. Everything should work smoothly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM