ruby-on-rails - Capistrano 任务中的 bundle 配置找不到 Gemfile

标签 ruby-on-rails gem capistrano bundler

我正在尝试在 deploy.rb 中添加配置参数,以便正确构建 pg gem:

before "bundle:install" do
  run "ls -l #{fetch(:latest_release)}/Gemfile"
  run "bundle config  --local --gemfile=#{fetch(:latest_release)}/Gemfile build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config"
end

在输出中,添加的诊断代码清楚地显示了非空 Gemfile 的存在:

  * executing `bundle:install'
    triggering before callbacks for `bundle:install'
  * executing "ls -l /apps/my_app/releases/20121008195429/Gemfile"
    servers: ["my_server.com"]
    [my_server.com] executing command
 ** [out :: my_server.com] -rw-r--r-- 1 webapp webapp 1291 Oct  5 22:34 /apps/my_app/releases/20121008195429/Gemfile
    command finished in 157ms
  * executing "bundle config  --local --gemfile=/apps/my_app/releases/20121008195429/Gemfile build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config"
    servers: ["my_server.com"]
    [my_server.com] executing command
 ** [out :: my_server.com] Could not locate Gemfile

如果我使用 --global 代替 --local,我会得到相同的结果。如果我删除 global/local 标志,我会得到一个不同的错误:

** [out :: my_server.com] Invalid scope --gemfile=/apps/my_app/releases/20121008194937/Gemfile given. Please use --local or --global.

似乎有一个全局配置或上下文使情况变得困惑。如何让 bundle config 看到我的 Gemfile?有更好的方法吗?

最佳答案

bundle install 命令中使用的 --gemfile 标志相比,bundle config 中的标志仅标识 Gemfile 的名称:

# man bundle-config
...
gemfile (BUNDLE_GEMFILE)
The name of the file that bundler should use as the Gemfile. This location of this file
also sets the root of the project, which is used to resolve relative paths in the Gemfile,
among other things. By default, bundler will search up from the current working directory
until it finds a Gemfile.

我先通过 cd 到该目录解决了这个问题:

run "cd #{fetch(:latest_release)} && bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config"

更多信息: http://gembundler.com/man/bundle-install.1.html & http://gembundler.com/man/bundle-config.1.html

关于ruby-on-rails - Capistrano 任务中的 bundle 配置找不到 Gemfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12788642/

相关文章:

ruby-on-rails - 如何使用 amazon cognito 实现密码过期和密码可存档功能

ruby-on-rails - 如何在 Ruby on Rails 的自动测试中使用 native OS X 通知而不是咆哮?

ruby - 在没有 'gem unpack' 的情况下解压 ruby​​ .gem?

bash - 如何将 shell 设置为 bash 以便在 Capistrano 中运行?

ruby-on-rails - 部署 capistrano 后,Rails 4 未检测到应用程序

javascript - 为什么这个 JS 会触发部分呈现在一页上而不是另一页上的表单?

ruby - 尝试调用邪恶的向导步骤时收到名称错误

ruby-on-rails - 使用 gem 在 Rails 应用程序之间共享模型

ruby - Capistrano 中的符号字符串连接

ruby-on-rails - 在 rails 中识别创建冲突的日期