bundler incorrectamente tratando de instalar “desarrollo” y gemas de grupo “de prueba” en la producción
-
09-10-2019 - |
Pregunta
Tengo una pequeña aplicación web, que utiliza un montón de piedras. Algunos de ellos sólo se utilizan para entornos test
y development
. Ahora, cuando intento iniciar unicornio en el servidor de producción con el siguiente comando, falla.
unicorn_rails -E production -D -c config/unicorn.rb
El error que veo en los archivos de registro es:
Refreshing Gem list
Could not find gem 'spork (>= 0.9.0.rc2, runtime)' in any of the gem sources listed in your Gemfile.
Try running `bundle install`.
he pegado a mi Gemfile a continuación:
source 'http://rubygems.org'
gem 'rails', '3.0.1'
gem 'unicorn'
gem 'mongoid', '>= 2.0.0.beta.19'
gem 'devise'
gem 'cancan'
gem 'haml', '>= 3.0.0'
gem 'bson'
gem 'bson_ext'
gem 'formtastic'
gem 'bluecloth'
group :production do
gem 'capistrano'
end
group :development do
gem 'haml-rails'
gem 'hpricot', '0.8.2'
gem 'ruby_parser', '2.0.5'
gem 'less'
gem 'rspec-rails', '>= 2.0.1'
end
group :development,:test do
gem 'spork', '>=0.9.0.rc2'
gem 'mongoid-rspec'
end
group :test do
gem 'factory_girl_rails'
gem 'autotest'
gem 'cucumber-rails'
gem 'cucumber'
gem 'capybara'
gem 'shoulda'
gem 'database_cleaner'
gem 'test_notifier'
gem 'rspec', '2.0.1'
gem 'launchy'
end
Bündler se supone para detectar el entorno adecuado y pasar por alto las otras gemas, ¿verdad? En este momento, estoy borrando todas las líneas que no están en el grupo por defecto en el servidor para conseguir este trabajo, pero eso es un truco feo.
Solución
After a lot of digging I found the fix for this issue. All I had to do was run bundle install --without development test
before starting the server. This adds a .bundle/config
file in the rails root with the line BUNDLE_WITHOUT: test:development
. Now whenever you run bundle install
or start the server it'll ignore those groups.
The Bundler CLI allows you to specify a list of groups whose gems bundle install should not install with the --without option. To specify multiple groups to ignore, specify a list of groups separated by spaces.
bundle install --without test bundle install --without development test After running bundle install --without test, bundler will remember that you excluded the test group in the last installation. The next time you run bundle install, without any --without option, bundler will recall it.
Also, calling Bundler.setup with no parameters, or calling require "bundler/setup" will setup all groups except for the ones you excluded via --without (since they are obviously not available).
Otros consejos
In my case it was installing gems from jenkins env. So i had to set my own bundle_without variable in capistrano.
Gemfile
group :test, :development, :jenkins do
gem 'test-unit', '1.2.3'
gem 'rspec-rails'
end
deploy.rb
set :bundle_without, [:development, :test, :jenkins]
You haven't defined a production group =)