Everything working fine on staging server, testing was complete. We have decided to move ahead with deploying our product in production. Heroku is decided to be our production server. We have made some changes, needed by herkou, and some other for our own foreseen benefits. Some Important changes are.
=> Added pg and unicorn gem under production group to our gem file
=> Added Procfile in root of our project to start our worker and unicorn server
=> Added some configuration file for unicorn server
=> some other changes in our environment file
code is committed and pushed to git…Herkou is up and running…yepieeee
Next day…I loged in to staging server..pull the current code on git..and restarted the staging server….BOOM…server crashed with below message.
Error message is self explainatory….”safe_yaml file is not getting loaded“. When you start your application server, It try to load all the gems and there dependency gems. So here, it is failing to load the safe_yaml gem. Well solution is simple then. just install the safe_yaml gem and it should work. But what the hell…safe_yaml gem is allready installed.
$ bundle show safe_yaml # below it list the path of the gem…thus it is allready installed
I struggled whole day…to trace back the error in the changes introduced last day…thinking staging server is fine before yesterday. Read up and down of Procfile, unicorn server and pg gem for possible clue about the error…but nothing helped. O.K…so time to follow the old saying…..🙂
“If you get LOST in your journey….go back to the place you have started”
If you read the error backtrace properly, You will always get clue….so first thing first….what is the error message…. safe_yaml file is not loading. well that, I knew from beginning. What, Iam doing wrong in my approach is linking it with pg, unicorn and Procfile added one day back, as everything fine before that. But, NO..they do not need safe_yaml. If you see the log, you will find that, actually rails_admin gem trying to load it...see line 4 of the image above.
check the path of rails_admin
$ bundle show rails_admin
So, you can see that, safe_yaml and rails_admin is installed at different location (see the bold part)and rails_admin trying to load safe_yaml relative to its current path.
In production mode, we generally use below command for bundle install which pull all the gem in vendor:
$ bundle install – -deployment # this will store all gems in vendor/bundle/ruby/version_no folder of your project.If you use simply bundle install, it will get installed in your rvm folder
The location of the the two gems get differed, due to way the rails_admin included in the gemfile and the way bundler install them.when a gem is fetched from gem source, it is installed to gems folder , and if from some specific repository, it get installed to bundler/gems folder .
Now, since I want some fixes related to jQuery of rails_admin which is present in git master branch, but not yet published as gem, I provided the git url as source of my gem
gem ‘rails_admin’, :git => “http://github.com/sferik/rails_admin.git” # bundle install command will install rails_admin to /bundler/gems folder of rvm or the vendor folder of the project, and since safe_yaml is one of its dependency, will get installed to gems folder of RVM.
SOLUTION : My problem is solved by removing the git source from the rails_admin, letting it to be fetched from the gem repository, so that both rails_admin and its dependency get installed in the same folder.
run bundle install, committed Gemfile and Gemfile.lock, pulled the code on staging server, restarted the server….huh…its UP again