9

I have seen this error all over the place, but none of the solutions I have found have helped to fix the issue. I am developing a rails app locally on a Mac and have set up a droplet on DigitalOcean to push the app to. My droplet is running Ubuntu 14 and i am deploying using a Git post-receive hook. This is the hook:

#!/bin/bash

GIT_DIR=/home/xxx/yyy_production
WORK_TREE=/home/xxx/yyy
export XXX_DATABASE_USER='xxx'
export XXX_DATABASE_PASSWORD='12345'

export RAILS_ENV=production
. ~/.bashrc

while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch to production..."
        mkdir -p $WORK_TREE
        git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
        mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log

        # start deploy tasks
        cd $WORK_TREE
        bundle install
        rake db:create
        rake db:migrate
        rake assets:precompile
        sudo restart puma-manager
        sudo service nginx restart
        # end deploy tasks
        echo "Git hooks deploy complete"
    else
        echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
    fi
done

This is the output I get when I push:

Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 444 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Master ref received.  Deploying master branch to production...
remote: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2
remote: rake aborted!
remote: Bundler::RubyVersionMismatch: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2

I don't understand this at all, as I have installed ruby 2.2.2 and selected it using RVM. When I log on to the Ubuntu machine using ssh, I don't get any errors at all running bundler. Yet this is what it does when I run using my hook. I've been fighting with this for several days. Any help is greatly appreciated.

Just some additional info:

ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]

rvm info

ruby-2.2.2:

  system:
    uname:       "Linux mgots-app-01 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux"
    system:      "ubuntu/14.04/x86_64"
    bash:        "/bin/bash => GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)"
    zsh:         " => not installed"

  rvm:
    version:      "rvm 1.26.11 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "21 hours 6 minutes 30 seconds ago"
    path:         "/usr/share/rvm"

  ruby:
    interpreter:  "ruby"
    version:      "2.2.2p95"
    date:         "2015-04-13"
    platform:     "x86_64-linux"
    patchlevel:   "2015-04-13 revision 50295"
    full_version: "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]"

  homes:
    gem:          "/home/xxx/.rvm/gems/ruby-2.2.2"
    ruby:         "/usr/share/rvm/rubies/ruby-2.2.2"

  binaries:
    ruby:         "/usr/share/rvm/rubies/ruby-2.2.2/bin/ruby"
    irb:          "/usr/share/rvm/rubies/ruby-2.2.2/bin/irb"
    gem:          "/usr/share/rvm/rubies/ruby-2.2.2/bin/gem"
    rake:         "/usr/share/rvm/rubies/ruby-2.2.2/bin/rake"

  environment:
    PATH:         "/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/usr/share/rvm/rubies/ruby-2.2.2/bin:/usr/share/rvm/bin:/home/carl/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rbenv/plugins/ruby-build/bin:/home/xxx/.rbenv/shims:/home/xxx/.rbenv/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
    GEM_HOME:     "/home/xxx/.rvm/gems/ruby-2.2.2"
    GEM_PATH:     "/home/xxx/.rvm/gems/ruby-2.2.2:/home/xxx/.rvm/gems/ruby-2.2.2@global"
    MY_RUBY_HOME: "/usr/share/rvm/rubies/ruby-2.2.2"
    IRBRC:        "/usr/share/rvm/rubies/ruby-2.2.2/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

EDIT: posting further data per request

Gemfile

source 'https://rubygems.org'
ruby "2.2.2"

gem 'rails',                                '4.2.2'
gem 'pg'
gem 'bootstrap-sass',               '3.3.5.1'
gem 'sass-rails',                   '~> 5.0'
gem 'uglifier',                         '>= 1.3.0'
gem 'coffee-rails',                 '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder',                         '~> 2.0'
gem 'font-awesome-rails'
gem 'sdoc',                                 '~> 0.4.0', group: :doc
gem 'bcrypt', '~> 3.1.7'
gem 'geocoder',                         '1.2.12'

group :development, :test do
  gem 'byebug'
  gem 'web-console',                    '~> 2.0'
    gem 'spring'
end

group :production do
  gem 'puma'
  gem 'therubyracer', platforms: :ruby
end

rvm list

rvm rubies

 * ruby-2.2.1 [ x86_64 ]
=> ruby-2.2.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

~/.bashrc

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
if [[ -n "$PS1" ]]; then
  # Some code here... e.g.
  export HISTCONTROL=ignoreboth
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session
Carl
  • 1,246
  • 3
  • 21
  • 39

1 Answers1

2

On both your droplet and your mac, remove Gemfile.lock, make sure ruby -v responds with version 2.2, and do a bundle update.

These steps should reset everything. If they don't work, do a spring stop and reinstall bundler binstubs (if you use these tools).

Good luck!

Sean Huber
  • 3,945
  • 2
  • 26
  • 31
  • I am not using binstubs. I ran a stop on spring, as it installed the gem, but I don't think I'm using it. All it said was "spring is not running" so I don't think it was running before I ran the stop. I also removed the .lock file on both systems, reinstalled bundler and ran bundle update - same result – Carl Dec 14 '15 at 00:41
  • Could you please add the contents of your `Gemfile` as well as the result of running `rvm list`? – Sean Huber Dec 14 '15 at 01:24
  • Sorry for the delay; been traveling. Is the response you pasted from `rvm list` what you are seeing on your Ubuntu droplet, or your Mac? The droplet is what I'm curious to know. Could you also paste the contents of `~/.bashrc` from your droplet? If bundler is saying that you are using version 1.9.3 of ruby when you only have ruby versions 2.2+ with rvm, that suggests that rvm is not being used in the bash shell. I'm not yet certain what the problem is. This might point you in the right direction: https://rvm.io/workflow/completion – Sean Huber Dec 19 '15 at 05:30
  • One other thought - does your project have any of the following files: `.ruby-version`, `.versions-conf`, or `.rvmrc`? These files are capable of setting the ruby version and overriding environment defaults: https://rvm.io/workflow/projects – Sean Huber Dec 19 '15 at 05:35
  • First question: Yes, that is the rvm list from the droplet – Carl Dec 19 '15 at 17:39
  • Second question: I am using a .ruby-version file. That file has only this in the contents: ruby-2.2.2. I am also using a .versions.conf file (I see that you are using a dash - I can change mine. And there is no .rvmc. I will post the contents of the bashrc above – Carl Dec 19 '15 at 17:41
  • Before I post the .bashrc contents - is there a particular part of it that would be most helpful? – Carl Dec 19 '15 at 17:42
  • I have added the part of the .bashrc that I think is relevant - can you tell me if I need to post more? – Carl Dec 19 '15 at 17:44
  • I'm thinking your git hook is running as a different user. See this: http://stackoverflow.com/questions/2626964/what-user-runs-the-git-hook – Sean Huber Dec 19 '15 at 18:15
  • It doesn't look like it. I added an "echo $USER" to my post-receive hook and it gave me the username I use to login and run the same commands locally – Carl Dec 19 '15 at 21:32
  • In fact, it's the only user that I have on the machine other than root, and root does not have ssh access – Carl Dec 20 '15 at 01:15
  • Damn. Honestly I'm running short on ideas. You're getting an error from bundler saying it's running via ruby version `1.9.3`, but you don't even have that version installed via `rvm`, which appears to be set up properly. Surely your droplet has ruby 1.9.3 installed, but I'm not sure why rvm isn't overriding that default install. On your droplet, if you do `sudo su root` and then run `which ruby`, does it give you a path to a non-rvm ruby install? – Sean Huber Dec 20 '15 at 01:32
  • It looks like it - my response from which ruby is this: /usr/bin/ruby – Carl Dec 21 '15 at 00:27
  • and when I switch back to my user which ruby returns this: /usr/share/rvm/rubies/ruby-2.2.2/bin/ruby – Carl Dec 21 '15 at 00:28
  • What's the output of `cat /etc/passwd`? I suspect there is a git user. – Sean Huber Dec 21 '15 at 01:35
  • on my local machine or the droplet? – Carl Dec 21 '15 at 12:42
  • On the droplet I don't see anything called "git" but there is a user called "sshd" - not sure what that is, but thought it might be relevant – Carl Dec 21 '15 at 12:45