rails + rbenv + bundler in prod with no internet or git allowed - ruby-on-rails

I have a setup in dev using rbenv with passenger and rails. In prod, I will have no internet access and not allowed to have git installed. Everything will be packaged from our local git repo and deployed via rpm. I've searched and read everything I could find, however the direction of what to use between bundle package and bundle deployment remains ambiguous to me. So here is what I am thinking of doing - please give feedback or a solution:
In dev:
install rbenv for user that will be same in prod
install ruby + bundler + passenger
put .rbenv dir in local git repo to be packaged
in rails dir, run bundle package --all
commit ./vendor/cache to git repo as part of my project
in all environments, run bundle install --local --deployment (not sure about this part goal is to have the gems, git , etc packages install to ./vender/bundle and not contact internet, but use ./vendor/cache)
gitignore ./vendor/bundle
Does this work as expected, or should I take another path?

Related

Rubymine: overcommit gem is not installed

I am working on a Ruby on Rails project that uses overcommit to perform various checks during the commit process. Everything works fine on the command line, I can commit, change branches, push and pull with no problem. However, when I try to perform the same actions in Rubymine, I get the following error:
This repository contains hooks installed by Overcommit, but the `overcommit` gem is not installed.
Install it with `gem install overcommit`.
Despite the fact that the overcommit gem is installed in the RVM gemset for this project.
My setup is as follow:
Rubymine 8.0.3
RVM 1.26.11
Ruby 2.2.3
overcommit 0.29.1
I ran into the same issue today. The problem is that Rubymine does not run in the same environment as your terminal and does not know anything about RVM, nor gems installed under RVM.
You need to install Overcommit into the system ruby environment which is most easily done by installing it under root:
$ sudo -i
$ gem install overcommit
After you do that, you should be able to make git commits in Rubymine again. However, note that Rubymine won't display Overcommit's warnings in the VCS console, nor anywhere else as the Rubymine's git plugin simply "eats" everything from STDOUT / STDERR unless Overcommit makes the git commit fail.

bundler and rvm are using different rubies

I have the gist of the difference between rvm and bundler. On my local machine, I use rvm to manage different rubies and different gemsets for those rubies. For example I have a ruby 2.1.2 with a gemset called core:
$ rvm-prompt
ruby-2.1.2#core
$ rvm gemdir
/Users/donato/.rvm/gems/ruby-2.1.2#core
$ cd /Users/donato/.rvm/gems/ruby-2.1.2#core/gems
$ ls
actionmailer-4.1.10
...
As you can see, I have a ruby 2.1.2 and a gemset core for that ruby. When I run my project, rails looks for the gems located in /Users/donato/.rvm/gems/ruby-2.1.2#core/gems. It DOES NOT look for the gems at shared/bundle. In fact, I don't even have a shared directory at my Rails root in my local machine.
So on my local machine, while bundler manages gem dependencies and adds gems if new ones found in Gemfile, it does not manage the LOCATION of the gems' installation. It installs the gems in rvm gemdir. In fact, when you run bundle install and a new gem exists in Gemfile, then bundler actually installs the gem in rvm's gem directory.
What's confusing is that this is not how it works in staging or production deploy. It appears bundler looks for gems in the location shared/bundle. So apparently in production, bundler not only wants to install the gems, but it wants to manage the location of the gems as well, and let rvm just worry about rubies, but not gem locations.
This has caused an issue for me. I am using capistrano for deployment. When I run cap staging deploy, It is installing gems in the wrong ruby.
The capistrano script runs this line:
Running /usr/local/rvm/bin/rvm ruby-2.1.2#core do bundle install
--path /var/www/mysite_staging/shared/bundle --without development test --deployment --quiet
You can see that it installs the gems in shared/bundle.
When I go to shared/bundle/ruby after a successful deployment, I see the following directory:
/shared/bundle/ruby/2.1.0
Wait a second! In my capistrano 3 script, which is using capistrano-rvm, I specified the following:
set :rvm_type, :system
set :rvm_ruby_version, 'ruby-2.1.2#core'
If it is recommended to use bundler to manage gem locations in staging and production, at shared/bundle directory, then how should I resolve this issue? Why is bundler installing gems in the wrong ruby version for this project?
so, what would you say the major the difference between your machine and the server you are deploying on?
Look at: http://bundler.io/v1.9/deploying.html
See different behaviour beween dev and deployment and also read note on capistrano.
hope this helps

Copy vendor/cache gems

I have a set of old gems I can't install from internet.
My plan is to copy what is in production server to my local environment.
gem env to know where gems are being installed.
cd to_gems_dir
there are a of of folders there,
I copied cache folder to my local machine
under vendor/cache inside project folder.
run bundle to check everything is OK.
But is not, bundler tries to install some gems, some others not. I don't know too much about bundler and gems envs, so my question is what am I doing wrong here? any other ideas to replicate remote gem set in my local machine?
This is what I did:
for file in vendor/cache/*; do gem i --local $file; done
Then all gems where installed, finally:
bundle check
The Gemfile's dependencies are satisfied

Deploying rails app on heroku

I'm learning RoR and trying to deploy my test app to heroku receiving next error:
Unresolved dependencies detected; Installing...
Using --without developmen
You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have added to the Gemfile:
* therubyracer (~> 0.9.3.beta1)
* pg
FAILED: http://devcenter.heroku.com/articles/bundler
! Heroku push rejected, failed to install gems via Bundler
Please! Help!
Have you committed your Gemfile.lock?
bundle install
git add Gemfile.lock
git commit -am "Add lock file"
git push heroku master
This error might be because you did not completely do bundle install.
First do
bundle install
Add gem 'pg' to the gem file and install the postgres gems and postgres on your local machine. If you dont want to install postgres on your local machine then add gem 'pg to production environment and run bundle install without test environment. Though heroku discourages this way of running your application. It is always better to use same database for running locally and in production. Installing postgres is pain but it is worth it.
Your ruby should be 1.9.2.
After installing all the dependencies and post gres on your machine do bundle install and add your gem file to heroku.
git add Gemfile
git add Gemfile.lock
git commit
git push heroku master

no such file to load -- .bundle/environment

I installed integrity app these days. and found some issues.
I follow this.
$ gem install bundler
$ git clone git://github.com/integrity/integrity
$ cd integrity
$ git checkout -b deploy v22
$ bundle install
$ bundle lock
$ rake db
at the end steps, I can't find and folders named ".bundle" in the integrity folder.
and the .bundle/environment.rb too.
so I was blocked there.
and btw, anybody can sent me a better way to install and config integrity app?
thank you very much
This is probably because you have a too recent version of bundler installed. Integrity v22 is not compatible with bundler > 0.9, but relies on functionality that was in removed in the subsequent version. In my case I installed bundler 0.9 before I ran bundle install:
gem install bundler --version=0.9
You might have to uninstall the newer bundler version, too.

Resources