简体   繁体   English

Gemfile中用于环境的不同红宝石版本,用于Rails应用程序

[英]Different ruby versions by environment in a Gemfile for rails application

I'm currently using capistrano 3 to deploy my rails 4 application across several environments. 我目前正在使用capistrano 3在多个环境中部署rails 4应用程序。 I want to try and move to ruby 2.1.2 in development (I'm running 2.0.0 in stage / prod). 我想尝试在开发中升级到ruby 2.1.2(我在阶段/产品中运行2.0.0)。 Is it possible to somehow specify this in a single Gemfile assuming I am using rbenv? 假设我正在使用rbenv,是否可以在单个Gemfile中以某种方式指定此设置?

I've tried to following in my Gemfile but to no avail: 我尝试在我的Gemfile但无济于事:

# Gemfile
group :development do
  ruby '2.1.2'
end

group :staging, :production do
  ruby '2.0.0'
end

When cap deploy runs on development it aborts due to the perceived version mismatch. 在开发中运行cap部署时,由于感知到的版本不匹配,它会中止。

Your Ruby version is 2.1.2, but your Gemfile specified 2.0.0

Here is the command it is trying to run. 这是它试图运行的命令。

cd /home/rails/releases/20140701151045 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 RAILS_ENV=development RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

Ideas are much appreciated. 想法很受赞赏。 Thanks! 谢谢!


Update After input from @toolz and reviewing the bundler code, this just isn't possible (or a good idea). 更新从@toolz输入并检查捆绑程序代码后,这是不可能的(或一个好主意)。 There are a couple of options: 有两种选择:

  1. Remove the "ruby" entry from the Gemfile (anything goes) 从Gemfile中删除“ ruby​​”条目(一切正常)
  2. Create separate Gemfiles 创建单独的Gemfile
  3. Create a separate branch for the move to the new Ruby version 为转移到新的Ruby版本创建一个单独的分支

I'm going with option #3 and it will solve my problem and seems to be the best practice. 我要使用选项3,它将解决我的问题,并且似乎是最佳实践。

I got it working by doing 我通过做来工作

Gemfile

if ENV["RAILS_ENV"] == "development"
  ruby '2.0.0'
elsif ENV["RAILS_ENV"] == "production"
  ruby '2.1.0'
end

then assuming you're using rvm you'll have to create a capistrano task to do 然后假设您正在使用rvm,则必须创建一个capistrano任务来执行

rvm use 2.1.0

on production 生产中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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