Ruby gem common deployement for all apps - ruby-on-rails

I am trying to deploy APM solution provided by scout app. Scout apm documentation says I need to install a gem in all the applications I am running on the server. I have multiple applications running on single server. All my ruby applications are located at /var/www. Is there a way I can deploy that apm gem in one place and then it can be used for all the services. so that I don't need to add it in each application Gemfile and its config file in config folder. I know I can achieve it using a shell script however problem with that approach is all the apps have their own git repo which would be administrative overhead for me.

No, you have to add gems that you want to use in an application to the Gemfile. Because if you do not add that gem to an application's Gemfile then the application will simply not load that gem.
Another option might be to install the gem globally ion the server and require that gem in each application manually. But that still means you have to add a require 'gem_name' to all applications and this is error-prone because you lose the magic provided by bundler.
tl;dr: No, you have to add the gem to each application's Gemfile.

Related

How can I use a gem locally without forcing it on collaborators?

I'm working on a collaborative Rails project and I'd like to make use of Thoughtbot's excellent vim-rspec gem in my own development environment without polluting the project's Gemfile (not many of the collaborators use Vim).
vim.rspec recommends it is installed as a vundle. It isn't a gem but more of a plugin.
There are instructions to install vundle on the homepage. If you install it locally outside of the rails project it won't affect your collaborators.

Environment to develop gem while develop rails app

I am developing a Rails app that uses a gem that I am also developing.
Every change that I make in the gem I have to: build, uninstall previously installed gem, install built gem, restart rails app.
You can imagine that it easily becomes a nightmare to make even litle changes in the gem.
I´ve tried to manually load all files that are configured to be loaded by the gem (at Gemspec) but it always seem to be some problem in the loading process, not finding libraries or not loading in the proper order.
Is there a way to set my environment to better develop my gem with my app?
You can just add a file reference to your local filesystem in your Gemfile, like
gem 'new_gem', :path => '~/RubyPlayground/DevGems/new_gem/'
That way you just need a new bundle install after modifying your new gem.
Update
Reading your description again you might not be using rails 32. My suggestion is of course based on bundler at least.
You could always symlink your gem code to lib/ and then include that in your autoreload paths (application.rb IIRC).

When to Add to Gemfile and when to just install via CLI

I'm just getting started with rails and I'm a little confused reading through different documentation as to when you should add the gem to your gemfile and when you should just "gem install XXX"
For example, when installing rspec and guard-rspec. I see that some folks will:
gem install rb-fsevent
and some people put it in their gemfile and bundle.
Which is the right way and how do you know which to choose? Thanks!
The Gemfile records and manages all the dependencies for the application. When you list gems in the Gemfile, bundler sorts out any version conflicts and makes sure that the correct version of the gems are used with your application.
When you set up the application in a new environment (such as when your colleagues pull your changes from version control or when you deploy to a production web server), Bundler can use the gem file to ensure that the environment is set-up exactly as you had it in development.
So, anything on which your application depends (any code you call from your application for example), needs to be in the Gemfile. This includes libraries that you use for testing (although they can be excluded from the production environment).
Gems that are not dependancies of your application don't need to go in the Gemfile. An example would be guard which is more of a development tool than an application dependancy. You can install those with the gem command.
Typically though, most things you're going to want to install probably need to be in the Gemfile.
It doesn't matter if you install it with the gem command however. You can still put it in your Gemfile afterwards and Bundler will work out what to do.
All gems you will use in your application you should put into Gemfile.
All gems that will be just serving your application you'd better keep out of Gemfile.
For example. You need paperclip and mysql2 gems to store pictures and data, so put them into Gemfile. And you need magic_encoding gem to do some helpful stuff. But as far you are creating it straight from console, you don't need it in your application. Keep it separate from your app.
You use test frameworks when writing code, so put them into your Gemfile.
You use passenger gem to deploy your apps, but you never need to use it right in your code - don't put it into Gemfile.

Creating a gem server, which I can release gems to

I've written a few gems that I've released to rubygems using Gemcutter and the source stored on github.
I have issue that I need to create a gem that can't be open source and also not available to the community, but only to members of my team.
I am aware that I can store gems locally and target them in my Gemfile, however I'd like to be able to do
rake version:bump
rake release
or similar. That would bump the version and push it to my gem server and still keep older gems so that people can install older versions of it.
Seems like it should be fairly simple to do. I'm just missing how to do it
This is fairly simple if you have a server you can host your private gems on. Setup a subdomain, something like gems.companyname.com and setup a virtual host to host your domain. You'd point that virtual host to a folder like you would any website and setup the gem server from there.
Example:
mkdir /var/www/gemserver
mkdir /var/www/gemserver/gems
cp private-gem-0.1.0.gem /var/www/gemserver/gems
cd /var/www/gemserver
gem generate_index
/var/www/gemserver would be the root directory. Lastly all you'd need to do is add a new source to your Gemfile
source 'http://rubygems.org'
source 'http://gems.companyname.com'
So anyone that knows about your custom domain can get access to the gems. The only pain is every time you rebuild your gem you need to run the generate_index command again after you upload your gem to the gems folder.

How to install a forked gem on Engine Yard?

I want to use the LinkedIn gem But not the one that I get when I type
sudo gem install linkedin
I want a specific one that somehow has done patches to. It is a fork of the original which is:
http://github.com/jbasdf/linkedin
I have downloaded sources from the above link, and use "rake" command to build a gem locally. So everything is working fine locally.
But now I have a question. How can I setup this folked gem on the server (engine yard)? I am not sure how to bild a gem on the server in this case.
Many thanks!
If the pre-built gem is available on a server(gem cutter) you should be able to use Trip's method.
If not two options spring to my mind:
1) Write a chef script that clones the source from github and builds it.
2) Use bundler with its built in support for building gems from a git url. EY fully supports bundler.
I think the latter would be a better choice, as it completely removes the need to use EY's UI for managing gems and is a step towards Rails 3 compatibility.
You can log into EY's cpanel. On your dashboard, Click "Application" in your instance, and then click on the Ruby Gem Icon. In this panel you can download gems to install on your server including what version you want them as well.

Resources