rubygems / rfcs

RubyGems + Bundler RFCs
45 stars 40 forks source link

Running application without RubyGems/Bundler #32

Closed voxik closed 3 years ago

voxik commented 3 years ago

Bundler is on step away from being perfect and that would be when Bundler (and RubyGems) was completely from the application runtime.

Lets say we have this simple Rails Gemfile:

source 'https://rubygems.org'

ruby '3.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.2', '>= 6.1.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma'

This transforms into Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (6.1.2.1)
      actionpack (= 6.1.2.1)
      activesupport (= 6.1.2.1)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)

... snip ...

PLATFORMS
  x86_64-linux

DEPENDENCIES
  puma
  rails (~> 6.1.2, >= 6.1.2.1)
  sqlite3 (~> 1.4)

RUBY VERSION
   ruby 3.0.0p0

BUNDLED WITH
   2.2.3

But what is really needed for application runtime? Just properly initialized $LOAD_PATH. So the Gemfile.lock above could be transformed into lets say Gemfile.rb:

$LOAD_PATH.unshift('/usr/share/gems/gems/actioncable-6.1.2.1/lib')
$LOAD_PATH.unshift('/usr/share/gems/gems/actionpack-6.1.2.1/lib')
$LOAD_PATH.unshift('/usr/share/gems/gems/activesupport-6.1.2.1/lib')

... snip ...

and Bundler also preloads the libraries by default, so there could also be:

requires 'action_cable'
requires 'action_pack'
requires 'active_support'

... snip ...

This way, one could run the application later via e.g. RUBYOPT="--disable-gems -r./Gemfile.rb rails server"

deivid-rodriguez commented 3 years ago

Bundler already has this feature, through bundle install --standalone.

voxik commented 3 years ago

It sounds it might do what I proposed, but except of it, it does way more which prevents it use. Let me explain.

I have generated the application using system installed Ruby on Rails, therefore I have every required gem available on the system. I can do the following:

$ bundle install --local
Resolving dependencies...
Using rake 13.0.3

... snip ...

Bundle complete! 3 Gemfile dependencies, 44 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

But the --standalone fails:

$ bundle install --local --standalone
Could not find rake-13.0.3 in any of the sources

Apparently, tries to do something unexpected. I don't want this feature to install anything. But maybe, I should rather report this as a bug against Bundler.