【发布时间】:2014-06-18 15:19:21
【问题描述】:
在我的 Gemfile 中,我根据 RAILS_ENV 指定在 git 存储库上使用哪个分支。但是,当 Capistrano 部署时,它会运行 bundle install 命令 - 由于它是通过 shell 运行的,因此未设置正确的环境(暂存)。它默认为开发并给我一个错误,指出 Gemfile.lock 与安装的内容不匹配。
您在更改您的配置后尝试在部署模式下安装 宝石文件。在别处运行
bundle install并添加更新的 Gemfile.lock 到版本控制。您已添加到 Gemfile: * 来源:git@bitbucket.org:MyRepository/manager-engine.git(开发时)
您已从 Gemfile 中删除: * 来源:git@bitbucket.org:MyRepository/manager-engine.git(在 master)
您在 Gemfile 中进行了更改: * 经理从
git@bitbucket.org:MyRepository/manager-engine.git (at develop)到no specified source
宝石文件:
RAILS_ENV = ENV['RAILS_ENV'] || 'development'
gem 'manager', git: "git@bitbucket.org:MyRepository/manager-engine.git", branch: "#{ [:production, :staging].include?(RAILS_ENV.to_sym) ? :master : :develop }"
即,如果 rails 环境不是“生产”或“暂存”,则使用“开发”分支。
部署/staging.rb:
set :branch, :master
set :keep_releases, 2
set :stage, :staging
set :rails_env, 'staging'
set :bundle_without, [:development, :test]
set :deploy_to, '/home/useraccount/rails_deployments/staging.www'
server 'localhost', user: 'useraccount', roles: %w{web app db}
所以要最简洁:
在常规 SSH 终端中,要在适当的环境下安装存储库 gem,我必须发出 RAILS_ENV=staging bundle install。否则,只需运行 bundle install 就会从开发分支安装存储库。由于 Capistrano 仅运行 bundle install 并且不包括 RAILS_ENV,因此正在发生此问题。但是Capistrano不是设置了:rails_env,还是不是真正的系统环境变量?
【问题讨论】:
标签: ruby-on-rails capistrano bundler capistrano3