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

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.

Related

rubocop not executing from nfs folder

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?

Bundler: ensure production gems installed system-wide?

I have a ruby program in my git repo, used by a team. It's executed directly out of the git repo. I don't want all the team members to have to deal with gems, so I want the production-level gems to be installed system-wide (on shared disk). Bundler will use the git-controlled Gemfile.lock to decide which gems to pick up.
For development, I often install gems using --user-install.
Problem: I might accidentally push changes that use gems which are only user-installed, which will break other team members when they pull and try to run.
How can I ensure that all non-development gems are installed system-wide?
Is there a bundle command I can run that will detect this and throw an error? Or can I somehow get my cucumber tests to run using only system gems?
There is no way to get Bundler to use System gems, though I think there should be: https://github.com/bundler/bundler/issues/1964
The most straightforward solution for you would be to package the gems into your Git repo: http://bundler.io/v1.12/bundle_package.html.
This is really how the bundler team recommend that it should be run in a case where you want a user to be able to run your app without having to install gems locally.
A second option would be for you to use the --path option to bundle install and point that to a shared location visible to all your users. This option is remembered, so check .bundle into your Git repo and then your users would use the same configuration and reference the same location when they run bundle. Since all of the gems would already be installed there by you, they would have no problems.

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.

How do I list required gems for my system, so they are installed automatically when deploying it?

I am new to Ruby but I really enjoyed it.
I used Aptana Studio 3 as an IDE, but I feel it lacks support (even though I installed the undle). When I created a Ruby project, there were no files inside it.
I added a test.rb file and started playing with it.
Now I hav a simple project in which I needed to install some gems. To do so I opened the CMD, navigated to my project's folder and issued the command "gem install xxxx". On my test.rb I include the gems using require 'xxxx'.
What is the best practice to add gems?
If I ever wanted to deploy this application, I would need to add the gems to my production server. Is there any way I can list the required gems so that the server intalls it automatically when I run deploy the application?
thanks!
Put them in a Gemfile, it is used to manage the gem required by an application.
http://bundler.io/v1.3/gemfile.html
It might depend on where you are deploying to but I like to use Capistrano for deployment. Capistrano will install the gems for you by running bundler which reads your Gemfile.
Also checkout bundler. It will read your Gemfile (create one if you don't have one). To install your gems it is as simple as:
$ bundle install

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'.

Resources