Portable ruby weapp on sinatra - ruby

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.

Related

Chef Client skip bundle install on air gapped server

I am trying to install chef recipes on air-gapped server
I bundled gems listed in all recipes and prepared vendor/cache archive. Copying it into the server and running /opt/chef/embedded/bin/bunlde install --local successfully installed 233 gems but when i run chef-client -j boot.json it finds all gems and doesn't download but still run bundle install step and tries to access rubygems.org and fails
Running chef-client in debug mode doesn't reveal any gem name, its trying to download so i don't know what's missing.
Is there anyway i can skip this step or know which gem is missing ?
Part of the run after loading the cookbooks is to install the gems required in the cookbook metadata.rb.
The client prepare a Gemfile and launch a bundle install to check if the necessary gems are installed and up to date, that's the behavior of bundler and why it tries to connect to rubygems.org.
As said in the comments, vendoring all the gems on each server is far from being efficient, you'd better have an internal gem repository and point your cient to it.
That's nearly what you did, get all gems from your recipes, install them on an internal machine and run gem server.
That can be tedious, and there's other approaches allowing to mirror rubygem internally more easily described here

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.

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

How to Install Ruby gems on all agents using TeamCity?

I am working on Teamcity 6.5.6, and looking for a way to automatically install required ruby GEMS on build agents.
For Ex: Suppose I have two gems that are required on each agent/remote (build) machine. Ex: Watir and Selenium gems. Then am I suppose to install them manually by logging on to those machines, or can I do keep them in a common library folder in SVN, and perform some tasks in Teamcity to install them if not present on machine.
If so, then What would be that task in Teamcity?
Thanks
Take a look at Bundler.
You could maintain a list of your required gems in a Gemfile, then run bundle install on each machine before the build starts. This would install all of the gems in the Gemfile (and you could lock gems to a particular version by also including the Gemfile.lock file).

Using Bundler in deployment

Pretty fundamental question but I'm trying to understand how best to use Bundler in a deployment situation.
I'm working on a Sinatra application that has about 20 dependent gems. During development, I'm using RVM with a custom gemset for the application, and I run bundle install to update the gemset in accordance with the gemfile.
When it comes to deployment (manually for now, so I can understand how it all works before using a tool like capistrano), I need to do bundle install --development right? This downloads the gems and places them in vendor/bundle.
My question is what else do I need to do? I'm using Unicorn on the server - do I just bundle exec unicorn ... and everything just works? (i.e. bundler finds the vendor directory and uses the gems from there?)
Should unicorn be a vendored gem in the application or a separate 'system' gem on the server that all applications share?
You need --deployment key, not --development: http://gembundler.com/man/bundle-install.1.html#DEPLOYMENT-MODE
On first run bundler creates config in .bundle directory. You can check it by running bundle config or just cat .bundle/config in project's directory. So bundle exec unicorn is enough since bundler knows where gems are installed. On development machine you can also install gems to arbitrary directory using --path key. For more details see manpage for bundle install (link above or bundle help install).

Resources