How to Install Ruby gems on all agents using TeamCity? - ruby

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

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

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

Can I get Bundler to share Git-based gems across projects?

Without the gemsets provide by a tool like RVM, all gem installations are global. So if two projects use the same version of Ruby, and both have identical gemfiles, I would expect that running bundle install for the first one would install the gems, then running bundle install for the second would be able to use the already-downloaded gems to satisfy its requirements.
However, this doesn't appear the be the case with gems that are located in Github repos. For example, I have several projects with identical gem references, similar to this:
gem 'some_gem', git: 'git#github.com/me/some_gem.git', ref: 'a293bkd9d23'
Yet, although bundle install in one project clearly has to download this particular commit, it seems that bundle install in the next project repeats that process.
Bundler does not appear to store these Git-based gems in ~/.gem with my normal gems.
Where does it put them, and can I make it check for the specified commit locally before fetching from the repo again?

Resources