rubocop not executing from nfs folder - ruby

I have a rails project that I run inside a vm and mount the project directory through nfs. I also have a copy of the project checked out locally.
If I run rubocop on the local version of the project, everything works correctly. However if I run rubocop in the nfs mounted version i get
Could not find proper version of rubocop (0.39.0) in any of the sources
Run `bundle install` to install missing gems.
If I run bundle install from the remote directory I get
Attempting to write to `/home/deploy/ruby/2.1.0` is unsupported by your OS.
However which ruby tells me ruby is located at
/Users/user/.rvm/rubies/ruby-2.1.6/bin/ruby
So, why is it looking for gems in /home/deploy/ruby/2.1.0 when my ruby (and rubocop for that matter) is in a totally different place?

Related

How to install Serverspec in windows machine where internet is not there?

I was using serverspec in a VM where internet is available and it was so nice.
But when we need to give the script to testers they have to install it in a machine where internet is not available.
I was trying to install in a local folder in a VM where internet available then installed in test VM. But when i run Serverspec-init it says rspec is not found.
Seems some dependent gems also need to be installed before using it.
Is it not possible to install the whole bundle as one step? How to do that?
Managing gems on a server that doesn't have internet access is definitely a challenge.
One relatively-straightforward way to do what you need is to make use of the vendor/cache directory in your application and make bundle know about it when using bundle install by using the --local flag.
First, download the gem archive (.gem file extension) of the bundler gem by going to its Rubygems page and clicking the "download" link in the bottom right. You'll need to upload that file to your test server and run $ gem install bundler-1.12.15.gem from the command line.
Now you need to get the .gem archives for serverspec, its dependencies, and all of its dependencies' dependencies, and put them inside your application in the vendor/cache directory (create those with $ mkdir -p vendor/cache) if they don't exist.
Now when you deploy the application to the server, with these .gem files in vendor/cache, run bundle install --local. This will install the gems. You can see the official documentation of the --local option at the bundler docs.

RVM: Could not locate Gemfile or .bundle/ directory when running $bundle install command

I'm trying to setup RVM on my mac. When I run bundle install in an empty folder (a dummy project folder) I get the following error:
Could not locate Gemfile or .bundle/ directory
Questions:
Do I need to copy any gem files to the dummy project folder? If so, what gems, and where from?
Do I need to install anything else?
You Just need to check whether you are currently in the rails app folder (In most cases) or double check whether you have created the rails app properly.
Here I am trying to execute the command for starting the rails server,
bundle exec rails server
As you can see since I'm not in that folder it cant locate the required gem to start up the service.
And an Error pops up like below
Could not locate Gemfile or .bundle/ directory
To remove just cd into the app folder
cd YourAPPfolder
And run the required rails command again.
You are done. Voila !!
Make sure you are in the project directory before running bundle install. For example, after running rails new myapp, you will want to cd myapp before running bundle install

Portable ruby weapp on sinatra

I have a webapp running on sinatra with several gems installed.
I would like to zip it and move to another machine, but since that machine doesnt have internet connection I would like to pack all the gems (sinatra, mongoid etc) with it?
If the two machines are similar and you’re using the same Ruby implementation (and version) you could use Bundler. Create a Gemfile, add the gems your app needs to it, then run
$ bundle install
to install those gems to the local machine.
You can then run
$ bundle package
which will copy all the gems used to the vendor/cache directory in your app. After zipping up and transferring the app to the other machine run
$ bundle install --local
to install all the gems from the vendor/cache directory on the other machine.
See the docs for bundle package.

Deploying a Ruby Command Line Application that Depends on Non-Rubygems-Hosted Gems

I am attempting to deploy a small command-line application written in Ruby. Many of the gems that the application depends on are hosted on my github account. I have specified their locations in the Gemfile appropriately. When I clone the repo on the deployment machine and run bundle install from the root, all goes smoothly. I can then run the command line app (named "hippo") with bin/hippo. I would like to install the app to the system so that I do not need to patch $PATH or specify the path to the executable in order to use it.
When I run gem install /path/to/my/.gem/file, installation fails and says that it cannot resolve the dependencies to my personal gems hosted on my Github account. I gather this is because the gem install command does not read the Gemfile, only the gemspec (why on earth did the bundler people name their file Gemfile instead of BundleFile or something?), and the locations of the gems are specified in the Gemfile (there is no way to point to a github gem in a gemspec, right?). I have the same issue when I use the rake install task that comes with a bundle-scaffolded gem. However, when I run bundle exec gem install /path/to/my/gemfile then it installs OK, I guess because it sees my gems on the bundler-altered load path and decides that they are already installed. But then, when I try to run the executable, it fails because it can't find the dependencies when they are required. (Note that the executable has require bundler/setup as its first line after the shebang).
So I ask: what is a good way to deploy, with bundler, a command line application that depends on non-rubygems-hosted gems?
bundle exec sets up your load path correctly so that the gems are visible when you require bundler/setup. One option would be to always run your binary with bundle exec bin/hippo.
Something more suited to your purposes might be to run bundle install --standalone, which generates a bundle/bundler/setup.rb file within your project's directory. That file sets up load paths correctly for you, so you'd just need to do something like require_relative '../bundle/bundler/setup' from your binary instead of require 'bundler/setup'.

bundler won't run (no-deployment doesn't work)

I was fiddling around with the --deployment option on my ruby app. After that I wanted to add another gem to my app. I added it to the gemspec, and ran bundle install but the new gem didn't get installed. I deleted the vendor cache, .bundle, Gemfile.lock and tried again, and got the error I expected:
You are trying to install in deployment mode after changing
your Gemfile. Run bundle install elsewhere and add the
updated Gemfile.lock to version control.
...
I had seen this before, so I proceeded to use --no-deployment flag. For some reason though, the same error popped up again. An hour later I'm still stuck in the same place. No matter what I do, I can't get bundle install to work and install the new gem.
Is this some sort of strange error? Or bundler by design?
Pff... Somehow a .bundle config folder sneaked into my home directory, which made all repos on my machine look like deployment repos to bundler. Deleting the .bundle folder resolved the issue.
You can list the current configurations by running
bundle config list
After that, if deployment is set to true, for instance, just do
bundle config set deployment false

Resources