当 Vagrant 正在配置时,如何在项目目录中自动运行 Bundler



我想让 Bundler 在 Vagrant 配置新 VM 时安装 Rails 项目依赖项。这是我目前拥有的,但我==> default: Could not locate Gemfile or .bundle/ directory打印了这一行.项目目录包含 Gemfile。

流浪者档案

# -*- 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

厨师文件

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

配置不是在项目目录 (/vagrant) 中完成的,这就是我的 Gemfile 所在的地方。

添加cd /vagrant可以解决此问题

相关内容

最新更新