Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #7246

Closed
Open
Created Jul 02, 2014 by Administrator@rootOwner

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/ruby is still 1.9.3 and we set PATH (in ~/.profile) for the git user to include ~/bin (which has a symlink ruby -> /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-shell runs w/ unmodified PATH via ssh; ruby 1.9.3 works just fine, pushing works.
  • gitlab-shell's update hook runs in the gitlab environment when committing via the web interface.
  • Because git called as /usr/bin/git prepends /usr/bin to $PATH, gitlab-shell's #!/usr/bin/env ruby is using ruby 1.9.3 instead of 2.0.
  • Because bundler passes its environment on (RUBYOPT=-rbundler/setup etc), ruby 1.9.3 tries to load bundle/setup and fails.

Temporary Solution:

  • Rename hooks/update to hooks/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_env and get the correct PATH.
  • The update hook will also load ~/.set_env and get the correct PATH.
  • 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_env should 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).]

Assignee
Assign to
Time tracking