ysbaddaden / prax

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

Prax does not use app gemsets #77

Closed kwstannard closed 10 years ago

kwstannard commented 10 years ago

It appears to use the global gemset even if you have an app specific gemset.

Steps to reproduce.

rails new testapp
cd testapp
prax link
rvm  use ruby@testapp --create --ruby-version
bundle install
rvm gemset use global
gem uninstall rake
rvm gemset use testapp
kwstannard commented 10 years ago

pull request: https://github.com/ysbaddaden/prax/pull/78

ysbaddaden commented 10 years ago

Could you switch to the unstable branch, configure RVM in ~/.praxconfig (just like you configured it in your ~/.bashrc)? It should work without requiring version-manager-specific code to be maintained in Prax :)

kwstannard commented 10 years ago

Thanks, I will give that a shot this evening.

kwstannard commented 10 years ago

If I get it working I could add something to the readme.

kwstannard commented 10 years ago

I changed to unstable and this is what I have in my .praxconfig and it still isn't working.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

Here is the log.

/home/kelly/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/gems/1.9.1/gems/bundler-1.6.0.rc2/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.1.1 in any of the sources (Bundler::GemNotFound)
kwstannard commented 10 years ago

it should be using a gemset called pricer.

kwstannard commented 10 years ago

This also doesn't work for the praxconfig. It seems to be because the present working directory at the point of it running is the home directory instead of the app directory so it isn't going to load the rvm files. Going to look into it further later.

if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then
  source "$rvm_path/scripts/rvm"
  rvm use `cat .ruby-version`@`cat .ruby-gemset`
fi
ysbaddaden commented 10 years ago

~/.praxconfig is sourced when Prax itself starts (so you may start it outside of a terminal and still have it use your default ruby). It's also sourced when starting Racker from a clean environment, in an attempt to let version managers do their job.

That being said there is #73 about the cleanup of environment variables; maybe some gems and version managers need more environment variables than the very few I let slip by (ie. almost none).

kwstannard commented 10 years ago

Great, I will probably take a second stab at this too.

Just in case you didn't have this, here is a powrc file that I got working on my mac partition today. It is a bit complex since it has backwards compatibility.

if [ -f "$rvm_path/scripts/rvm" ]; then
  source "$rvm_path/scripts/rvm"
  if [ -f ".rvmrc" ]; then
    source ".rvmrc"
  else
    if [ -f ".ruby-version" ]; then
      if [ -f ".ruby-gemset" ]; then
        rvm use `cat .ruby-version`@`cat .ruby-gemset`
      else
        rvm use `cat .ruby-version`
      fi
    fi
  fi
fi
ysbaddaden commented 10 years ago

Nice! But you must set it up for every projects, right? That's cumbersome :(

kwstannard commented 10 years ago

Yeah, maybe prax link could do something like this:

FileUtils.copy('/prax_path/premade_praxrc', '/app_path/.praxrc') unless File.exists?('/app_path/.praxrc')
MDCore commented 10 years ago

I'm on Ubuntu 13.10. I used the .praxconfig that @kwstannard provided but it didn't work. I had to add rvm_path="$HOME/.rvm/" at the top and now my apps load. Thank you, aside from that addition it was 99.9% of what I needed :)

kwstannard commented 10 years ago

@MDCore glad I could help someone. I have rvm_path set automagically somehow.

helmerj commented 10 years ago

Could some one write briefly how to set this up, which branch and what .praxconfig lines? I have tried every branch with all sorts of different configurations and it still does not work. According to the log files, my rvm ruby binary is not the first in the $PATH variable. How would I accomplish that? I modified the $PATH definition in .praxconfig but that was ignored...

MDCore commented 10 years ago

@helmerj I'm on Ubuntu 13.10. I've checked out prax to /opt/prax/ on the unstable branch.

This is my .praxconfig

echo "----"
echo "Hi! ~/.praxconfig here :)"
rvm_path="$HOME/.rvm/"
echo $rvm_path
echo $PWD
echo $HOME
echo "----"

if [ -f "$rvm_path/scripts/rvm" ]; then
  source "$rvm_path/scripts/rvm"
  if [ -f ".rvmrc" ]; then
    source ".rvmrc"
  else
    if [ -f ".ruby-version" ]; then
      if [ -f ".ruby-gemset" ]; then
        rvm use `cat .ruby-version`@`cat .ruby-gemset`
      else
        rvm use `cat .ruby-version`
      fi
    fi
  fi
fi

The important line for me was rvm_path="$HOME/.rvm/". The rest of the lines between (and including) the ---- is debug code that I just left in. Hope that helps!

helmerj commented 10 years ago

It still wont work :-(

Here is what I do (as a regular user):

  1. Unistall old prax stuff to start from scratch
  2. sudo git clone git://github.com/ysbaddaden/prax.git /opt/prax
  3. cd /opt/prax
  4. ./bin/prax install
  5. I copied the kindly provided by @MDCore content for the .praxconfig into ~/.praxconfig
  6. Using the unstable branch the permissions for ~/.prax are correct. In master they belonged to root.
  7. Execute prax link in my rails project's directory resulting in the correct link in ~/.prax

When I then restart my browser and go to http://myapp.dev (myapp replaced the correct name of my link in ~/prax) I get a DNS error and chrome cannot connect to myapp.dev. I have tried to restart the prax service and stopped the background job using prax stop && prax start which outputs the echo lines from ~/.praxconfig. There is no _log directory created in ~/.prax so I am afraid the service is actually not working at all!

Clueless on this one. :-(

MDCore commented 10 years ago

@helmerj Are you perhaps running apache? I have to sudo service apache2 stop ; sudo service prax start, because apache is seems to get port 80 first.

helmerj commented 10 years ago

@MDCore I am running nginx on port 80 actually. stopping nginx fixed it! Coolio! Thanks for your help! :-)

terlar commented 10 years ago

If you don't want to stop nginx you could still use nginx as a proxy to prax, using a config like this: https://github.com/ysbaddaden/prax/wiki/Alternate-setup#nginx

helmerj commented 10 years ago

Ever since the merge of unstable into master (release of version 0.1.0) the ~/.praxconfig file is ignored and my rvm setup does not work anymore. :-(

After a fresh install:

  1. No _socket or _log directory created in .prax
  2. no loading of ~/.praxconfig (tested with echo statements in the file)

How can I make sure the service is even running?

ysbaddaden commented 10 years ago

Please try to run Prax with PRAX_DEBUG=1 prax start --foreground, that should help debug what's happening. ~/.praxconfig is still always loaded, and the _sockets and _logs folders are lazily created (when required).

helmerj commented 10 years ago

Coolio! Ever since I started the service with the debug var and foreground flag it works again. Even without them flags. Before I had re-installed rebooted several times and it didn't. Don't know why but on't care as well. It works, that makes me happy. Thanks a lot! :-)

UPDATE:

IF I start prax outside my project's directory the command ignores my ~/.praxconfig file and I cannot start the app using myapp.dev

If I start prax inside the project's directory, the ~/.praxconfig file is read and the app can be used under myapp.dev

Don't think that is desired behavior is it?

ysbaddaden commented 10 years ago

Then nothing is fixed. This is working when run from project directory because prax will be run using RVM and your project's ruby version, which won't be the case outside (maybe it's the system ruby).

Please note that prax start is a shell script (bin/prax and libexec/prax-start) that is sourcing ~/.praxconfig, there is no ruby involved at this point, and thus your RVM config in ~/.praxconfig isn't working as expected.

Please run with the PRAX_DEBUG flag and then debug prax.log and myapp.log in ~/.prax/_logs to understand what's not working.

mattbeedle commented 10 years ago

The solution posted by @MDCore works for me. I noticed though that when I run PRAX_DEBUG=1 prax start --foreground in the project directory I see a warning about the PATH:

Warning! PATH is not properly set up, '/home/matt/.rvm/gems/ruby-2.1.2/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.1.2'.

This warning does not appear if I run the same command from any other folder

ysbaddaden commented 10 years ago

As stated in #91 maybe all that's required is to call cd $PWD instead of reimplementing RVM's logic?

zmilojko commented 10 years ago

So I tried all from #77 and #91, but the only thing that helped me in the end was:

rvm_path="$HOME/.rvm"
source "$rvm_path/scripts/rvm"
cd $PWD
rvm use ruby-2.0.0-p451

It works and I do not want to be spending (wasting?) more time on this, and @ysbaddaden - thanks a lot, Prax is really awesome, in particular for demos, but I am one more problem away from uninstalling RVM completely and just using one Ruby at the time...

ysbaddaden commented 10 years ago

I did switch to a single Ruby runtime on a fresh linux install, using my ruby-updates ubuntu ppa and Vagrant boxes for bigger projects (they usually need special software anyway). I'm still using Prax directly for small projects and for port-forwarding to the Vagrant boxes.

ysbaddaden commented 10 years ago

I'm closing the issue. Prax + RVM looks like working. I also created a [[Ruby Version Managers]] page on the Wiki.