problems w/ ruby != /usr/bin/ruby
Created by: obfusk
Background:
- Ubuntu 14.04 w/ GitLab 7.0 (manually installed from git).
- Ruby packages: ruby1.9.1 (1.9.3) + ruby2.0 (from ubuntu).
- GitLab says it needs ruby >= 2.0; Ubuntu also requires 1.9.3 to be installed and does not allow ruby2.0 to provide
/usr/bin/ruby. - Thus,
/usr/bin/rubyis still 1.9.3 and we setPATH(in~/.profile) for the git user to include~/bin(which has a symlinkruby -> /usr/bin/ruby2.0). - Everything seems to work just fine...
Except: when trying to commit a change to a file in the web interface, something is wrong:
ERROR -> Command failed [1]: /usr/bin/git --git-dir=/home/git/gitlab-satellites/user/repo/.git push origin master
remote: /home/git/.gem/ruby/2.0.0/gems/bundler-1.6.3/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.3.2 in any of the sources (Bundler::GemNotFound)
...
remote: from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
...
Diagnosis:
-
gitlab-shellruns w/ unmodifiedPATHvia ssh; ruby 1.9.3 works just fine, pushing works. -
gitlab-shell'supdatehook runs in the gitlab environment when committing via the web interface. - Because git called as
/usr/bin/gitprepends/usr/binto$PATH,gitlab-shell's#!/usr/bin/env rubyis using ruby 1.9.3 instead of 2.0. - Because bundler passes its environment on (
RUBYOPT=-rbundler/setupetc), ruby 1.9.3 tries to loadbundle/setupand fails.
Temporary Solution:
- Rename
hooks/updatetohooks/update.real. - New
hooks/update:
#!/bin/bash
[ -e ~/.set_env ] && . ~/.set_env
exec "$( readlink -f "$0" )".real "$@" # TODO: make portable
- Create
~/.set_env:
export PATH=/home/git/bin:/home/git/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- Prepend to
.bashrc:
[ -e ~/.set_env ] && . ~/.set_env
- Now, commands run via ssh will load
~/.set_envand get the correctPATH. - The update hook will also load
~/.set_envand get the correctPATH. - Note: when committing in the web interface, the update hook is still run via bundler, whereas when committing via ssh it is not. This discrepancy may cause problems in future. Perhaps
Bundler.with_clean_envshould be used?
The temporary solution works, but requires amongst other things modification of the gitlab-shell code, which is not ideal. So does anyone know how to solve this properly?
- Felix
[Other issues like #6575 (closed) and #3373 (closed) and #7230 (closed) seem to run into the same underlying problem(s).]