rails / execjs

Run JavaScript code from Ruby
MIT License
539 stars 282 forks source link

`rails server` fails using Dockerfile generated by `rails new`, bun and execjs #134

Closed SpringMT closed 1 year ago

SpringMT commented 1 year ago

I use boostrap gem with Rails 7.1 and bun . bootstrap uses execjs gem.

When I run rails s with the Dockerfile generated by rails new, the rails app fails with the following error.

/usr/local/bundle/ruby/3.2.0/gems/execjs-2.9.1/lib/execjs/runtimes.rb:68:in `autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

This error occurs because bun binary does not exist. This error can be fixed by modifying the Dockerfile as shown below.

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
+ COPY --from=build /usr/local/bun /usr/local/bun
+ ENV PATH=/usr/local/bun/bin:$PATH

This Dockerfile is generated by Rails. https://github.com/rails/rails/blob/2d271a4b901e7a7dae8ba4e5e83edfebdee278e8/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt#L88-L91

Is the modification that resolves this error acceptable to submit in the Rails?

byroot commented 1 year ago

The Rails default dockerfile assume you only need node/bun at build time. It seems you need it at runtime which is more the exception, not the rule.

It's fine for you to modify your Dockerfile. The default Dockerfile tries to cover most use cases but it's impossible to cover all use cases. I don't think this should be added to the default Dockerfile.