ericpaulbishop / redmine_git_hosting

A ChiliProject/Redmine plugin which makes configuring your own git hosting easy.
186 stars 37 forks source link

RVM Compatibility #125

Open nickgal opened 12 years ago

nickgal commented 12 years ago

When using RVM installed in single user mode there appears to be problems with PATH not being set. From what I tried to gather it appears that sudo -u -i doesn't execute ~/.profile , ~/.bashrc , ~/.bash_profile , ~/.bash_login and so on to set the RVM path.

This can be seen when doing a git push, the post-receive hook fails with a message that it is unable to find ruby.

For now I'm using a terrible workaround where I ran another script to set the RVM PATH

mv ~/.gitolite/hooks/common/post-receive ~/.gitolite/hooks/common/post-receive-real
#~/.profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
#~/.gitolite/hooks/common/post-receive

#!/bin/bash
source ~/.profile
~/.gitolite/hooks/common/post-receive-real

Sorry for the incoherent ramblings.

eins78 commented 12 years ago

i stumpled over the same problem, although it might be caused by an older system-wide rvm installation…

incorvia commented 12 years ago

I wonder if my issue is thie same? I have RVM installed and am trying to get ChiliProject working with this plugin. When I push I get the notification:

Counting objects: 7, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 334 bytes, done. Total 4 (delta 1), reused 0 (delta 0) error: cannot run hooks/post-receive: No such file or directory remote: /usr/bin/env: ruby: No such file or directory To git@server:gitolite-admin 2f50bac..a791b35 master -> master

incorvia commented 12 years ago

@nickgal I should mention that your 'work around' seemed to remove that error so thank you.

three18ti commented 12 years ago

Hello,

I too encountered this problem, but only after using this plugin for uploading a couple projects.

Indeed the workaround does work.

Using CP 3.0.0b2 ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux] Rails 2.3.14 Ubuntu 11.10, 3.0.0-15-server, x86_64 Postgres 9.1

EDIT: should be CP 3.0.0b2 sorry for the confusion.

EDIT2: I just upgraded to CP 3.0.0 and this work around does not work any more.

Additionally, I have changed my git user to a bash shell and added this to my .bashrc

#~/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

Moving on, it seems to be an issue with not using a login shell so the correct ruby path is not loaded.
It seems that pointing to the actual location of ruby (or creating a link a /usr/bin/ruby to the full path) Though, I suppose, ideally an rvm wrapper could/would do the job (better?)

Once you add the git user to the rvm group,

git@chiliproject:~$ which ruby
/usr/local/rvm/rubies/ruby-1.8.7-p357/bin/ruby

Then add that as the sha-bang line in /home/git/.gitolite/hooks/common/post-receive

#!/usr/local/rvm/rubies/ruby-1.8.7-p357/bin/ruby
EspadaV8 commented 12 years ago

I was also having this issue. Changing the #! line worked for me and seemed like the least intrusive change.

This is the output of 'env' when running the hook, as can been seen $PATH is set very oddly.

GIT_DIR=.
GL_CREATOR=NOBODY
GL_USER=redmine_asmith_1328576125_137019
GL_ADMINDIR=/home/git/.gitolite
SHELL=/bin/bash
SSH_CLIENT=172.16.3.162 65393 22
GL_RC=/home/git/.gitolite.rc
GL_TS=2012-02-07.15:06:13
USER=git
PATH=/usr/lib/git-core:/usr/lib/git-core:/usr/lib/git-core:/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
MAIL=/var/mail/git
_=/usr/bin/env
PWD=/home/git/repositories/something-awesome.git
LANG=en_AU.UTF-8
GL_REPO_BASE_ABS=/home/git/repositories
GL_LOG=/home/git/.gitolite/logs/gitolite-2012-02.log
HOME=/home/git
SHLVL=2
SSH_ORIGINAL_COMMAND=git-receive-pack 'something-awesome.git'
LOGNAME=git
SSH_CONNECTION=172.16.3.162 65393 172.16.2.97 22
GL_REPO=something-awesome
GL_BINDIR=/home/git/bin
three18ti commented 12 years ago

@EspadaV8 are you now getting the error: "post-receive" is alreay present but it's not ours!
I've described here: https://github.com/ericpaulbishop/redmine_git_hosting/issues/148

This is under the "Repository Hooks" heading on the settings page: http://chiliproject/settings/plugin/redmine_git_hosting

EspadaV8 commented 12 years ago

I am, but I don't think that'll be an issue (I didn't know about that was mentioned in the admin section).

Checking the code - https://github.com/ericpaulbishop/redmine_git_hosting/blob/master/lib/git_adapter_hooks.rb#L44 - it looks like it's just getting the MD5 hash of the file to see if it's been modified and logging a warning.

EspadaV8 commented 12 years ago

I'm not sure even if the hook is called from the plugin, I have a feeling that it's likely to be a gitolite issue.

EspadaV8 commented 12 years ago

Chatting with the #gitolite IRC room it seems that gitolite isn't doing anything with $PATH that should mess it up.

Running a few tests without having gitolite involved and I get the following env output

USER=git
SSH_CLIENT=172.16.3.162 57156 22
MAIL=/var/mail/git
GIT_DIR=.
SHLVL=1
HOME=/home/git
LOGNAME=git
_=/usr/bin/git-receive-pack
PATH=/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
LANG=en_AU.UTF-8
SHELL=/bin/bash
PWD=/home/git/repositories/something-awesome.git
SSH_CONNECTION=172.16.3.162 57156 172.16.2.97 22

This is using an SSH connection directly to a gitolite git repo. Something with the Git/SSH connection is changing $PATH

EspadaV8 commented 12 years ago

AH HA.

Because SSH isn't opening an session and is just running a command via an non-interactive shell any bashrc or profile files aren't parsed. The only file that does get read is /etc/environment, on my Ubuntu server it's contents are (can you guess)

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

Which is what is shown in my above comment, the only addition is the /usr/lib/git-core (which I'm assuming is added by git).

I should be possible to edit the /etc/environment file to include the paths that are needed, but I feel that there should be a better way to do this.

EspadaV8 commented 12 years ago

I'm pretty sure this isn't an issue with the plugin.

It might be possible to update the hook to handle rvm better, but I think that the issue lies with how RVM sets up the ruby installs.

PATH=/home/git/bin:/home/git/bin:/usr/local/rvm/gems/ruby-1.9.3-p0/bin:/usr/local/rvm/gems/ruby-1.9.3-p0@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p0/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/

A standard shell has something like that set for $PATH which comes from RVM in the profile file. This really needs to be parser when logging in via an non-interactive SSH connection too.

Failing that there should be a way to add in the RVM files into a standard $PATH location, e.g. /usr/local/bin

A minor change to @three18ti suggestion

#!/usr/local/rvm/rubies/default/bin/ruby

This should mean that if you upgrade ruby to a new version and remove the old one the script should still work (since it's using the default).

three18ti commented 12 years ago

@EspadaV8

I agree, this is the correct way to set the plugin path is with the default ruby,

#!/usr/local/rvm/rubies/default/bin/ruby

However, as long as you don't uninstall 1.8.7, my previous suggestion will not break if you install a new Ruby and change the default.

Because SSH isn't opening an session and is just running a command via an non-interactive shell any bashrc or profile files aren't parsed. The only file that does get read is /etc/environment, on

Exactly, I sort of alluded to this in my first comment,

Moving on, it seems to be an issue with not using a login shell so the correct ruby path is not loaded

But didn't really explain. Thanks for expounding on that point. (And sorry if you had to duplicate any work).

That being said, with the path set correctly, I still encounter the "post-receive" error.
I'm almost positive that the plugin "something" calls the hook, in part because of the "Run hooks asynchronously" option in the config settings, and because I see the the application call it in chiliproject/logs/production.log

Processing SettingsController#plugin (for 8.8.8.8 at 2012-02-07 13:26:35) [GET]

I'm not so sure it's the plugin any more...

Looking at the code you've identified, https://github.com/ericpaulbishop/redmine_git_hosting/blob/master/lib/git_adapter_hooks.rb#L44 this seems to not "register" the hook, because the value not set to "true".

Anyway, I stopped Apache, removed the post-receive (just renamed it), restarted Apache and visited this page and it reinstalled the hook and checks out now.

I am happy.

jehoshua02 commented 12 years ago

I had an issue with git not seeing ruby on the path because I installed ruby under chili with rvm. I solved the issue by symlinking chili's ruby under /usr/local/bin, which is in the git user's path.

https://github.com/ericpaulbishop/redmine_git_hosting/issues/150