2017-01-02 24 views
0

我想要Bundler在Vagrant配置新VM時安裝Rails項目依賴關係。這是我目前所擁有的,但我得到這行打印==> default: Could not locate Gemfile or .bundle/ directory。該項目目錄確實包含一個Gemfile。如何在Vagrant供應時自動在項目目錄中運行Bundler?

Vagrantfile

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

VAGRANTFILE_API_VERSION = "2" 

Vagrant.require_version ">= 1.9.1" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 

    config.vm.box = "bento/ubuntu-16.04" 

    # Configurate the virtual machine to use 2GB of RAM 
    config.vm.provider :virtualbox do |vb| 
    vb.customize ["modifyvm", :id, "--memory", "2048"] 
    vb.name = "Nuggets_API_Env" 
    end 

    # Forward the Rails server default port to the host 
    config.vm.network :forwarded_port, guest: 3000, host: 3000 

    # Use Chef Solo to provision our virtual machine 
    config.vm.provision :chef_solo do |chef| 
    chef.cookbooks_path = ["cookbooks"] 

    chef.add_recipe "apt" 
    chef.add_recipe "build-essential" 
    chef.add_recipe "nodejs" 
    chef.add_recipe "openssl" 
    chef.add_recipe "ruby_build" 
    chef.add_recipe "ruby_rbenv::user" 
    chef.add_recipe "vim" 
    chef.add_recipe "postgresql::config_initdb" 
    chef.add_recipe "postgresql::server" 
    chef.add_recipe "postgresql::client" 

    chef.json = { 
     postgresql: { 
     apt_pgdg_postgresql: true, 
     version: "9.5", 
     password: { 
      postgres: "test1234", 
     } 
     }, 
     rbenv: { 
     user_installs: [{ 
      user: 'vagrant', 
      rubies: ["2.4.0"], 
      global: "2.4.0", 
      gems: { 
      "2.4.0" => [ 
       { name: "bundler" } 
      ] 
      } 
     }] 
     }, 
    } 
    end 

    config.vm.provision "shell" do |s| 
    s.path = "VM_Local_Setup.sh" 
    s.upload_path = "/vagrant/VM_Local_Setup.sh" 
    s.privileged = false 
    end 

end 

Cheffile

site "https://supermarket.getchef.com/api/v1" 

cookbook 'apt' 
cookbook 'build-essential' 
cookbook 'nodejs' 
cookbook 'openssl' 
cookbook 'postgresql' 
cookbook 'ruby_build' 
cookbook 'ruby_rbenv' 
cookbook 'vim' 

VM_Local_Setup.sh

#!/bin/bash 

sudo apt-get update 
sudo apt-get upgrade -y 
bundler install 
rbenv rehash 

回答

0

供應未在項目目錄(/流浪者)做的,這就是我的Gemfile是。

添加cd /vagrant解決此問題