phusion / passenger-docker

Docker base images for Ruby, Python, Node.js and Meteor web apps
MIT License
2.78k stars 408 forks source link

Shebang lines are wrong #78

Closed lazywei closed 9 years ago

lazywei commented 9 years ago

Hi,

I'm using Ruby 2.2, with ruby-switch.

ruby-switch --check
Currently using: ruby2.2
------------------------

ruby    -> /usr/bin/ruby2.2
gem -> /usr/bin/gem2.2

However, when I try to bundle install from my Gemfile inside the docker, I got this:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/jruby-1.7/bin/jruby extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.

   (root) at /usr/local/jruby-1.7/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1071
   (root) at /usr/local/jruby-1.7/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
   (root) at extconf.rb:2

Gem files will remain installed in /usr/local/jruby-1.7/lib/ruby/gems/shared/gems/mysql2-0.3.17 for inspection.
Results logged to /usr/local/jruby-1.7/lib/ruby/gems/shared/gems/mysql2-0.3.17/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.17), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.17'` succeeds before bundling.

What I don't understand is I didn't switch to JRuby, so why the bundle install try to use JRuby for me?

Thanks.

FooBarWidget commented 9 years ago

Which variant of the image are you using?

lazywei commented 9 years ago

I'm using this one

FROM phusion/passenger-full:0.9.15
skyminer15 commented 9 years ago

Found the same issue with 0.9.15. Looks like ruby-switch is not handling bundler

/home/app# ruby-switch --set ruby2.2
/home/app# head -1 `which bundle`
#!/usr/bin/env jruby

Workaround

RUN rm /usr/local/bin/bundle && ln -s /var/lib/gems/2.2.0/gems/bundler-1.7.12/bin/bundle  /usr/local/bin/bundle
FooBarWidget commented 9 years ago

Looks like our build script is not correctly fixing up the shebang line.

lazywei commented 9 years ago

Got it. @skyminer15 's workaround works for me. Thanks!

Off topic By the way, it seems I can't use bundle install for non-root user? Then how can I install gems for the role app given the passenger will run my rails in that role? Thanks.

FooBarWidget commented 9 years ago

@lazywei You should bundle install to a path that you have write access to, for example bundle install --path=/home/app/bundle.

lazywei commented 9 years ago

@FooBarWidget Thanks. I'll try that.

I found that after bundle install (with @skyminer15 's workaround), it will fail with

Could not find rdoc-4.2.0 in any of the sources
Run `bundle install` to install missing gems.

when trying to run bundle exec rake db:create.

Is this also some bugs with ruby-switch?

lazywei commented 9 years ago

OK, it turns out the rake also uses jruby, we need to

rm /usr/local/bin/rake && ln -s /var/lib/gems/2.2.0/gems/rake-10.4.2/bin/rake /usr/local/bin/rake
FooBarWidget commented 9 years ago

Probably all the shebang lines are wrong in the passenger-full image. I'll have a look at this asap.

inooid commented 9 years ago

Same issue here, but I do not use ruby-switch (as far as I know). I am trying out an example app and am using this Dockerfile:

# Use phusion/passenger-full as base image. To make your builds reproducible, make
# sure you lock down to a specific version, not to `latest`!
# See https://github.com/phusion/passenger-docker/blob/master/Changelog.md for
# a list of version numbers.
FROM phusion/passenger-full:0.9.15
# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# Start Nginx / Passenger
RUN rm -f /etc/service/nginx/down

# Remove the default site
RUN rm /etc/nginx/sites-enabled/default

# Add the nginx info
ADD nginx.conf /etc/nginx/sites-enabled/webapp.conf

# Prepare folders
RUN mkdir /home/app/webapp

# Run Bundle in a cache efficient way
WORKDIR /tmp
ADD my-app/Gemfile /tmp/
ADD my-app/Gemfile.lock /tmp/
RUN bundle install

# Add the rails app
ADD . /home/app/webapp

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

It does build with the extra line from @skyminer15, but if I don't add the line, it complains about:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/jruby-1.7/bin/jruby extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.

   (root) at /usr/local/jruby-1.7/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1071
   (root) at /usr/local/jruby-1.7/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
   (root) at extconf.rb:19
FooBarWidget commented 9 years ago

This issue has been fixed now in commit 368e7ac0. You can also fix it locally by running:

sed -E -i 's|/usr/bin/env j?ruby.*$|/usr/bin/env ruby|; s|/usr/bin/j?ruby.*$|/usr/bin/env ruby|' \
    /usr/local/bin/rake /usr/local/bin/bundle /usr/local/bin/bundler