ysbaddaden / prax

Rack proxy server for development
http://ysbaddaden.github.io/prax/
Other
475 stars 49 forks source link

Not able to spawn application with bundle specific gems (unstable branch) #62

Closed terlar closed 10 years ago

terlar commented 10 years ago

I am running the unstable branch and this was working in the master one.

The debug output says the following:

I, [2014-02-04T23:34:29.565164 #4254]  INFO -- : Spawning application 'myapp' [/home/terje/Code/myapp]
D, [2014-02-04T23:34:29.565278 #4254] DEBUG -- : ["bundle", "exec", "/home/terje/.prax-dist/bin/racker", "--server", "/home/terje/.prax/_sockets/myapp.sock"]
D, [2014-02-04T23:34:59.577701 #4254] DEBUG -- : Killing myapp (4304)...

In the application specific log:

/home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.1.0 in any of the sources (Bundler::GemNotFound)
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/spec_set.rb:85:in `map!'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/spec_set.rb:85:in `materialize'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/definition.rb:133:in `specs'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/definition.rb:178:in `specs_for'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/definition.rb:167:in `requested_specs'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/environment.rb:18:in `requested_specs'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:13:in `setup'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler.rb:119:in `setup'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/setup.rb:17:in `<top (required)>'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/terje/.rubies/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

Inside the project directory:

➥ gem list | grep rake
rake (10.1.1, 0.9.2.2) 
➥ bundle | grep rake
Using rake (10.1.0) 

So bascially what happens is that it tries to look for the bundled gem, but outside of the bundle. If I install that gem version globally, then it works.

I am willing to debug and fix this if you can point me in the right direction where to look.

Right now I'm mostly looking in the lib/prax/application.rb which I figured made most of this work.

Edit: If I run this command manually from that directory it works.

bundle exec /home/terje/.prax-dist/bin/racker --server /home/terje/.prax/_sockets/kviberg.sock
ysbaddaden commented 10 years ago

Maybe it fails because of 55d49a0c0611c9fdaa2c7ab37f2e9e239e9a3d01 —bundle being ruby may need a shell environment for the ruby version manager to work correctly, or something.

I moved the bundle exec logic from Prax::Application to the racker script in branch bug/62. Does it fix the problem?

terlar commented 10 years ago

Nope, issue is still present, now I also had to add a .praxrc file to the ruby project to get the ruby version-switch working. Worked without that before.

When I debug the Prax::Application#spawn now and log PATH from env. Now it shows my default ruby version. Before it used the one done by my ruby switcher.

That's not such a big issue though, but unfortunally the bundler/gem error persists.

Any tip on how I can help solve/debug this?

ysbaddaden commented 10 years ago

This test passes for me with rbenv —bundler requires sinatra 1.0 while the globally installed one is 1.4.

The point of the spawn + shell script is to reset the environment, so ruby switchers can do their job for each application. Sourcing both chruby.sh and auto.sh in ~/.praxconfig should do the trick globally.

ysbaddaden commented 10 years ago

I tested with various applications with various ruby versions and bundler packages, and they all run great using rbenv.

terlar commented 10 years ago

Yeah, I'm using my own switcher fry which is written in fish-shell, so guess that could be the cause. Running the test suite; all tests pass except that last one. Will do some more debugging to see what's going on.

terlar commented 10 years ago

I tried not using any ruby switcher and still got the same error.

I manually set this in my .praxrc in the project directory. export PATH="/home/terje/.rubies/1.9.3-p392/bin:$PATH"

And I switched my shell to bash to rule out fish-shell troubles.

ysbaddaden commented 10 years ago

I tried to do the same: I disabled rbenv and started a clean bash shell, with exported GEM_HOME and PATH to point to my installation of ruby and the test suite passes.

Did you bundle install in test/hosts/bundler?

Here is my environment:

terlar commented 10 years ago

What's your GEM_HOME?

It still fails for me.

My environment:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2013-02-22 patchlevel 392) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /home/terje/.rubies/1.9.3-p392/bin/ruby
  - EXECUTABLE DIRECTORY: /home/terje/.rubies/1.9.3-p392/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1
     - /home/terje/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

$ echo $PATH
/home/terje/.rubies/1.9.3-p392/bin:/home/terje/.local/bin:/home/terje/.cabal/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/bin/core_perl

Running test:

$ cd .prax-dist
$ bundle exec rake test
/home/terje/.rubies/1.9.3-p392/bin/ruby -I"lib:test" -I"/home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib" "/home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb" "test/failure_test.rb" "test/microserver_test.rb" "test/microworker_test.rb" "test/proxy_test.rb" 
Run options: --seed 52779

# Running:

........F

Finished in 37.072899s, 0.2428 runs/s, 0.7283 assertions/s.

  1) Failure:
Proxy#test_0006_supports bundler with special gems [/home/terje/.prax-dist/test/proxy_test.rb:65]:
--- expected
+++ actual
@@ -1 +1,10 @@
-"1.0"
+"<html>
+  <head>
+    <title>Can't start application bundler</title>
+  </head>
+  <body>
+    <h1>Can't start application <q>bundler</q></h1>
+    <p>Please look at <code>/home/terje/.prax-dist/test/hosts/_logs/bundler.log</code> for details</p>
+  </body>
+</html>
+"

9 runs, 27 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -I"lib:test" -I"/home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib" "/home/terje/.rubies/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb" "test/failure_test.rb" "test/microserver_test.rb" "test/microworker_test.rb" "test/proxy_test.rb" ]

Tasks: TOP => test
ysbaddaden commented 10 years ago

Thanks for testing. We do have the same configuration (GEM_HOME, PATH, etc).

Is there an error reported in /home/terje/.prax-dist/test/hosts/_logs/bundler.log ?

terlar commented 10 years ago

I have found a way to reproduce it and also get it working. The current implementation is dependant on all gems being installed in the same place. I am however using the following config for bundler:

~/.bundle/config

BUNDLE_PATH: vendor/bundle
BUNDLE_BIN: ./bin

Which means gems are locally installed per project. Somehow when the bundle exec is run through prax it doesn't respect this setting.

Would still be nice to run prax with this bundler setting, since I don't like to litter the global gem-folder with projects specific gems and versions.

ysbaddaden commented 10 years ago

I merged #68 yesterday from @suan which I think should fix your problem: I'm resetting the ENV before spawning applications, so version managers aren't influenced by the ruby version Prax is running with.

The problem is that I'm resetting it so hard that not even HOME was set. Maybe that's the reason why the global bundler configuration is discarded: it's not found.

I guess more environment variables should be kept, like UID, USER, HOSTNAME, LANG, ...

terlar commented 10 years ago

Yes, it actually seems to work now. Thank you! :bow: