Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby gem spring is required by command bin/rails, even in production environment #3316

Closed
nicolasfranck opened this issue Jun 1, 2023 · 2 comments

Comments

@nicolasfranck
Copy link
Contributor

Please complete the following fields as applicable:

What version of the DMPRoadmap code are you running? (e.g. v2.2.0)

4.0.1

Expected behaviour:

In a production environment environment, gems from groups like development
are typically not installed, and should not be relied on. I even add the environment variable
EXECJS_RUNTIME=Disabled to ensure that rails does not try to compile assets or start
an asset compiler.

Actual behaviour:

If you have run bundle install with the following configuration ..

bundle config without test development ci

then the rails command fails with the following error:

$ bundle exec rails server
/usr/local/bundle/gems/bundler-2.4.8/lib/bundler/rubygems_integration.rb:280:in `block (2 levels) in replace_gem': spring is not part of the bundle. Add it to your Gemfile. (Gem::LoadError)
	from /opt/roadmap/bin/spring:14:in `<top (required)>'
	from bin/rails:7:in `load'
	from bin/rails:7:in `<main>'

If I removed the lines that try to load spring, then the command works again

@benjaminfaure
Copy link
Contributor

Hello @nicolasfranck

Setting up the environment variable DISABLE_SPRING to true is supposed to solve this issue but it doesn't seem to work.

I'm sending a PR with a fix today. Could you confirm that replacing the content of bin/spring by the code below is solving this issue for you ?

#!/usr/bin/env ruby

# This file loads Spring without using loading other gems in the Gemfile, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
  require "bundler"

  Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
    Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
    gem "spring", spring.version
    require "spring/binstub"
  end
end

@nicolasfranck
Copy link
Contributor Author

yes!

nicolasfranck added a commit to DMPbelgium/roadmap that referenced this issue Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants